python sqlite3事务_SQLite的事务模式

sqlite3在执行SQL语句的时候,如果不是显示的包含在transaction内(即begin…commit),就是auto commit状态。即,每一条DML语句都会默认立即commit。有人也说这是sqlite3的隐式事务,而用begin开始用commit结束的,是显示事务。

注意python自带的sqlite3模块接口,不是这样的,必须要调用commit接口。

sqlite3有3种事务模式:DEFERRED, IMMEDIATE, or EXCLUSIVE.

DEFERRED

DEFERRED means that the transaction does not actually start until the database is first accessed. Internally, the BEGIN DEFERRED statement merely sets a flag on the database connection that turns off the automatic commit that would normally occur when the last statement finishes. This causes the transaction that is automatically started to persist until an explicit COMMIT or ROLLBACK or until a rollback is provoked by an error or an ON CONFLICT ROLLBACK clause. If the first statement after BEGIN DEFERRED is a SELECT, then a read transaction is started. Subsequent write statements will upgrade the transaction to a write

Original: https://blog.csdn.net/weixin_42515093/article/details/114912626
Author: Atomic阿强
Title: python sqlite3事务_SQLite的事务模式

原创文章受到原创版权保护。转载请注明出处:https://www.johngo689.com/817528/

转载文章受原作者版权保护。转载请注明原作者出处!

(0)

大家都在看

亲爱的 Coder【最近整理,可免费获取】👉 最新必读书单  | 👏 面试题下载  | 🌎 免费的AI知识星球