Small. Fast. Reliable.
Choose any three.

SQLite C Interface

Commit And Rollback Notification Callbacks

void *sqlite3_commit_hook(sqlite3*, int(*)(void*), void*);
void *sqlite3_rollback_hook(sqlite3*, void(*)(void *), void*);

R-08702-09805:[The sqlite3_commit_hook() interface registers a callback function to be invoked whenever a transaction is committed. ] R-05416-39654:[Any callback set by a previous call to sqlite3_commit_hook() for the same database connection is overridden. ] R-27941-57764:[The sqlite3_rollback_hook() interface registers a callback function to be invoked whenever a transaction is rolled back. ] R-24984-42113:[Any callback set by a previous call to sqlite3_rollback_hook() for the same database connection is overridden. ] R-17269-58859:[The pArg argument is passed through to the callback. ] R-30582-29746:[If the callback on a commit hook function returns non-zero, then the commit is converted into a rollback. ]

R-39719-17021:[The sqlite3_commit_hook(D,C,P) and sqlite3_rollback_hook(D,C,P) functions return the P argument from the previous call of the same function on the same database connection D, or NULL for the first call for each function on D. ]

The commit and rollback hook callbacks are not reentrant. The callback implementation must not do anything that will modify the database connection that invoked the callback. Any actions to modify the database connection must be deferred until after the completion of the sqlite3_step() call that triggered the commit or rollback hook in the first place. Note that running any other SQL statements, including SELECT statements, or merely calling sqlite3_prepare_v2() and sqlite3_step() will modify the database connections for the meaning of "modify" in this paragraph.

R-35460-03740:[Registering a NULL function disables the callback. ]

R-29198-50701:[When the commit hook callback routine returns zero, the COMMIT operation is allowed to continue normally. ] R-14099-28081:[If the commit hook returns non-zero, then the COMMIT is converted into a ROLLBACK. ] R-12556-35327:[The rollback hook is invoked on a rollback that results from a commit hook returning non-zero, just as it would be with any other rollback. ]

R-40541-54897:[For the purposes of this API, a transaction is said to have been rolled back if an explicit "ROLLBACK" statement is executed, or an error or constraint causes an implicit rollback to occur. ] R-60001-20170:[The rollback callback is not invoked if a transaction is automatically rolled back because the database connection is closed. ]

See also the sqlite3_update_hook() interface.

See also lists of Objects, Constants, and Functions.