BEGIN TRANSACTION
 ... issued commands inside transaction
COMMIT or ROLLBACK
-- transaction is now closed

That is, 
  BEGIN "opens" a transaction
  COMMIT "closes" the transaction in progress and saves the changes made during 
that transaction.
  ROLLBACK "closes" the transaction in progress and discards the changes made 
during that transaction.

While a transaction is "in effect", the "view" of the database is stable 
relative to all other CONNECTIONS to the database.  Changes made to the 
database in transactions on OTHER CONNECTIONS are not visible, and *unless you 
specify otherwise* you have REPEATABLE READ isolation.

Within a transaction you may nest SAVEPOINTs.  Savepoints are transactions 
within transactions and can be viewed as a stack.  If no TRANSACTION is in 
process then BEGIN TRANSACTION and SAVEPOINT are identical -- that is, a 
SAVEPOINT can only exist within a transaction and a SAVEPOINT where no 
transaction is in progress will start an "implicit" transaction if necessary.

SAVEPOINT <xxxxx> -- create a "context" named "xxxxx" (and an "implicit" 
transaction if one is not already in progress)

ROLLBACK TO <xxxxx> -- rollback the "context" to the state that it was in when 
the context was created.  Do not pop the context <xxxxx> off the stack but pop 
any contexts off the stack that were created "after" context <xxxxx> was 
created.  You are still in a transaction and the context <xxxxx> still exists.

RELEASE <xxxxx> -- commit all the changes that occurred after the specified 
context to the outer context.  Pop <xxxxx> from the context stack and also pop 
any contexts created after context <xxxxx> was declared (that is, all changes 
made after the declaration of the context are "moved into" the next higher 
context and all references to the named context and contained contexts are 
removed.  If you have "RELEASED" the last SAVEPOINT (ie, the first on the 
stack) and the containing transaction was created implicitly (rather than 
explicitly with BEGIN), then that implicit outer transaction is also committed 
and no transaction is any longer in effect.  If the out transaction was 
explicitly commenced (with BEGIN) then that transaction is still in effect and 
must be COMMITTED or ROLLBACKed in order to end it.

---
The fact that there's a Highway to Hell but only a Stairway to Heaven says a 
lot about anticipated traffic volume.

>-----Original Message-----
>From: sqlite-users [mailto:sqlite-users-
>boun...@mailinglists.sqlite.org] On Behalf Of Simon Slavin
>Sent: Saturday, 2 March, 2019 16:12
>To: SQLite mailing list
>Subject: [sqlite] Handling ROLLBACK
>
>I have run experiments in the shell tool, using different journal
>modes, but I would like to know whether my observations are cannon or
>just one-offs.  Contributions welcome from all, especially those who
>have read SQLite source code, and SQL language-lawyers whether or not
>you're familiar with how other SQL implementations work.
>
>
>Does ROLLBACK release the transaction lock on the database ?
>
>Does ROLLBACK cancel the BEGIN ?  Or do I need to issue END ?
>
>Suppose ROLLBACK does not cancel the BEGIN, can a programmer reliably
>issue more SQL commands, including another ROLLBACK ?  Will SQLite
>continue to react correctly to other ROLLBACKs, and to SQL commands
>which result in "(516) SQLITE_ABORT_ROLLBACK".
>
>
>If you think I've missed a relevant point, please don't hesitate to
>bring it up.
>_______________________________________________
>sqlite-users mailing list
>sqlite-users@mailinglists.sqlite.org
>http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users



_______________________________________________
sqlite-users mailing list
sqlite-users@mailinglists.sqlite.org
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to