[pyar] Escapar parametros en consultas, MySQLdb
Luis I. Facciolo
lifacciolo en gmail.com
Mar Feb 8 19:25:34 ART 2011
Podrias hacer algo asi:
# si fuesen: primaryUsers = ["user1","user2","user3","user4","user5"]
delete2 = "DELETE FROM Users where user NOT IN ( %s )" % (",".join(["'%s'" %
user for user in primaryUsers]),)
>>> output:
"DELETE FROM Users where user NOT IN (
'user1','user2','user3','user4','user5' )"
Saludos!
2011/2/8 Gerardo Benitez <gerardo en coresecurity.com>
> Hola, estoy armando unas consultas sql, y quiero saber cual seria la
> mejor manera de escapar algo asi.
>
> listaUsers = ""
> for user in primaryUsers:
> listaUsers = listaUsers + "'" + user + "', "
>
> listaUsers = listaUsers + "''"
>
> delete2 = "DELETE FROM Users where user NOT IN ( %s )" % listaUsers
>
>
> Gracias de antemano.
>
>
> Gerardo.
>
> _______________________________________________
> pyar mailing list pyar en python.org.ar
> http://listas.python.org.ar/listinfo/pyar
>
> PyAr - Python Argentina - Sitio web: http://www.python.org.ar/
>
------------ próxima parte ------------
Se ha borrado un adjunto en formato HTML...
URL: <http://listas.python.org.ar/pipermail/pyar/attachments/20110208/aa9288f1/attachment.html>
More information about the pyar
mailing list