An interesting suggestion...I can see how I could use it for some sort
of workaround.  What it would me is that I would have to use two
separate selects, when I was hoping you only do one.  Still it seems
to me that my initial approach is the correct one, and that the DAL
should be consistent in the way it generates SQL. Specifically:

==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)

Should work, but does NOT work because the DAL gives different results
for query1 and query2.  Is this, then a bug?


On Mar 24, 3:28 pm, nick name <[email protected]> wrote:
> On Friday, March 23, 2012 10:09:07 PM UTC-4, Limedrop wrote:
>
> > Thanks for the information.  Unfortunately, in my case I really do
> > need to store the raw query in the session...and then convert it back
> > to a Query so I can then add a few more filters before the final
> > select(). Has anyone managed to store a representation of a query in
> > the session?
>
> If you are using an SQL database, and the initial query is for a subset of
> records in a specific table, you might be able to use "belongs", which can
> accept a query string; so:
>
> # compute complicated query; use _select instead of select
> sqlquery = db(table)(...)(...)._select(table.id)
>
> # store sqlquery in your string storage, etc; it is a string.
> #  e.g. put it in your session (but under no circumstance in a form/request
> # variable or a cookie - that would make your app vulnerable to SQL
> injection)
>
> # retrieve your sqlquery string from the secure storage
>
> # add additional conditions
> finalquery = db(table.id.belongs(sqlquery) & table.field1=='field1value')

Reply via email to