Hello,
Currently I am relying on the return code of sqlite3_exec(db,"BEGIN
IMMEDIATE",0,0,0) == SQLITE_ERROR as an indication that there is already a
transaction in progress and then in such cases, I will then call
sqlite3_exec(db,"SAVEPOINT mySavePoint",0,0,0) as a mean of nested
transaction.
Is this good enough? What is the correct way of detecting existing
transaction?
<code>
void func(sqlite3* db) {
int rc, active = 0, savepoint=0;
rc=sqlite3_exec(db,"BEGIN IMMEDIATE",0,0,0);
if (rc==SQLITE_OK) {
active=1;
}
else if (rc==SQLITE_ERROR) { /* is this a good test condition? */
rc=sqlite3_exec(db,"SAVEPOINT mySavePoint",0,0,0);
if(rc==SQLITE_OK) {
savepoint = active = 1;
}
}
/* do something */
if (active) {
if (savepoint) {
rc=sqlite3_exec(db,"RELEASE mySavePoint",0,0,0);
}
else {
rc=sqlite3_exec(db,"END",0,0,0);
}
}
}
</code>
Similar functions are called outside and inside TRANSACTIONs as well as
SAVEPOINTs.
Regards,
Afriza N. Arief
_______________________________________________
sqlite-users mailing list
[email protected]
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users