【问题标题】:How to delete record from sql如何从sql中删除记录
【发布时间】: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 文件;在运行查询之后关闭连接之前。

标签: python sql sqlite


【解决方案1】:

执行查询后,您需要提交它: con.commit()

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-09-20
    • 1970-01-01
    • 2020-03-31
    • 2011-09-15
    • 2011-04-28
    • 1970-01-01
    • 2023-04-06
    • 1970-01-01
    相关资源
    最近更新 更多