[DB-SIG] [parameter substitution] how to escape perecent?

Craig Amundsen cdamundsen at gmail.com
Wed Jun 7 18:51:51 CEST 2006


Hi -

I am doing a parameter substitution, but when I execute the following
> statement I get an error. Could you tell me how should i escape %
> signs?
>
> sql="select DATE_FORMAT(FROM_UNIXTIME(my_table.received_date),'%Y %M
> %d,%H:%i') from my_table where my_table.from_email=%s"
>
> then
> c.execute(sql,('myemail at mydomain'))
> or
> c.execute(sql,(email))


>>> sql="select DATE_FORMAT(FROM_UNIXTIME(my_table.received_date),'%%Y %%M
%%d,%%H:%%i') from my_table where my_table.from_email=%s" % '
myaddress at mydomain.com'
>>> sql
"select DATE_FORMAT(FROM_UNIXTIME(my_table.received_date),'%Y %M %d,%H:%i')
from my_table where my_table.from_email=myaddress at mydomain.com"

- Craig
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/db-sig/attachments/20060607/11bc20dd/attachment.html 


More information about the DB-SIG mailing list