【发布时间】:2022-01-19 01:09:35
【问题描述】:
为什么这段代码不起作用?
def deleted(self):
id = self.res[i][6] # it's int
con = sqlite3.connect('db.sqlite')
cur = con.cursor()
cur.execute("""DELETE from Table1 WHERE id = ?""", (id, ))
cur.close()
con.close()
【问题讨论】:
-
看起来不错,只是你忘记了
con.commit()将更改持久化到 db 文件;在运行查询之后关闭连接之前。