SAVEPOINT mechanism in SQLite
Asked Answered
B

0

7

I am trying to understand Savepoints and Transactions in SQLite. I had the following commands on a Table/Database and I am using Savepoints.

SAVEPOINT aaa;
RELEASE aaa;
BEGIN;

Now, if I execute all the above statements at once, its throwing an error saying that A transaction cannot be started inside another transaction. If I run them one at a time, it works fine. if I run the first two Savepoint and release commands and try to start another transaction by executing the Begin. it again throws the same error as previous.

The link here says that

If the SAVEPOINT command is issued when SQLite is in autocommit mode—that is, outside of a transaction—then a standard autocommit BEGIN DEFERRED TRANSACTION will be started. However, unlike with most commands, the autocommit transaction will not automatically commit after the SAVEPOINT command returns, leaving the system inside an open transaction. The automatic transaction will remain active until the original save-point is released, or the outer transaction is either explicitly committed or rolled back. `

So, Is it absolutely necessary for a Commit or Rollback command after the Release Savepoint Command? Doesn't release command commit and allow us to start a new transaction using BEGIN?

Burseraceous answered 27/7, 2016 at 20:26 Comment(7)
Are you using Python?Shiflett
Nope, we are using C#Burseraceous
How? Show the code.Shiflett
we meant to use C# but I am trying the above commands in Plain SQLite Editor just to understand Savepoints to decide between Savepoints and Transactions or a mix of both.Burseraceous
There is no program called "Plain SQLite Editor". Are you using the sqlite3 command-line shell? If yes, show the exact sequence of commands you're using.Shiflett
apologies for wrong wording, I meant the SQL Editor which is available as a Tab on "SQLite Expert Professional" software where in we type in the queries on the table. Coming to the Sequence of the statements that I am using is same as in my question. SavePoint aaa; some DML statements, Release aaa and Begin; Please let me know if you need more info. I tried on a test database on my local machine.Burseraceous
This sounds like a bug in that software. Try to reproduce it in sqlite3.Shiflett

© 2022 - 2024 — McMap. All rights reserved.