On Jun 21, 2014, at 1:36 PM, Simon Slavin <slav...@bigfraud.org> wrote:
>   But the programming style I've been using recently does the equivalent of 
> allowing any number of concurrent "BEGIN"s and handing back a handle for each 
> one.  You can execute any number of commands (SELECT or write) for each 
> BEGIN, and then close the transaction with an "END" or "ROLLBACK".
> 
> SQLite, of course, does not hand back a handle for each "BEGIN".  A BEGIN 
> inside a transaction is, correctly, an error.  But I find myself wanting to 
> handle my transactions more ... erm ... modularly.  So if I was to change my 
> programming style accordingly ...

Do you mean nested transactions?

In my home-grown C++ wrapper for sqlite I do this with a "transaction tracker" 
object that tracks the nesting level on a connection and executes a BEGIN 
(IMMEDIATE) if the nesting level == 0, and a "SAVEPOINT X" if the nesting level 
!= 0, and if successful, a COMMIT if the level is 0, and a "RELEASE X" if the 
nesting level != 0.

If the transaction is not successful and the nesting level is 0, it does a 
ROLLBACK, otherwise a "ROLLBACK TO X; RELEASE X"

(Yes, the name of the savepoint is always X.)

Works well.

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

Reply via email to