我有一个数据库:
datas.db --->表bk
编码Python
self.db = sqlite3.connect("library.db")
self.cur = self.db.cursor()
search_name = self.lineEdit_1.text()
name = self.lineEdit_2.text()
number_age = self.lineEdit_3.text()
description = self.lineEdit_4.text()
self.cur.execute("UPDATE bk SET (Name ='?',Number =?, Timer ='?') WHERE Name ='?'",(name,number_age,description,search_name))
self.db.commit()
现在我收到语法错误,我已经看到他们使用了这个
"Name ='%s'"%name)
但是当我有多个变量时,我不知道如何使用它
答案 0 :(得分:0)
根据SQLLite Docs,您的代码应如下所示。
您的查询错误,请更改为
UPDATE bk SET (Name ='?',Number =?, Timer ='?') WHERE Name ='?'
到
UPDATE bk SET Name=?, Number=?, Timer=? WHERE Name=?
self.db = sqlite3.connect("library.db")
self.cur = self.db.cursor()
search_name = self.lineEdit_1.text()
name = self.lineEdit_2.text()
number_age = self.lineEdit_3.text()
description = self.lineEdit_4.text()
self.cur.execute("UPDATE bk SET Name=?, Number=?, Timer=? WHERE Name =?",(name, number_age, description, search_name))
self.db.commit()