I may be off target but I just recently noticed the .as_dict() method for rows objects. This converts the rows object to a regular dict (instead of a gluon storage object) which can be stored in session or cache (i.e., it's picklable). If you need the query (not the resulting rows object) to be stored this doesn't help, but if it works in your case to store the select() result this may actually be easier.
Ian On Friday, March 23, 2012 4:49:23 PM UTC-4, Limedrop wrote: > > Thanks for your suggestion...it pointed me in the right direction. > > It turns out the issue is not with the query construction, but that > DAL handles string input differently to objects. What I am trying to > do is take a Query and then convert it to a string so it can be saved > in the session. The string can then be pulled from the session and > converted back into a Query. This works for simple queries, but not > for queries with implicit joins. See the difference: > > > >>>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) > >>>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));" > >>>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)));" > > Does anyone know how to convert a Query to a string (so it can be > saved in the session) and then get it back again? > > > On Mar 24, 4:52 am, Wikus van de Merwe <dupakrop...@googlemail.com> > wrote: > > Just a blind guess but does this work any better? > > query = (comment.id > 0) & (webpage.title == 'FAQ') & (comment.page_id > == > > webpage.id) & (comment.id == comment_tags.comment_id) & (tag.id == > > comment_tags.tag_id) & (tag.label == 'Agree') > > db(query).select()