db().select() and db.executesql() quetstion

142 views
Skip to first unread message

Richard

unread,
Mar 30, 2017, 11:51:00 AM3/30/17
to web2py-users
Hello,

I would like to clarify how DAL handle backend query.

For instance, if I assign a db().select() or executesql to a var like so :

query = db().select() 
or
query = db.executesql() 

Is the backend query occurs then or it occurs when I use the query var in a for loop for instance.

And if I am loop 2-3 differents times over the same query var does that trigger backend query each time?

Thanks

Richard

Anthony

unread,
Mar 30, 2017, 12:17:15 PM3/30/17
to web2py-users
No, the database is queried when you call the .select() or .executesql() method. The former returns a Rows object and the latter a list of tuples, so when you loop over your "query" object (which is confusingly named), you are simply looping over a Python data structure.

Anthony

Richard Vézina

unread,
Mar 30, 2017, 12:27:25 PM3/30/17
to web2py-users
Thanks Anthony,

I should use rows...

I had investigate that with help postgresql log and as you said DAL does queried the database at the assignation of the db select or executesql...

Richard

--
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
---
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+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages