On 2015-03-10 10:44 PM, Mayank Kumar (mayankum) wrote: > Thanks Richard, but we call rollback only when my earlier sqlite3_step has > failed for some reason. Can it still undo some inserts/updates/deletes from a > previously executed but not yet commited tx ? > > Does completion of sqlite3_step with success , means a transaction was > successfully commited ? > > Are there other scenarios where , even though I am calling rollback when > sqlite3_step returns failed, it can undo previous txs.
Hi Mayan, A transaction has a precise start and an end. It is started explicitly with "BEGIN" or "BEGIN TRANSACTION" followed by the optional "IMMEDIATE" etc. Once it has started, any and all following SQL statements belong to the transaction right up to the point it ends by issuing either "END TRANSACTION" or "COMMIT" (which is just another way of saying END TRANSACTION) or indeed you roll it back with "ROLLBACK". I hope this clarifies your question - but to answer precisely: ANY and ALL previously executed but uncommitted statements that occurred after the last BEGIN TRANSACTION /will/ be rolled back when you issue a "ROLLBACK" and will otherwise only ever be committed once you issue "COMMIT" or indeed "END TRANSACTION". This is the entire point of having a transactional system. This means also that: If you've never issued a "BEGIN TRANSACTION", then any call to END TRANSACTION or ROLLBACK will fail but be otherwise harmless and have no effect. Beware that many wrappers start transactions automatically for you, which can cause unexpected results. Also see: https://www.sqlite.org/lang_transaction.html Note: There are other ways of committing clustered sections of transactions using the SAVEPOINT / RELEASE SAVEPOINT mechanic.