rows = db((~db.person.name=='Alex') | (db.person.id>3)).select()
>>> q = ~db.auth_user.id.belongs(1,2,3)
>>> q
<Query (NOT (auth_user.id IN (1,2,3)))>
>>> q = ~db.auth_user.id==0
>>> q
<Query (auth_user.id DESC = 0)>
>>> q = ~db.auth_user.id>0
>>> q
<Query (auth_user.id DESC > 0)>
>>> db(q).select()
...
OperationalError: near "DESC": syntax error
--
---
You received this message because you are subscribed to the Google Groups "web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to web2py+un...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
With trunk, I have tested the behavior of the ~ operator, and doesn't seem consistent to me:
Here Bruno gives a working example of belongs negation
https://groups.google.com/d/msg/web2py/fCB9a4K9FqU/GBLwfzNnkjMJ
But the book uses this example:rows = db((~db.person.name=='Alex') | (db.person.id>3)).select()
This is wat I get in the console (with SQLite/Python 2.7.3)
>>> q = ~db.auth_user.id.belongs(1,2,3)
>>> q
<Query (NOT (auth_user.id IN (1,2,3)))>
>>> q = ~db.auth_user.id==0
>>> q
<Query (auth_user.id DESC = 0)>
>>> q = ~db.auth_user.id>0
>>> q
<Query (auth_user.id DESC > 0)>
>>> q.select()
Traceback (most recent call last):
File "<console>", line 1, in <module>
AttributeError: 'Query' object has no attribute 'select'
>>> db(q).select()
Traceback (most recent call last):
...
OperationalError: near "DESC": syntax error
Note that the second and third query would return an OperationalError (the INVERT operator is used instead of NOT)
To avoid the error the syntax must be ~(db.auth_user.id==0), with parethesis.
Is this an problem with the sqlite adapter only?
A similar caveat applies to the use of | or & in queries.