Simple query with variable table

33 views
Skip to first unread message

Gael Princivalle

unread,
Nov 15, 2014, 10:53:11 AM11/15/14
to web...@googlegroups.com
Hello all.

I would like to make a query with a table name that will come from request.vars.
Something like that:
query = db.request.vars['table_name']

or like that:
db_and_table = 'db.'+ request.vars['table_name']
query
= db_and_table

Is there a solution ?

Thank's !

Leonel Câmara

unread,
Nov 15, 2014, 10:59:16 AM11/15/14
to web...@googlegroups.com
Yeah, here's an example:

if request.vars.table_name in db.tables:
    db(db[request.vars.table_name].id > 0).select()




Gael Princivalle

unread,
Nov 15, 2014, 11:20:08 AM11/15/14
to web...@googlegroups.com
Ok but for a query to give to a grid ?
This:
query = db[request.vars.table_name].id > 0

don't work.

----------------------
Gael Princivalle

--
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 a topic in the Google Groups "web2py-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/web2py/AbluPr6eIQs/unsubscribe.
To unsubscribe from this group and all its topics, send an email to web2py+un...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Leonel Câmara

unread,
Nov 15, 2014, 11:35:55 AM11/15/14
to web...@googlegroups.com
Well it should work, in fact just passing db[request.vars.table_name] to the grid should work, have you checked what's in request.vars.table_name? 

Gael Princivalle

unread,
Nov 15, 2014, 12:51:13 PM11/15/14
to web...@googlegroups.com
Yes with db[request.vars.table_name] directly in the grid it works, thanks a lot.


----------------------
Gael Princivalle

2014-11-15 17:35 GMT+01:00 Leonel Câmara <leonel...@gmail.com>:
Well it should work, in fact just passing db[request.vars.table_name] to the grid should work, have you checked what's in request.vars.table_name? 

--
Reply all
Reply to author
Forward
0 new messages