MySQLdb LIKE '%%%s%%' problem

gumbah joost.ruyter at gmail.com
Wed Jan 14 03:31:11 EST 2009


I have this really strange problem. I hope someone can help:

I am trying to update a database like so:

UPDATE `tablename` set fieldx='test' WHERE flfieldx = null and fieldy
like '%certainvalue%'

My Python code looks like this:

fillsql = "UPDATE `tablename` set fieldx='test' WHERE flfieldx = null
and fieldy like '%%%s%%' " % certainvalue
print fillsql
cursor.execute(fillsql)

#also tried:
#cursor.execute("UPDATE `tablename` set fieldx='test' WHERE flfieldx =
null and fieldy like %s ", "%%%s%%" % certainvalue)

But it doesn't work... But when i copy and past the SQL (printed by
"print fillsql" line) and execute that in phpMyAdmin, it does work!!!

Can anyone tell me what i am doing wrong??

Thanks in advance!!



More information about the Python-list mailing list