The difference is in the FROM clause. In the second SQL the webpage table is missing.
On Mar 26, 12:51 pm, Niphlod <niph...@gmail.com> wrote: > is that because of the "extra" () ? > every time you call db() the where clause gets "encapsulated" in a pair of > parenthesis. > > db(db.auth_user.id>0)(db.auth_user.email==localhost) > > and > > db((db.auth_user.id>0) & (db.auth_user.email==localhost)) > > give you different raw strings, but the same exact result. > > Il giorno sabato 24 marzo 2012 21:49:58 UTC+1, Limedrop ha scritto: > > > > > > > > > > > I've copied this from the bottom of another thread. > > > The DAL gives different SQL when a query is provided in string format. > > Is this a bug, or should I not expect this to work? > > > See the example below, the first SQL works, the second SQL raises an > > error. > > > >>>from gluon.dal import Query > > >>>query = (db.comment.id > 0) & (db.webpage.title == 'FAQ') & > > (db.comment.page_id == db.webpage.id) > > >>>query_as_string = str(query) > > >>>query_from_string = Query(db, query_as_string) > > >>>print db(query)._select(db.comment.body) > > > SELECT comment.body FROM comment, webpage WHERE (((comment.id > 0) > > AND (webpage.title = 'FAQ')) AND (comment.page_id = webpage.id)); > > > >>>print db(query_from_string)._select(db.comment.body) > > > SELECT comment.body FROM comment WHERE ((((comment.id > 0) AND > > (webpage.title = 'FAQ')) AND (comment.page_id = webpage.id))); > > > Why do this? If the were possible it would enable you to easily save > > a query in the session. For example: > > > ==Controller 1== > > query1 = (db.comment.id > 0) & (db.webpage.title == 'FAQ') & > > (db.comment.page_id == db.webpage.id) > > session.query = str(query1) > > > ==Controller 2== > > from gluon.dal import Query > > query2 = Query(db, session.query) > > > This does NOT work because the DAL gives different SQL for query1 and > > query2.