【发布时间】:2018-12-01 10:17:04
【问题描述】:
我有下面的 MySQL 语句,但其中一个值中有一个单引号 ',因此出现以下错误:
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()
)
【问题讨论】:
标签: python mysql scrapy character mysql-error-1064