gpt4 book ai didi

python - _mysql_exceptions.ProgrammingError : (1064, "You have an error in your SQ L syntax; right syntax to use near ' )' at line 1")

转载 作者:太空宇宙 更新时间:2023-11-03 10:58:32 24 4
gpt4 key购买 nike

Python MySQL 语句返回错误

def _conditional_insert(self, tx, item):
tx.execute('select * from table where text1 = %s', (item['text1'], ))
result = tx.fetchone()
if result:
log.msg("Item already stored in db: %s" % item, level=log.DEBUG)
else:
tx.execute(\
"INSERT INTO table (text3 table, text1, text2) "
"values (%s, %s, %s, %s)",
(item['text3'],
item['table'],
item['text1'],
item['text2'],
)
)
log.msg("Item stored in db: %s" % item, level=log.DEBUG)

def handle_error(self, e):
log.err(e)

但不断收到以下错误:

_mysql_exceptions.ProgrammingError: (1064, "You have an error in your SQ L syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ')' at line 1")

谁能告诉我在哪里忽略了)

最佳答案

您的字段规范中 text3 后缺少逗号。

INSERT INTO table (text3 table, text1, text2)

应该是:

INSERT INTO table (text3, table, text1, text2)

此外,如果您不将 table 括在引号中,我认为它不是有效的表名或列名,因为它是关键字。

关于python - _mysql_exceptions.ProgrammingError : (1064, "You have an error in your SQ L syntax; right syntax to use near ' )' at line 1"),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18084268/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com