SQLite Forum

Is there a way to detect if committing a transaction will modify the database?
Login

Is there a way to detect if committing a transaction will modify the database?

(1) By anonymous on 2021-02-28 18:29:38 [link] [source]

I have a scenario where I would like to run additional queries in a transaction if the previously executed queries will result in the database being modified upon commit.

sqlite3_total_changes works only for INSERT, UPDATE, and DELETE. I'm looking for something that works for all SQL operations.

SQLITE_FCNTL_DATA_VERSION, on the other hand, seems to work only after committing.

I'm using SQLITE_TEMP_STORE 3 in case it has an impact.

Any ideas? Thanks.

(2) By Keith Medcalf (kmedcalf) on 2021-02-28 19:57:45 in reply to 1 [link] [source]

sqlite3_total_changes works only for INSERT, UPDATE, and DELETE. I'm looking for something that works for all SQL operations.

What other SQL operations that modify data are there other than INSERT, UPDATE, and DELETE?

Note also that just because total_changes increases between the start of a transaction and commit does not mean that there was a change to the database.

(3) By Clemens Ladisch (cladisch) on 2021-02-28 20:15:00 in reply to 2 [link] [source]

The database can also be modified by ALTER, ANALYZE, CREATE, DROP, PRAGMA, or REINDEX.

Anyway, the sqlite3_txn_state() function determines the read/write transaction state.

(4) By anonymous on 2021-02-28 20:46:47 in reply to 3 [source]

Thanks! I somehow managed to click on basically every relevant sounding function in the documentation, except that one. Lol.