python sqlite“BEGIN TRANSACTION”和“COMMIT”命令

2024-05-06 04:21:15 发布

您现在位置:Python中文网/ 问答频道 /正文

如果我想通过python在数据库中启动事务,我必须显式地执行sql命令“BEGIN transaction”,如下所示:

import sqlite3

conn = sqlite3.connect(db)
c = conn.cursor()

c.execute('BEGIN TRANSACTION;')
##... some updates on the database ...
conn.commit() ## or c.execute('COMMIT'). Are these two expressions the same?

当我建立连接或开始事务时,数据库是否被锁定以便从其他客户端进行更改?


Tags: theimport命令数据库executedbsqlconnect