Determine if SQLite3 transaction is active

I run END TRANSACTION in my database and sometimes get an error

# 1, which "cannot commit - transaction is inactive"

Is there a way to determine if a transaction is active before trying to commit? I track my "BEGIN TRANSACTIONS" manually, but I feel that there is a better way.

I am using C API

+7
sqlite iphone sqlite3
source share
3 answers

You can check this out:

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

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

+13
source share

This is strange. I thought sqlite was always in a transaction explicitly created by you or implicitly created by sqlite:

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

So, I assume that the error means that it is not in the transaction that you initiated ... and if this is what you need to know, it seems that for the SQL server it seems that you are not behind it. Of course, not very convenient, but I think the cost of a simple API. = /

0
source share

In SQLite, transactions created using BEGIN TRANSACTION ... END TRANSACTION do not nest.

For nested transactions, you need to use the SAVEPOINT and RELEASE commands.

See http://www.sqlite.org/lang_transaction.html

and http://www.sqlite.org/lang_savepoint.html

-one
source share

All Articles