开发者

a really strange bug when my python program working with mysqll

here is the code

sql="SELECT node_id FROM %s WHERE domain='%s';"%(config.nodetable,url)
r=getBySql(sql) 

my problem is trying to save data in mysql db so this code should was executed repeatedly for like more than hundred thousands of times. and at the beginning everything went well, until several times the interpretor return the error:

File "/usr/lib/pymodules/python2.6/MySQLdb/connections.py", line 35, 
in defaulterrorhandler
    raise errorclass, errorvalue
OperationalError: (1054, "Unknown column 'h' in 'where clause'")

but I find the sql string to be executed is totally OK as:

SELECT node开发者_开发问答_id FROM testnodewww WHERE domain='http://service.qq.com';

I totally have no idea about it. why it was working good at first? and why the error informed of "unknown column 'h'"?? my code have nothing to do with column h at all...


MySQLdb will convert your parameter into a SQL literal, do not use single quotes in your sql string, or a semi-colon at the end, and don't use string interpolation:

sql = "SELECT node_id FROM %s WHERE domain=%s" % (config.nodetable, url)

Do this instead:

cursor.execute("SELECT node_id FROM %s WHERE domain=%s", (config.nodetable, url))
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜