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

Damien Garaud damien.garaud at logilab.fr
Fri Aug 8 09:33:24 CEST 2014


Florent Cayré writes:

> 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

Indeed. In the README file of cwclientlib
https://www.cubicweb.org/project/cwclientlib in the "kerberos" example,
you can read:

queries = [builders.create_entity('CWUser', login='Babar', password='secret'),
           builders.build_trinfo('__r0', 'disable', 'not yet activated'),
          ]
resp = client.rqlio(queries)

'queries' is a list of couple ({query}, values). You can see the '__r0'
in the 2nd query. This is a reference to the EID created in the previous
query. rqlcontroller execute each query, then commit and should return
the eids of created EType.

As said Florent, there is also an example of query building in the
unitted of the cube rqlcontroller (called by the 'rqlio' method of our
client).

-- 
Damien Garaud          <damien.garaud at logilab.fr>



More information about the Cubicweb mailing list