[Cubicweb] Which way to go to do remote RQL ?

Yann Cointepas yann at cointepas.net
Fri Aug 8 09:36:10 CEST 2014


Thanks, I did not know the possibility to use __r* for referencing the
result of other requests (I suppose that * represent the index of the
request in the list). You are right, it makes it possible to implement my
simple example.

However, during the insertion process, I need to query the database (taking
into account entities inserted earlier in the transaction). For instance, a
ScoreValue have to be connected to a ScoreDefinition. When I insert a
ScoreValue, I query for the corresponding ScoreDefinition and if it does
not exists I create it* :

d = db.rql('Any X WHERE X is ScoreDefinition, ...')
if not d:
    d = db.rql('INSERT ScoreDefinition X ...')
db.rql('INSERT ScoreValue X: X definition D, D eid %d ...' % d[0][0])

It still seems difficult to me to put this in a single transaction with
rqlcontroller.

      Yann

* This example is stupid because I could create all StudyDefinition before
insertion but I have other, however more complex, similar situations.


Yann Cointepas            Tel: +33 1 69 08 78 31
CEA - Neurospin           Fax: +33 1 69 08 79 80
Bâtiment 145, Point Courrier 156
91191 Gif-sur-Yvette cedex, France


On Fri, Aug 8, 2014 at 8:42 AM, Florent Cayré <florent.cayre at logilab.fr>
wrote:

> Hello Yann,
>
> Le 08/08/2014 00:12, Yann Cointepas a écrit :
>
>> [snip]
>>
>>
>> db = CubicwebAPIWithRollback()
>> try:
>>     s = db.rql('INSERT Subject X: X identifier "N")[0][0]
>>     db. rql('INSERT Scan X: X concerns S, S eid %d' % s)
>>     s = db.rql('INSERT Subject X: X identifier "S")[0][0]
>>     db. rql('INSERT Scan X: X concerns S, S eid %d' % s)
>> except:
>>     db.rollback()
>> else:
>>     db.commit()
>>
>> Because of the constraint error, there will be no change in the database
>> at the end of this code. How could I construct a code that would do the
>> same without transactions ?
>>
>> Sorry for this long message.
>>
>>       Yann
>>
>>
>>
> There is probably a misunderstanding here: rqlcontroller does not mean "no
> transaction" but rather "one transaction per web request".
>
> Your simmplified example above fits perfectly with rqlcontroller
> capabilities, as illustrated in the rqlcontroller unittests :
> http://hg.logilab.org/review/cubes/rqlcontroller/file/
> 948e9b500fe9/test/unittest_rqlcontroller.py#l38
>
> Hope that helps.
> Cheers,
> Florent.
> _______________________________________________
> Cubicweb mailing list
> Cubicweb at lists.cubicweb.org
> http://lists.cubicweb.org/mailman/listinfo/cubicweb
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.cubicweb.org/pipermail/cubicweb/attachments/20140808/a86dea09/attachment-0186.html>


More information about the Cubicweb mailing list