c.execute("UPDATE Players SET %s = %d WHERE nick=%s",
(parts[1], int(parts[2]), parts[0]))
给了我错误
TypeError: %d format: a number is required, not str
我知道execute
应该只取%s
,但parts[2]
应该转换为 int,因为它将是一个 int(作为字符串输入)。
所以,如果我只放%s
's,当然会出现这个错误:
mysql_exceptions.ProgrammingError: (1064,
"You have an error in your SQL syntax; "
"check the manual that corresponds to your MySQL server version "
"for the right syntax to use near "
"''wins' = '450' WHERE nick='xan'' at line 1")
因为wins
是整数。解决方案是什么?