1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-11-18 10:21:03 +03:00

Add the experimental sqlite3_transaction_hook() API.

FossilOrigin-Name: 093d8cd8e2f3a6af5d40cf810e396f4919eb5cef
This commit is contained in:
dan
2011-03-03 20:05:59 +00:00
parent 46c47d4677
commit 21e8d0126d
11 changed files with 282 additions and 32 deletions

View File

@@ -764,6 +764,26 @@ int sqlite3_close(sqlite3 *db){
return SQLITE_OK;
}
/*
** Invoke the transaction-hook.
*/
void sqlite3TransactionHook(sqlite3 *db, int op, int iLevel){
assert( op==SQLITE_BEGIN || op==SQLITE_COMMIT || op==SQLITE_ROLLBACK );
assert( op==SQLITE_BEGIN || iLevel<db->iOpenTrans || iLevel==0 );
assert( op==SQLITE_BEGIN || iLevel<db->iOpenTrans || db->iOpenTrans==0 );
assert( op!=SQLITE_BEGIN || iLevel==db->iOpenTrans || iLevel==0 );
assert( op!=SQLITE_BEGIN || iLevel==db->iOpenTrans || db->iOpenTrans==1 );
if( op==SQLITE_BEGIN && iLevel!=db->iOpenTrans ) return;
if( op!=SQLITE_BEGIN && iLevel>=db->iOpenTrans ) return;
if( db->xTransCallback ){
db->xTransCallback(db->pTransArg, op, iLevel);
}
db->iOpenTrans = iLevel + (op==SQLITE_BEGIN);
}
/*
** Rollback all database files.
*/
@@ -796,6 +816,10 @@ void sqlite3RollbackAll(sqlite3 *db){
if( db->xRollbackCallback && (inTrans || !db->autoCommit) ){
db->xRollbackCallback(db->pRollbackArg);
}
/* If a transaction-hook is configured, invoke it now to report on
** the rollback operation. */
sqlite3TransactionHook(db, SQLITE_ROLLBACK, 0);
}
/*
@@ -1290,6 +1314,24 @@ void *sqlite3_preupdate_hook(
return pRet;
}
/*
** Register a callback to be invoked each time a transaction or savepoint
** is opened, committed or rolled back.
*/
void *sqlite3_transaction_hook(
sqlite3 *db, /* Database handle */
void(*xCallback)(void *, int, int), /* Callback function */
void *pArg /* First callback argument */
){
void *pRet;
sqlite3_mutex_enter(db->mutex);
pRet = db->pTransArg;
db->xTransCallback = xCallback;
db->pTransArg = pArg;
sqlite3_mutex_leave(db->mutex);
return pRet;
}
#ifndef SQLITE_OMIT_WAL
/*
** The sqlite3_wal_hook() callback registered by sqlite3_wal_autocheckpoint().