我正在使用Python MySQL connector,需要编写一个SQL查询,如下所示:
update inventory set checked_out = 'n' where item = 'dongle'
所有项目都被放置在上一次执行的游标中,我在循环中使用:
cnx = mysql.connector.connect(host='localhost',database='mem_bug',user='root',password='July@2013')
for r in cursor :
sql = "update inventory set checked_out = 'n' where item = {}".format(r[0])
cursor.execute(sql)
cnx.commit()
形成SQL时,其形式如下:
update inventory set checked_out = 'n' where item = dongle
因此给出的误差为:
_mysql_connector.MySQLInterfaceError: Unknown column 'dongle' in 'where clause'
如何在字符串中格式化字符串以正确执行SQL
只要加上引号,问题就来了:
相关问题 更多 >
编程相关推荐