> If I start a transaction and there will be a failure for whatever reason,
> do I have to call ROLLBACK?

The answer depends on your definition of "failure" and "whatever reason"; your 
definition of "start a transaction"; and, the journal mode in effect.

> Or this transaction will just stay somewhere in a journal and will not go
> to db?

In the net result, if this is a "user error" (meaning that you have attempted 
to do something not permitted such as insert a duplicate row or otherwise 
violate database integrity constraints) *and* you are in the middle of an 
EXPLICIT transaction (ie, you started it by commanding "BEGIN"), then it is 
your responsibility to ROLLBACK the transaction (if you started a transaction, 
then it is your responsibility to either COMMIT or ROLLBACK, in the face of a 
"user" error).  If you are relying on magical behaviour (that is, you are in 
the middle of a per-statement implicit transaction) then the magic will do what 
magic does and magically rollback in the face of a "user error" or magically 
commit if there is no "user error".

This becomes much more complicated if you are using DEFERRED transactions or 
constraint checking, or if you are using savepoints.  The general rule is that 
if *you* started it, then *you* must finish it.  The exception to the rule is 
where you get an error indicating that a "system error" has occurred and that 
any operation other than dumping core and waving bye-bye is unsafe.

Any in-progress transaction will rolled back or committed as appropriate from 
the journal when the database is opened in order to return the database to a 
consistent state.  That is to say that if you have not received an OK 
indication from a commit operation, then the in-progress transaction will be 
rolled back.  If you did receive an OK from a commit operation then the 
transaction will be commited.  This applies to any abend of the application at 
any time.

http://www.sqlite.org/transactional.html

---
()  ascii ribbon campaign against html e-mail
/\  www.asciiribbon.org





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

Reply via email to