开发者

Trouble with MySQL UPDATE syntax with the module mysqldb in Python

开发者 https://www.devze.com 2022-12-18 20:26 出处:网络
I am attempting to execute the following query via the mysqldb module in python: for i in self.p.parameter_type:

I am attempting to execute the following query via the mysqldb module in python:

for i in self.p.parameter_type: cursor.execute("""UPDATE parameters SET %s = %s WHERE parameter_set_name = %s""" % (i, float(getattr(self.p, i)), self.list_box_parameter.GetStringSelection()))

I keep getting the error: "Unknown column 'M1' in 'where clause'". I want to update columns i with the value getattr(self.p, i), but only in rows that have the column parameter_set_name equal to self.list_box_parameter.GetStringSelection(). The error suggests that my query is looking for columns by the name 'M1' in the WHERE clause. Why is the above开发者_StackOverflow中文版 query incorrect and how can I correct it?


i see now, i think you need to enclose parameter_set_name = %s in quotes such as:

parameter_set_name = "%s"

otherwise it's trying to acces column M1

so:

cursor.execute("""UPDATE parameters SET %s = %s WHERE parameter_set_name = \"%s\" """ % (i, float(getattr(self.p, i)), self.list_box_parameter.GetStringSelection()))


It looks like query is formed with wrong syntax. Could you display string parameter of cursor.execute?

0

精彩评论

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

关注公众号