【发布时间】:2016-12-06 16:15:10
【问题描述】:
我在尝试向表中插入一些值时遇到此错误。 这是我的代码:
def tsx_insert(self, d_list):
for item in d_list:
query = """ INSERT IGNORE INTO tsx_first_insert(protocollo,procedura,oggetto,priorita,
tipo_richiesta,sottotipo_richiesta,emergenza,
richiesta,uo_richiedente,autore,scadenza_sla)
VALUES(%(protocollo)s,%(procedura)s,%(oggetto)s,%(priorita)s,%(tipo_richiesta)s,
%(sottotipo_richiesta)s,%(emergenza)s,%(richiesta)s,%(uo_richiedente)s,
%(autore)s,%(scadenza_sla)s)"""
values = item.values()
self.exec_query(query,values)
这里还有'exec_query'函数:
def exec_query(self, query, params):
try:
if self.connected is None:
self.connect()
self.cursor = self.connected.cursor()
self.cursor.connection.autocommit(True)
self.cursor.execute(query)
if self.cursor.description:
self.description = [d[0] for d in self.cursor.description]
self.rows = self.cursor.rowcount
self.sql_result = self.cursor.fetchall()
except MySQLdb.Error, e:
logging.error('Error {0}: {1}'.format(e.args[0], e.args[1]))
finally:
self.cursor.close()
错误是:“错误 1064:您的 SQL 语法有错误;请查看与您的 MariaDB 服务器版本相对应的手册,了解在 '%(protocollo)s,%(procedura)s, 附近使用的正确语法, %(oggetto)s,%(priorita)s,%(tipo_richiesta)s, ' 在第 4 行"
我不知道是什么问题。提前感谢您的帮助。
【问题讨论】:
-
您遗漏了错误中最重要的部分
-
@e4c5 已编辑完整的错误消息
-
看起来你没有代入参数...
标签: python mysql mysql-python mysql-error-1064