c.execute("UPDATE Players SET %s = %d WHERE nick=%s",
(parts[1], int(parts[2]), parts[0]))
Run Code Online (Sandbox Code Playgroud)
给了我错误
TypeError: %d format: a number is required, not str
Run Code Online (Sandbox Code Playgroud)
我知道execute应该只采取%s,但parts[2]应该转换为int,因为它将是一个int(作为字符串输入).
所以,如果我只放了%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")
Run Code Online (Sandbox Code Playgroud)
因为wins是整数.这是什么解决方案?