对于我的代码,我需要通过用户ID号更新记录。将值输入Exercise
和Weight
的输入框后,单击一个按钮即可更新记录。 Exercises
是第一个具有外键ID
的表,该外键与MemberID
表中的memb
相关联。我为此创建了一个UPDATE
查询,这是代码:
def Update(self):
global MemberID
connection = sqlite3.connect(r"E:\TESTING\Program\Accounts.db")
cursor = connection.cursor()
Exercise = self.Exercises.get()
Weight = self.Weights.get()
MemberID = self.ent_MemberID.get()
List = [Exercise, Weight]
cursor.execute("UPDATE Exercises SET Exercise=?, Weight=? WHERE ID = (SELECT MemberID FROM memb WHERE MemberID = ?);",(Exercise, Weight, MemberID))
connection.commit()
它不会显示任何错误,但不会将数据输入表中。这是我用来创建Exercises
表的代码:
CREATE TABLE `Exercises` (
`Exercise` TEXT,
`Weight` INTEGER,
`Reps` INTEGER,
`Sets` INTEGER,
`ID` INTEGER,
PRIMARY KEY(`ID`),
FOREIGN KEY(`ID`) REFERENCES `memb`(`MemberID`)
);