我在下面的MySQL语句中使用python,但其中一个值中有一个单引号',因此出现以下错误:
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 L at line 1
要插入的值是Regal INT'L
如何转义或更正MySQL语句?
MySQL语句
def query(self, item):
return "INSERT INTO income_statement({columns}) VALUES ({values})".format(
columns=', '.join(item.keys()),
values=self.item_to_text(item)
)
def item_to_text(self, item):
return ', '.join("'" + str(v) + "'" for v in item.values()
)
HUX布斯
相关分类