aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authordrh <drh@noemail.net>2010-05-05 20:00:25 +0000
committerdrh <drh@noemail.net>2010-05-05 20:00:25 +0000
commit5def0843f1075f85494b63ed326c7061dd5420a8 (patch)
tree8981f28de1016fa4fe20a47825745b60a9c701e8 /src
parentccd13d1f80b3036d63d78c3d8b8bf70a70f200ff (diff)
downloadsqlite-5def0843f1075f85494b63ed326c7061dd5420a8.tar.gz
sqlite-5def0843f1075f85494b63ed326c7061dd5420a8.zip
Change the behavior of the sqlite3_wal_hook() callback. It should now return
SQLITE_OK or an error code and the error code is propagated back up the stack. If a checkpoint is desired, the callback should invoke sqlite3_wal_callback() itself. FossilOrigin-Name: 1b14195e05fe5551992a39246ec3bcf6a33bbfac
Diffstat (limited to 'src')
-rw-r--r--src/main.c17
-rw-r--r--src/sqlite.h.in7
-rw-r--r--src/tclsqlite.c21
-rw-r--r--src/vdbeapi.c6
4 files changed, 26 insertions, 25 deletions
diff --git a/src/main.c b/src/main.c
index 962c857d6..4cd90663f 100644
--- a/src/main.c
+++ b/src/main.c
@@ -1189,19 +1189,20 @@ void *sqlite3_rollback_hook(
#ifndef SQLITE_OMIT_WAL
/*
** The sqlite3_wal_hook() callback registered by sqlite3_wal_autocheckpoint().
-** Return non-zero, indicating to the caller that a checkpoint should be run,
-** if the number of frames in the log file is greater than
-** sqlite3.pWalArg cast to an integer (the value configured by
+** Invoke sqlite3_wal_checkpoint if the number of frames in the log file
+** is greater than sqlite3.pWalArg cast to an integer (the value configured by
** wal_autocheckpoint()).
*/
int sqlite3WalDefaultHook(
- void *p, /* Argument */
+ void *pClientData, /* Argument */
sqlite3 *db, /* Connection */
- const char *zNotUsed, /* Database */
+ const char *zDb, /* Database */
int nFrame /* Size of WAL */
){
- UNUSED_PARAMETER(zNotUsed);
- return ( nFrame>=SQLITE_PTR_TO_INT(p));
+ if( nFrame>=SQLITE_PTR_TO_INT(pClientData) ){
+ sqlite3_wal_checkpoint(db, zDb);
+ }
+ return SQLITE_OK;
}
#endif /* SQLITE_OMIT_WAL */
@@ -1218,13 +1219,11 @@ int sqlite3WalDefaultHook(
*/
int sqlite3_wal_autocheckpoint(sqlite3 *db, int nFrame){
#ifndef SQLITE_OMIT_WAL
- sqlite3_mutex_enter(db->mutex);
if( nFrame>0 ){
sqlite3_wal_hook(db, sqlite3WalDefaultHook, SQLITE_INT_TO_PTR(nFrame));
}else{
sqlite3_wal_hook(db, 0, 0);
}
- sqlite3_mutex_leave(db->mutex);
#endif
return SQLITE_OK;
}
diff --git a/src/sqlite.h.in b/src/sqlite.h.in
index 2672690b7..e59b02c74 100644
--- a/src/sqlite.h.in
+++ b/src/sqlite.h.in
@@ -5780,9 +5780,10 @@ void sqlite3_log(int iErrCode, const char *zFormat, ...);
** is the number of pages currently in the log file, including those that
** were just committed.
**
-** If an invocation of the callback function returns non-zero, then a
-** checkpoint is automatically run on the database. If zero is returned,
-** no special action is taken.
+** The callback function should normally return SQLITE_OK. If an error
+** code is returned, that error will propagate back up through the
+** SQLite code base to cause the statement that provoked the callback
+** to fail.
**
** A single database handle may have at most a single log callback
** registered at one time. Calling [sqlite3_wal_hook()] replaces any
diff --git a/src/tclsqlite.c b/src/tclsqlite.c
index d9d6a7d8a..d8d0fd2b9 100644
--- a/src/tclsqlite.c
+++ b/src/tclsqlite.c
@@ -123,7 +123,7 @@ struct SqliteDb {
SqlFunc *pFunc; /* List of SQL functions */
Tcl_Obj *pUpdateHook; /* Update hook script (if any) */
Tcl_Obj *pRollbackHook; /* Rollback hook script (if any) */
- Tcl_Obj *pLogHook; /* WAL hook script (if any) */
+ Tcl_Obj *pWalHook; /* WAL hook script (if any) */
Tcl_Obj *pUnlockNotify; /* Unlock notify script (if any) */
SqlCollate *pCollate; /* List of SQL collation functions */
int rc; /* Return code of most recent sqlite3_exec() */
@@ -486,8 +486,8 @@ static void DbDeleteCmd(void *db){
if( pDb->pRollbackHook ){
Tcl_DecrRefCount(pDb->pRollbackHook);
}
- if( pDb->pLogHook ){
- Tcl_DecrRefCount(pDb->pLogHook);
+ if( pDb->pWalHook ){
+ Tcl_DecrRefCount(pDb->pWalHook);
}
if( pDb->pCollateNeeded ){
Tcl_DecrRefCount(pDb->pCollateNeeded);
@@ -593,19 +593,22 @@ static void DbRollbackHandler(void *clientData){
}
}
-static int DbLogHandler(
+/*
+** This procedure handles wal_hook callbacks.
+*/
+static int DbWalHandler(
void *clientData,
sqlite3 *db,
const char *zDb,
int nEntry
){
- int ret = 0;
+ int ret = SQLITE_OK;
Tcl_Obj *p;
SqliteDb *pDb = (SqliteDb*)clientData;
Tcl_Interp *interp = pDb->interp;
- assert(pDb->pLogHook);
+ assert(pDb->pWalHook);
- p = Tcl_DuplicateObj(pDb->pLogHook);
+ p = Tcl_DuplicateObj(pDb->pWalHook);
Tcl_IncrRefCount(p);
Tcl_ListObjAppendElement(interp, p, Tcl_NewStringObj(zDb, -1));
Tcl_ListObjAppendElement(interp, p, Tcl_NewIntObj(nEntry));
@@ -2775,7 +2778,7 @@ static int DbObjCmd(void *cd, Tcl_Interp *interp, int objc,Tcl_Obj *const*objv){
if( choice==DB_UPDATE_HOOK ){
ppHook = &pDb->pUpdateHook;
}else if( choice==DB_WAL_HOOK ){
- ppHook = &pDb->pLogHook;
+ ppHook = &pDb->pWalHook;
}else{
ppHook = &pDb->pRollbackHook;
}
@@ -2801,7 +2804,7 @@ static int DbObjCmd(void *cd, Tcl_Interp *interp, int objc,Tcl_Obj *const*objv){
sqlite3_update_hook(pDb->db, (pDb->pUpdateHook?DbUpdateHandler:0), pDb);
sqlite3_rollback_hook(pDb->db,(pDb->pRollbackHook?DbRollbackHandler:0),pDb);
- sqlite3_wal_hook(pDb->db,(pDb->pLogHook?DbLogHandler:0),pDb);
+ sqlite3_wal_hook(pDb->db,(pDb->pWalHook?DbWalHandler:0),pDb);
break;
}
diff --git a/src/vdbeapi.c b/src/vdbeapi.c
index 2a8c1dd18..2f5aaa36d 100644
--- a/src/vdbeapi.c
+++ b/src/vdbeapi.c
@@ -318,10 +318,8 @@ static int doWalCallbacks(sqlite3 *db){
Btree *pBt = db->aDb[i].pBt;
if( pBt ){
int nEntry = sqlite3PagerWalCallback(sqlite3BtreePager(pBt));
- if( db->xWalCallback && nEntry>0 && rc==SQLITE_OK
- && db->xWalCallback(db->pWalArg, db, db->aDb[i].zName, nEntry)
- ){
- rc = sqlite3Checkpoint(db, i);
+ if( db->xWalCallback && nEntry>0 && rc==SQLITE_OK ){
+ rc = db->xWalCallback(db->pWalArg, db, db->aDb[i].zName, nEntry);
}
}
}