【发布时间】:2020-08-27 02:41:48
【问题描述】:
这是我的第一个问题,如果有点乱,抱歉,我在 MYSQL 上执行了这个查询
INSERT INTO ms_print_stock (product_code, product_name, product_stock, product_unit) SELECT * FROM ms_product WHERE product_code = %s
但它不适用于 MYSQL DB 连接器。但是,如果我将 %s 更改为它可以工作的值。它返回此错误。
mysql.connector.errors.ProgrammingError: 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version
for the right syntax to use near '%s' at line 1
顺便说一下,这里是python的完整代码
self.mycursor = self.mydb.cursor()
self.sql_print = "INSERT INTO ms_print_stock (product_code, product_name, product_stock, product_unit) SELECT * FROM ms_product WHERE product_code = %s"
print(self.sql_print)
self.val_print = (self.txtPCode.text())
self.mycursor.execute(self.sql_print, self.val_print)
print("BERHASIL")
self.mydb.commit()
【问题讨论】:
-
嗨 Clarissa,请参阅此处以了解如何更好地格式化您问题中的代码:meta.stackexchange.com/questions/22186/…
-
试试
self.val_print = (self.txtPCode.text(),)(注意多余的逗号) -
这工作得很好!谢谢!我想知道额外的逗号做了什么?
标签: python mysql sql mysql-python