SQLite Forum

Recover Database
Login
The concept of inner and outer transactions is fundamentally flawed, because transactions cannot be nested.

Transactions cannot be nested.  There is only one transaction.  It is started with a BEGIN TRANSACTION statement (which may implicitly precede a SAVEPOINT x statement if no transaction has yet commenced).

The `SAVEPOINT x` gives a LABEL to the particular state of the transaction at the point at which the statement occurs.

`ROLLBACK TO x` rolls back the transaction to the state the transaction was in at the time the label was created, which includes destroying all labels created subsequent to the creation of the label `x`.

`RELEASE x` removes the LABEL x and all labels assigned after label x was assigned from the transaction.

You still need to COMMIT or ROLLBACK the entire transaction.

A transaction is like a logbook, which you BEGIN (go fetch an empty logbook) and then xerox each page from the source book before you modify it and put the xerox copy in the logbook.

When you `COMMIT` or `END` the transaction, you are throwing the logbook in the shredder (so you can no longer "go back" to where you were before in the source book -- in other words, making the changes you made permanent).

When you `ROLLBACK` the transaction, you basically remove the pages from the logbook and put them back in the location from where they came in the original book and throwing the modified pages into the shredder (that is, undoing the changes).  When the logbook is empty, you throw it in the pager shredder too.

Creating a "SAVEPOINT" basically means that you get a coloured tab page with whatever name you like written on it and insert it at the current (end) position of the logbook.

`ROLLBACK TO x` basically means that you do the `ROLLBACK` procedure above, also throwing any coloured tab page that is not the one you are looking for into the paper shredder.  When you finally come across the coloured tab page named `x` you stop, leaving the coloured tab page named `x` as the last page of the logbook.

`RELEASE x` basically means that you start ripping coloured tab pages from the logbook from end to beginning until you find the one with `x` written on it.  Once you have thrown the coloured tab page labelled `x` into the shredder, you stop.  You do not change or modify in any way any other page in the logbook.

Note that in the case of `SAVEPOINT x`, `ROLLBACK TO x` and `RELEASE x`, you still have a logbook.  You can only "do away with" the logbook by issuing either `ROLLBACK` or `COMMIT` or `END` for the whole thing -- even if the whole process was started implicitly.