Determine if SQLite3 transaction is active

The interface you're looking for is actually implemented in this next version of sqlite as you can see in the notes: https://sqlite.org/draft/c3ref/txn_state.html

Determine the transaction state of a database

int sqlite3_txn_state(sqlite3*,const char *zSchema);

The sqlite3_txn_state(D,S) interface returns the current transaction state of schema S in database connection D. If S is NULL, then the highest transaction state of any schema on databse connection D is returned. Transaction states are (in order of lowest to highest):

SQLITE_TXN_NONE
SQLITE_TXN_READ
SQLITE_TXN_WRITE

If the S argument to sqlite3_txn_state(D,S) is not the name of a valid schema, then -1 is returned.

You might want to check this:

http://www.sqlite.org/c3ref/get_autocommit.html

According to the page, if you are in a transaction, sqlite3_get_autocommit() will return 0.

Tags:

Sqlite