SQLite Forum

Recover Database
Login
Think of the database as a kitchen table with a bunch of plates on it.

When you *BEGIN" a transaction you "roll over a dirty dishes cart" to hold the plates.

When you do `SAVEPOINT x` you are doing the equivalent of writing x (the savepoint name) on a plate taken from the clean plate cupboard and stacking it on the "dirty dishes cart".

You can do a `SAVEPOINT x` command without doing the `BEGIN` first, in which case a dirty dishes cart (BEGIN) will be rolled over for you.

Now each time you make a change to the table (by putting some mashed potatos on a plate, for example) you have to save a "copy" of the plate as it was before the change was made on the "dirty dishes table" stack.

You carry on making copies of plates from the table onto the stack of copies of plates on the "dirty dishes stack", or adding plates on which you have written a savepoint name.

Once in a while you make "rollback to x" where x is a savepoint name that you previously used.  When you do this, then each plate from the stack of plates is removed one after each from the "dirty dishes cart" and replaces the plate on the table which was modified. the modified plate from the table is loaded into the dishwasher.  When you eventually get to the plate on which "x" is written you stop (you do not remove the plate on which "x" is written.

Once in a while you can also "release x" where x is a savepoint name that you previously used.  In this case you look through the pile of plates on the dirty dishes cart looking for the plates you have written on.  You place all plates you have written on including the one with "x" written on it in the dishwasher.  Note that you have not done anything to the to the data (stack of plate copies) on the dirty dishes cart.

You will note that `ROLLBACK x` does NOT remove the savepoint name x, and neither `rollback x` nor `release x` puts away the cart (end the transaction).  You still need to do this.

You may also say "rollback" without specifying a savepoint name, in which case you take each plate one after each from the "dirty dishes cart" and replace the corresponding plate on the table, and put the plate from the table in the dishwasher.  If the plate that you take from the top of the pile on the dirty dishes cart has something written on it, it goes directly into the dishwasher.  Eventually the dirty dishes cart is empty, so you wheel it back to the corner because the transaction is now finished.

You may also say "commit" or "end" in which case you simply put all the plates on the dirty dishes cart in the dishwasher, and put the cart back in the corner because the transaction is now complete.

If you attempt to "get another cart" while you already have a cart, you get an error message saying that you already have a cart in progress, and nothing will be done.

If you attempt to "close a cart" using "rollback", "commit", or "end" while you do not have a cart in progress you will get an error telling you so, and nothing will be done.

If you attempt to "rollback to x" or "release x" but there is no plate on which "x" is written in the stack of plates on the cart, you will get an error telling you so and nothing will be done.