Pro*_*zzz 5 sqlite transactions savepoints
我正在尝试了解 SQLite 中的保存点和事务。我在表/数据库上有以下命令,我正在使用保存点。
SAVEPOINT aaa;
RELEASE aaa;
BEGIN;
Run Code Online (Sandbox Code Playgroud)
现在,如果我一次执行上述所有语句,它会抛出一个错误,说A transaction cannot be started inside another transaction. 如果我一次运行一个,它工作正常。如果我运行前两个 Savepoint 和 release 命令并尝试通过执行Begin. 它再次抛出与以前相同的错误。
这里的链接说
如果 SAVEPOINT 命令在 SQLite 处于自动提交模式时(即在事务之外)发出,则将启动标准自动提交 BEGIN DEFERRED TRANSACTION。但是,与大多数命令不同,自动提交事务在 SAVEPOINT 命令返回后不会自动提交,使系统处于打开的事务中。自动事务将保持活动状态,直到原始保存点被释放,或者外部事务被显式提交或回滚。`
那么,Release Savepoint 命令之后是否一定需要 Commit 或 Rollback 命令呢?不release命令提交并允许我们使用BEGIN?
Dav*_*tti -2
SAVEPOINT aaa;
RELEASE aaa;
BEGIN;
被 sqlite 解释为
BEGIN DEFERRED TRANSACTION; SAVEPOINT aaa; // Create a transaction, and mark current db state as savepoint "aaa" [1]
RELEASE aaa; // Remove all db changes made since savepoint "aaa", but keep on executing the transaction
BEGIN; // Create another transaction, while there is already a transaction. This will FAIL because there cannot be 2 transactions executed simultaneously
以下内容就可以了:
BEGIN;
SAVEPOINT "aaa";
RELEASE "aaa";
COMMIT;
BEGIN;
[1] https://sqlite.org/lang_savepoint.html
| 归档时间: |
|
| 查看次数: |
2492 次 |
| 最近记录: |