[Cubicweb] RQL: substitution of values for IN predicate

Alexandre Fayolle alexandre.fayolle at logilab.fr
Mon Nov 29 14:23:22 CET 2010


On Monday 29 November 2010 12:54:54 Sylvain Thénault wrote:
> On 29 novembre 10:35, Alexandre Fayolle wrote:
> > Hello
> 
> Hi,
> 
> > Suppose I have something like:
> > 
> > wanted_values = [u'foo', u'bar', u'baz']
> > 
> > query = 'Any X WHERE X is Mumble, X name IN %(values)s'
> > 
> > As far as I understand, there is no way in the current implementation to
> > pass the query as it is now to execute(), with wanted values being part
> > of a dictionary of substitutions passed as the second argument.
> > Therefore I have to do the substitution for the list of values myself.
> > This probably has an impact on the caching of the query on the server
> > side, as such queries have to be reparsed each time.
> 
> Indeed
> 
> > Am I the only one who would like to be able to::
> >  _cw.execute(query, {'values': wanted_values})
> > 
> > in other words should I file a ticket for this?
> 
> We could probably deal with this in cubicweb's querier, so yes.
> 
> BTW, does anyone know a sql dbapi module handling this?

None come to mind. 

However, I just checked that the following works:

query = 'Any X WHERE X is Mumble, X name IN (%(v0)s, %(v1)s, %(v2)s)'
substs = {'v0': u'foo', 'v1': u'bar', 'v2':u'baz'}
execute(query, subst)


-- 
Alexandre Fayolle                              LOGILAB, Paris (France)
Formations Python, CubicWeb, Debian :  http://www.logilab.fr/formations
Développement logiciel sur mesure :      http://www.logilab.fr/services
Informatique scientifique:               http://www.logilab.fr/science



More information about the Cubicweb mailing list