On 5 Oct 2011, at 6:40pm, Pero Mirko wrote:

> So in other words a pseudo function like this:
> 
> BEGIN EXCLUSIVE
> if anyerror return
> INSERT INTO [table]
> if anyerror ROLLBACK
> INSERT INTO [table]
> if anyerror ROLLBACK
> UPDATE [table]
> if anyerror ROLLBACK
> UPDATE [table]
> if anyerror ROLLBACK
> COMMIT
> if anyerror ROLLBACK
> return
> 
> Would that guarantee ROLLBACK on any error?
> Does last ROLLBACK knows it should rollback from BEGIN EXCLUSIVE or should I
> still mark it with SAVEPOINT?

There is no need for you to use ROLLBACK.  The SQL engine knows that any error 
inside a transaction should automatically cancel all statements inside the 
transaction.  The ROLLBACK command is only for when you, the programmer, have 
decided on your own that a transaction should be cancelled, by spotting 
something that the SQL engine itself would not notice.  For example, that a 
debit has brought an account balance negative when it shouldn't do.  So your 
function is simply

BEGIN EXCLUSIVE
INSERT INTO [table]
INSERT INTO [table]
UPDATE [table]
UPDATE [table]
COMMIT

Then you check the result returned by the COMMIT and that tells you whether the 
transaction succeeded or was rolled back.  If the transaction succeeded, all 
four commands are now 'saved'.  If it did not, none of the four commands are 
now 'saved'.

I suggest you try an example using the SQLite shell tool and watch as it shows 
you which errors are generated by which commands:

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

This will show you what result codes your program might expect and should 
handle correctly.

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

Reply via email to