How to pass variables to db.executesql?

22 views
Skip to first unread message

Alex Glaros

unread,
Nov 19, 2020, 11:56:07 PM11/19/20
to web2py-users
for example 

    where mytable.id = someWeb2PyVariable

thanks,

Alex Glaros 

Alex Beskopilny

unread,
Nov 20, 2020, 8:09:20 AM11/20/20
to web2py-users
myid = 10L
sql_str = "xxx .... where id=%s;" % (str(myid))
db.executesql( sql_str )

Carlos Correia

unread,
Nov 20, 2020, 9:44:13 AM11/20/20
to web...@googlegroups.com
--
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+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/web2py/fa1cf04c-a01c-40fa-8e00-20295fa46113n%40googlegroups.com.

The recomended way is to use parameter 'placeholders', which is a dictionary with key-value pairs.

Example:

rows = db.executesql( 'select * from mytable where id = %(id)s', placeholders=dict( id=someWeb2PyVariable ) )

Regards,

Carlos Correia
=========================
MEMÓRIA PERSISTENTE
GSM:  917 157 146 (Signal, WhatsApp)
e-mail: ge...@memoriapersistente.pt
URL: http://www.memoriapersistente.pt
XMPP (Jabber): car...@memoriapersistente.pt
GnuPG: wwwkeys.eu.pgp.net
Reply all
Reply to author
Forward
0 new messages