]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Add the "PRAGMA wal_autocheckpoint" command. Rename "PRAGMA checkpoint" to "PRAGMA...
authordan <dan@noemail.net>
Mon, 3 May 2010 11:05:08 +0000 (11:05 +0000)
committerdan <dan@noemail.net>
Mon, 3 May 2010 11:05:08 +0000 (11:05 +0000)
FossilOrigin-Name: 714e5947264571386f966aa8fcdd5607b5832238

14 files changed:
manifest
manifest.uuid
src/main.c
src/pragma.c
src/sqliteInt.h
src/sqliteLimit.h
src/vdbeapi.c
test/savepoint.test
test/wal.test
test/walbak.test
test/walcrash.test
test/walhook.test
test/walslow.test
test/walthread.test

index e67d5cc39f2f3e17b282ff6c5887fb64928aff85..bfd14bcdd6e3eb64587e5e762bf04505e3bae5d3 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Merge\stwo\swal\sleaves.
-D 2010-05-03T08:19:34
+C Add\sthe\s"PRAGMA\swal_autocheckpoint"\scommand.\sRename\s"PRAGMA\scheckpoint"\sto\s"PRAGMA\swal_checkpoint".
+D 2010-05-03T11:05:09
 F Makefile.arm-wince-mingw32ce-gcc fcd5e9cd67fe88836360bb4f9ef4cb7f8e2fb5a0
 F Makefile.in d83a0ffef3dcbfb08b410a6c6dd6c009ec9167fb
 F Makefile.linux-gcc d53183f4aa6a9192d249731c90dbdffbd2c68654
@@ -131,7 +131,7 @@ F src/journal.c b0ea6b70b532961118ab70301c00a33089f9315c
 F src/legacy.c a199d7683d60cef73089e892409113e69c23a99f
 F src/lempar.c 7f026423f4d71d989e719a743f98a1cbd4e6d99e
 F src/loadext.c 1c7a61ce1281041f437333f366a96aa0d29bb581
-F src/main.c 7aab969e23fea0140bdc2cc6d2b8978e8d9b0090
+F src/main.c d08f2f34e92e5ad7b5ab605a2d22d24e12567efa
 F src/malloc.c a08f16d134f0bfab6b20c3cd142ebf3e58235a6a
 F src/mem0.c 6a55ebe57c46ca1a7d98da93aaa07f99f1059645
 F src/mem1.c 89d4ea8d5cdd55635cbaa48ad53132af6294cbb2
@@ -158,7 +158,7 @@ F src/parse.y ace5c7a125d9f2a410e431ee3209034105045f7e
 F src/pcache.c ace8f6a5ecd4711cc66a1b23053be7109bd437cf
 F src/pcache.h c683390d50f856d4cd8e24342ae62027d1bb6050
 F src/pcache1.c 6dc1871ce8ead9187161c370a58cd06c84221f76
-F src/pragma.c 97c6054d7867b8c5b13023d3dc566274057cd853
+F src/pragma.c 4540555271b98366a408289318c7c1e508d7c8a6
 F src/prepare.c fd1398cb1da54385ba5bd68d93928f10d10a1d9c
 F src/printf.c 5f5b65a83e63f2096a541a340722a509fa0240a7
 F src/random.c cd4a67b3953b88019f8cd4ccd81394a8ddfaba50
@@ -168,8 +168,8 @@ F src/select.c c03d8a0565febcde8c6a12c5d77d065fddae889b
 F src/shell.c c40427c7245535a04a9cb4a417b6cc05c022e6a4
 F src/sqlite.h.in 8097161ad63e2a00e26217da43327d396371c2e5
 F src/sqlite3ext.h 69dfb8116af51b84a029cddb3b35062354270c89
-F src/sqliteInt.h 1f81585797162269a0f18b77c815d552dad636c2
-F src/sqliteLimit.h 3afab2291762b5d09ae20c18feb8e9fa935a60a6
+F src/sqliteInt.h cb2b63a9538b9e79fc41b6d5026703600ab84407
+F src/sqliteLimit.h 196e2f83c3b444c4548fc1874f52f84fdbda40f3
 F src/status.c 4df6fe7dce2d256130b905847c6c60055882bdbe
 F src/table.c 2cd62736f845d82200acfa1287e33feb3c15d62e
 F src/tclsqlite.c 4de81521174fedacd8393ea7b70b730ce17f8eae
@@ -215,7 +215,7 @@ F src/vacuum.c 8e7d9a6fd076774bb6e211cad335c7337948a164
 F src/vdbe.c 8be37a1b18786b5c026adcb2e9edc93e3a940885
 F src/vdbe.h 471f6a3dcec4817ca33596fe7f6654d56c0e75f3
 F src/vdbeInt.h 19ebc8c2a2e938340051ee65af3f377fb99102d1
-F src/vdbeapi.c 810abe698db3ccaf67c5a8982f8cd4f31c6c902f
+F src/vdbeapi.c cf1ff7cbcbd44d2082af71b98762407ae01ce009
 F src/vdbeaux.c 395d21a1617553ea9b9f4abe0d302449d8549e1d
 F src/vdbeblob.c 5327132a42a91e8b7acfb60b9d2c3b1c5c863e0e
 F src/vdbemem.c 2a82f455f6ca6f78b59fb312f96054c04ae0ead1
@@ -548,7 +548,7 @@ F test/rollback.test 73355ad4492ff9a3a31e61c7e5eb5e01a1de94ca
 F test/rowhash.test 97f56043ba11f0679920416c0cdbc72e5272267b
 F test/rowid.test e58e0acef38b527ed1b0b70d3ada588f804af287
 F test/rtree.test 55466a200af3591946c5da77ad5dbfbc1e5e05f9
-F test/savepoint.test 500ef5afb383107fd3b7d055cdeb015d36d1bc76
+F test/savepoint.test 14f78c2c2538764850b38446957048113cc24f75
 F test/savepoint2.test 9b8543940572a2f01a18298c3135ad0c9f4f67d7
 F test/savepoint3.test e328085853b14898d78ceea00dfe7db18bb6a9ec
 F test/savepoint4.test c8f8159ade6d2acd9128be61e1230f1c1edc6cc0
@@ -758,13 +758,13 @@ F test/vtabE.test 7c4693638d7797ce2eda17af74292b97e705cc61
 F test/vtab_alter.test 9e374885248f69e251bdaacf480b04a197f125e5
 F test/vtab_err.test 0d4d8eb4def1d053ac7c5050df3024fd47a3fbd8
 F test/vtab_shared.test 0eff9ce4f19facbe0a3e693f6c14b80711a4222d
-F test/wal.test 4ff92f36495142420ce8c2bb45340dcad714a1e5
-F test/walbak.test fad10a10df78ab67e89a8779ddc3c0d230460693
-F test/walcrash.test 20ebd86c0ea1bfdec97987c3cf667118f5c74a84
-F test/walhook.test 5ee5fd35cdc3763d5674da0dd9974f6f70c07bed
+F test/wal.test 9f142c65c436b209ffdce0eba37b1b90d2998c1a
+F test/walbak.test a0e45187c7d8928df035dfea29b99b016b21ca3c
+F test/walcrash.test 63edc6a9e05f645b54d649186a5818fc82953e2e
+F test/walhook.test 5f18e0fc8787f1f8889d7a9971af18f334f83786
 F test/walmode.test bac6f06544a8554588a1543def996bbe2fc41792
-F test/walslow.test 9be52d033e871cb608a18fa4425a6dc64b625377
-F test/walthread.test 4ef06a22d0d207aecba8cd11add820f6e7e94c43
+F test/walslow.test d21625e2e99e11c032ce949e8a94661576548933
+F test/walthread.test cc3c5302dfd56361def4023b7f29d361f1f1602d
 F test/where.test de337a3fe0a459ec7c93db16a519657a90552330
 F test/where2.test 43d4becaf5a5df854e6c21d624a1cb84c6904554
 F test/where3.test aa44a9b29e8c9f3d7bb94a3bb3a95b31627d520d
@@ -808,7 +808,7 @@ F tool/speedtest2.tcl ee2149167303ba8e95af97873c575c3e0fab58ff
 F tool/speedtest8.c 2902c46588c40b55661e471d7a86e4dd71a18224
 F tool/speedtest8inst1.c 293327bc76823f473684d589a8160bde1f52c14e
 F tool/vdbe-compress.tcl d70ea6d8a19e3571d7ab8c9b75cba86d1173ff0f
-P 9803196dec85e3aa4105cc477e9cfe98d370e486 94dea5f9c11a68564220cec76ac3fae2ba90e907
-R 788341a84b9fc72cb664689f96e77759
+P 23c0e6c3f333e878fe5a2ae5d61df0d765f437b4
+R f8f9e7aa1d48de791ac4d31549cb2c66
 U dan
-Z 74b01ac5f69a8df35f22fcc654a97307
+Z 864d996940b21341339cd035e1e7f0cc
index f4ae2cc983157f120efa752130224e28e79a1438..3309d97d6c63c86cc03c2fadb3863d18adc26763 100644 (file)
@@ -1 +1 @@
-23c0e6c3f333e878fe5a2ae5d61df0d765f437b4
\ No newline at end of file
+714e5947264571386f966aa8fcdd5607b5832238
\ No newline at end of file
index c714e03ffff81d0605c124c0da5370507db6b005..f6a343e85f724647368360c32133ff9cd7ff427e 100644 (file)
@@ -1191,12 +1191,12 @@ void *sqlite3_rollback_hook(
 ** 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.nDefaultCheckpoint (the value configured by wal_autocheckpoint()).
+** sqlite3.nAutoCheckpoint (the value configured by wal_autocheckpoint()).
 */ 
 static int defaultWalHook(void *p, sqlite3 *db, const char *z, int nFrame){
   UNUSED_PARAMETER(p);
   UNUSED_PARAMETER(z);
-  return ( nFrame>=db->nDefaultCheckpoint );
+  return ( nFrame>=db->nAutoCheckpoint );
 }
 
 /*
@@ -1213,8 +1213,8 @@ static int defaultWalHook(void *p, sqlite3 *db, const char *z, int nFrame){
 int sqlite3_wal_autocheckpoint(sqlite3 *db, int nFrame){
   sqlite3_mutex_enter(db->mutex);
   if( nFrame>0 ){
-    db->nDefaultCheckpoint = nFrame;
     sqlite3_wal_hook(db, defaultWalHook, 0);
+    db->nAutoCheckpoint = nFrame;
   }else{
     sqlite3_wal_hook(db, 0, 0);
   }
@@ -1236,6 +1236,7 @@ void *sqlite3_wal_hook(
   pRet = db->pWalArg;
   db->xWalCallback = xCallback;
   db->pWalArg = pArg;
+  db->nAutoCheckpoint = 0;
   sqlite3_mutex_leave(db->mutex);
   return pRet;
 }
@@ -1870,7 +1871,7 @@ static int openDatabase(
   setupLookaside(db, 0, sqlite3GlobalConfig.szLookaside,
                         sqlite3GlobalConfig.nLookaside);
 
-  sqlite3_wal_autocheckpoint(db, SQLITE_DEFAULT_CACHE_SIZE);
+  sqlite3_wal_autocheckpoint(db, SQLITE_DEFAULT_WAL_AUTOCHECKPOINT);
 
 opendb_out:
   if( db ){
index 7e4c0b3f6bc8fe18a3575bf91a5a3a436cb7265d..0d2be03daf967fcd8b98efbc97e81e84735d9c1c 100644 (file)
@@ -1402,13 +1402,30 @@ void sqlite3Pragma(
 
 #ifndef SQLITE_OMIT_WAL
   /*
-  **   PRAGMA [database.]checkpoint
+  **   PRAGMA [database.]wal_checkpoint
   **
   ** Checkpoint the database.
   */
-  if( sqlite3StrICmp(zLeft, "checkpoint")==0 ){
+  if( sqlite3StrICmp(zLeft, "wal_checkpoint")==0 ){
+    if( sqlite3ReadSchema(pParse) ) goto pragma_out;
     sqlite3VdbeAddOp3(v, OP_Checkpoint, iDb, 0, 0);
   }else
+
+  /*
+  **   PRAGMA wal_autocheckpoint
+  **   PRAGMA wal_autocheckpoint = N
+  **
+  ** Configure a database connection to automatically checkpoint a database
+  ** after accumulating N frames in the log. Or query for the current value
+  ** of N.
+  */
+  if( sqlite3StrICmp(zLeft, "wal_autocheckpoint")==0 ){
+    if( zRight ){
+      int nAuto = atoi(zRight);
+      sqlite3_wal_autocheckpoint(db, nAuto);
+    }
+    returnSingleInt(pParse, "wal_autocheckpoint", db->nAutoCheckpoint);
+  }else
 #endif
 
 #if defined(SQLITE_DEBUG) || defined(SQLITE_TEST)
index ccc03432af8d6851b6a38c68aff553f8d76c31b9..c216816f6aa5e459ee131beb5aefccae03a8f782 100644 (file)
@@ -824,7 +824,7 @@ struct sqlite3 {
   void *pUpdateArg;
   void (*xUpdateCallback)(void*,int, const char*,const char*,sqlite_int64);
 #ifndef SQLITE_OMIT_WAL
-  int nDefaultCheckpoint;       /* Value configured by wal_autocheckpoint() */
+  int nAutoCheckpoint;          /* Value configured by wal_autocheckpoint() */
   int (*xWalCallback)(void *, sqlite3 *, const char *, int);
   void *pWalArg;
 #endif
index faf80d4378d60267640fdadf995494abe6426c89..1dc5d675dabdd0f6f2a0ffad2e01f11ac354cc40 100644 (file)
 # define SQLITE_DEFAULT_TEMP_CACHE_SIZE  500
 #endif
 
+/*
+** The default number of frames to accumulate in the log file before
+** checkpointing the database in WAL mode.
+*/
+#ifndef SQLITE_DEFAULT_WAL_AUTOCHECKPOINT
+# define SQLITE_DEFAULT_WAL_AUTOCHECKPOINT  1000
+#endif
+
 /*
 ** The maximum number of attached databases.  This must be between 0
 ** and 30.  The upper bound on 30 is because a 32-bit integer bitmap
index 5aec7ca0f67b05e111fd64582a11164afcdade57..f16cc1be08545e8d2dd3675570057b23e9dbec22 100644 (file)
@@ -321,7 +321,7 @@ static int doWalCallbacks(sqlite3 *db){
       if( db->xWalCallback && nEntry>0 && rc==SQLITE_OK
        && db->xWalCallback(db->pWalArg, db, db->aDb[i].zName, nEntry)
       ){
-        rc = sqlite3PagerCheckpoint(sqlite3BtreePager(pBt));
+        rc = sqlite3Checkpoint(db, i);
       }
     }
   }
index bd385308367e762c10099d6e479821700dca4538..ab198baddeda53c5bd6a365e5791d7b90a49a802 100644 (file)
@@ -792,7 +792,7 @@ do_test savepoint-11.6 {
 integrity_check savepoint-11.7
 do_test savepoint-11.8 {
   execsql { ROLLBACK }
-  execsql { PRAGMA checkpoint }
+  execsql { PRAGMA wal_checkpoint }
   file size test.db
 } {8192}
 
index 1f032cac320b635525b2658aa3d43f2baebcbadf..e5c1d6cdc1dee0cd59325da09948bfc893c9710e 100644 (file)
@@ -349,7 +349,7 @@ do_test wal-7.1 {
   list [file size test.db] [file size test.db-wal]
 } [list 1024 [log_file_size 3 1024]]
 do_test wal-7.2 {
-  execsql { PRAGMA checkpoint }
+  execsql { PRAGMA wal_checkpoint }
   list [file size test.db] [file size test.db-wal]
 } [list 2048 [log_file_size 3 1024]]
 
@@ -380,14 +380,14 @@ do_test wal-8.2 {
     INSERT INTO t1 SELECT blob(900) FROM t1;       /* 16 */
     INSERT INTO t1 SELECT blob(900) FROM t1;       /* 32 */
     INSERT INTO t1 SELECT blob(900) FROM t1;       /* 64 */
-    PRAGMA checkpoint;
+    PRAGMA wal_checkpoint;
   }
   file size test.db
 } [expr 68*1024]
 do_test wal-8.3 {
   execsql { 
     DELETE FROM t1 WHERE rowid<54;
-    PRAGMA checkpoint;
+    PRAGMA wal_checkpoint;
   }
   file size test.db
 } [expr 14*1024]
@@ -426,7 +426,7 @@ do_test wal-9.3 {
 db3 close
 
 do_test wal-9.4 {
-  execsql { PRAGMA checkpoint }
+  execsql { PRAGMA wal_checkpoint }
   db2 close
   sqlite3_wal db2 test.db
   execsql {PRAGMA integrity_check } db2
@@ -549,7 +549,7 @@ foreach code [list {
     sql2 { BEGIN; SELECT * FROM t1 }
   } {1 2 3 4 5 6 7 8 9 10}
   do_test wal-10.$tn.12 {
-    catchsql { PRAGMA checkpoint } 
+    catchsql { PRAGMA wal_checkpoint } 
   } {1 {database is locked}}
   do_test wal-10.$tn.13 {
     execsql { INSERT INTO t1 VALUES(11, 12) }
@@ -568,7 +568,7 @@ foreach code [list {
   }
   db busy busyhandler
   do_test wal-10.$tn.14 {
-    execsql { PRAGMA checkpoint } 
+    execsql { PRAGMA wal_checkpoint } 
   } {}
 
   # Similar to the test above. Except this time, a new read transaction is
@@ -582,7 +582,7 @@ foreach code [list {
     sql2 { BEGIN; SELECT * FROM t1; }
   } {1 2 3 4 5 6 7 8 9 10 11 12}
   do_test wal-10.$tn.16 {
-    catchsql { PRAGMA checkpoint } 
+    catchsql { PRAGMA wal_checkpoint } 
   } {1 {database is locked}}
   proc busyhandler x {
     if {$x==3} { sql3 { BEGIN; SELECT * FROM t1 } }
@@ -592,7 +592,7 @@ foreach code [list {
   }
   db busy busyhandler
   do_test wal-10.$tn.17 {
-    execsql { PRAGMA checkpoint } 
+    execsql { PRAGMA wal_checkpoint } 
   } {}
   do_test wal-10.$tn.18 {
     sql3 { SELECT * FROM t1 }
@@ -616,13 +616,13 @@ foreach code [list {
   # (as [db3] still has a snapshot locked).
   #
   do_test wal-10.$tn.23 {
-    execsql { PRAGMA checkpoint }
+    execsql { PRAGMA wal_checkpoint }
   } {}
   do_test wal-10.$tn.24 {
     sql2 { BEGIN; SELECT * FROM t1; }
   } {1 2 3 4 5 6 7 8 9 10 11 12 13 14}
   do_test wal-10.$tn.25 {
-    execsql { PRAGMA checkpoint }
+    execsql { PRAGMA wal_checkpoint }
   } {}
   do_test wal-10.$tn.26 {
     catchsql { INSERT INTO t1 VALUES(15, 16) }
@@ -641,11 +641,11 @@ foreach code [list {
   db busy {}
   do_test wal-10.$tn.29 {
     execsql { INSERT INTO t1 VALUES(17, 18) }
-    catchsql { PRAGMA checkpoint }
+    catchsql { PRAGMA wal_checkpoint }
   } {1 {database is locked}}
   do_test wal-10.$tn.30 {
     code3 { sqlite3_finalize $::STMT }
-    execsql { PRAGMA checkpoint }
+    execsql { PRAGMA wal_checkpoint }
   } {}
 
   # At one point, if a reader failed to upgrade to a writer because it
@@ -685,7 +685,7 @@ foreach code [list {
   proc busyhandler x { return 1 }
   db busy busyhandler
   do_test wal-10.$tn.36 {
-    catchsql { PRAGMA checkpoint }
+    catchsql { PRAGMA wal_checkpoint }
   } {1 {database is locked}}
   do_test wal-10.$tn.36 {
     sql3 { INSERT INTO t1 VALUES('e', 'f') }
@@ -693,7 +693,7 @@ foreach code [list {
   } {a b c d}
   do_test wal-10.$tn.37 {
     sql2 COMMIT
-    execsql { PRAGMA checkpoint }
+    execsql { PRAGMA wal_checkpoint }
   } {}
 
   catch { db close }
@@ -718,7 +718,7 @@ do_test wal-11.1 {
   list [expr [file size test.db]/1024] [expr [file size test.db-wal]/1044]
 } {1 3}
 do_test wal-11.2 {
-  execsql { PRAGMA checkpoint }
+  execsql { PRAGMA wal_checkpoint }
   list [expr [file size test.db]/1024] [file size test.db-wal]
 } [list 3 [log_file_size 3 1024]]
 do_test wal-11.3 {
@@ -753,7 +753,7 @@ do_test wal-11.7 {
   }
 } {16 ok}
 do_test wal-11.8 {
-  execsql { PRAGMA checkpoint }
+  execsql { PRAGMA wal_checkpoint }
   list [expr [file size test.db]/1024] [file size test.db-wal]
 } [list 37 [log_file_size 41 1024]]
 do_test wal-11.9 {
@@ -829,11 +829,11 @@ do_test wal-12.4 {
 db2 close
 do_test wal-12.5 {
   execsql {
-    PRAGMA checkpoint;
+    PRAGMA wal_checkpoint;
     UPDATE t2 SET y = 2 WHERE x = 'B'; 
-    PRAGMA checkpoint;
+    PRAGMA wal_checkpoint;
     UPDATE t1 SET y = 1 WHERE x = 'A';
-    PRAGMA checkpoint;
+    PRAGMA wal_checkpoint;
     UPDATE t1 SET y = 0 WHERE x = 'A';
     SELECT * FROM t2;
   }
@@ -955,11 +955,11 @@ do_test wal-14 {
     INSERT INTO t1 SELECT randomblob(10), randomblob(100);
   }
 
-  # After executing the "PRAGMA checkpoint", connection [db] was being
+  # After executing the "PRAGMA wal_checkpoint", connection [db] was being
   # left with an inconsistent cache. Running the CREATE INDEX statement
   # in this state led to database corruption.
   catchsql { 
-    PRAGMA checkpoint;
+    PRAGMA wal_checkpoint;
     CREATE INDEX i1 on t1(b);
   }
    
index 4028aa4d56bbce9fdff140e8b66ad1cd63bc890a..63c1e2fa31e5a15e2b7ca81128384a3df9043844 100644 (file)
@@ -71,7 +71,7 @@ do_test walbak-1.5 {
   list [file size test.db] [file size test.db-wal]
 } [list 1024 [log_file_size 6 1024]]
 do_test walbak-1.6 {
-  execsql { PRAGMA checkpoint }
+  execsql { PRAGMA wal_checkpoint }
   list [file size test.db] [file size test.db-wal]
 } [list [expr 3*1024] [log_file_size 6 1024]]
 do_test walbak-1.7 {
@@ -87,7 +87,7 @@ do_test walbak-1.8 {
   list [file size test.db] [file size test.db-wal]
 } [list [expr 3*1024] [log_file_size 8 1024]]
 do_test walbak-1.9 {
-  execsql { PRAGMA checkpoint }
+  execsql { PRAGMA wal_checkpoint }
   list [file size test.db] [file size test.db-wal]
 } [list [expr 2*1024] [log_file_size 8 1024]]
 
index dc718b0d29b20efcd4fbe376d8075162a0373be9..47f454c1e906eb2637312873adb6661346575e04 100644 (file)
@@ -192,7 +192,7 @@ for {set i 1} {$i < $REPEATS} {incr i} {
       INSERT INTO t1 SELECT randomblob(900) FROM t1 LIMIT 4;   /* 28 */
       INSERT INTO t1 SELECT randomblob(900) FROM t1 LIMIT 4;   /* 32 */
 
-      PRAGMA checkpoint;
+      PRAGMA wal_checkpoint;
       INSERT INTO t1 VALUES(randomblob(900));
       INSERT INTO t1 VALUES(randomblob(900));
       INSERT INTO t1 VALUES(randomblob(900));
@@ -233,7 +233,7 @@ for {set i 1} {$i < $REPEATS} {incr i} {
       INSERT INTO t1 SELECT randomblob(900) FROM t1 LIMIT 4;   /* 28 */
       INSERT INTO t1 SELECT randomblob(900) FROM t1 LIMIT 4;   /* 32 */
 
-      PRAGMA checkpoint;
+      PRAGMA wal_checkpoint;
       INSERT INTO t1 VALUES(randomblob(900));
       INSERT INTO t1 VALUES(randomblob(900));
       INSERT INTO t1 VALUES(randomblob(900));
@@ -260,9 +260,9 @@ for {set i 1} {$i < $REPEATS} {incr i} {
         CREATE TABLE t1(a, b);
         INSERT INTO t1 VALUES(1, 2);
       COMMIT;
-      PRAGMA checkpoint;
+      PRAGMA wal_checkpoint;
       CREATE INDEX i1 ON t1(a);
-      PRAGMA checkpoint;
+      PRAGMA wal_checkpoint;
     }
   } {1 {child process exited abnormally}}
 
index 49f07dda53a4cf42330d9c938647566f502b7bab..05f543d2c84c02967967db4072679f9bb6fd3d24 100644 (file)
 # This file implements regression tests for SQLite library.  The
 # focus of this file is testing the operation of the library in
 # "PRAGMA journal_mode=WAL" mode.
+# 
+# More specifically, this file contains regression tests for the 
+# sqlite3_wal_hook() mechanism, including the sqlite3_wal_autocheckpoint()
+# and "PRAGMA wal_autocheckpoint" convenience interfaces.
 #
 
 set testdir [file dirname $argv0]
@@ -18,27 +22,27 @@ source $testdir/tester.tcl
 
 ifcapable !wal {finish_test ; return }
 
-proc sqlite3_wal {args} {
-  eval sqlite3 $args
-  [lindex $args 0] eval { 
-    PRAGMA journal_mode = wal;
-    PRAGMA synchronous = normal;
-    PRAGMA page_size = 1024;
-  }
+proc log_file_size {nFrame pgsz} {
+  expr {12 + ($pgsz+16)*$nFrame}
 }
-sqlite3_wal db test.db
-db wal_hook wal_hook
 
 set ::wal_hook [list]
 proc wal_hook {zDb nEntry} {
   lappend ::wal_hook $zDb $nEntry
   return 0
 }
+db wal_hook wal_hook
 
 do_test walhook-1.1 {
-  execsql { CREATE TABLE t1(i PRIMARY KEY, j) }
+  execsql { 
+    PRAGMA page_size = 1024;
+    PRAGMA journal_mode = wal;
+    PRAGMA synchronous = normal;
+    CREATE TABLE t1(i PRIMARY KEY, j);
+  }
   set ::wal_hook
 } {main 3}
+
 do_test walhook-1.2 {
   set ::wal_hook [list]
   execsql { INSERT INTO t1 VALUES(1, 'one') }
@@ -49,10 +53,9 @@ do_test walhook-1.3 {
   execsql { INSERT INTO t1 VALUES(2, 'two') }
   file size test.db
 } [expr 3*1024]
-
 do_test walhook-1.4 {
   proc wal_hook {zDb nEntry} { 
-    execsql { PRAGMA checkpoint }
+    execsql { PRAGMA wal_checkpoint }
     return 0
   }
   execsql { CREATE TABLE t2(a, b) }
@@ -60,15 +63,49 @@ do_test walhook-1.4 {
 } [expr 4*1024]
 
 do_test walhook-1.5 {
-  sqlite3_wal db2 test.db
-  proc wal_hook {zDb nEntry} { 
-    execsql { PRAGMA checkpoint } db2
+  sqlite3 db2 test.db
+  proc wal_hook {zDb nEntry} {
+    execsql { PRAGMA wal_checkpoint } db2
     return 0
   }
   execsql { CREATE TABLE t3(a PRIMARY KEY, b) }
   file size test.db
 } [expr 6*1024]
 
+db2 close
+db close
+sqlite3 db test.db
+do_test walhook-2.1 {
+  execsql { PRAGMA synchronous = NORMAL }
+  execsql { PRAGMA wal_autocheckpoint }
+} {1000}
+do_test walhook-2.2 {
+  execsql { PRAGMA wal_autocheckpoint = 10}
+} {10}
+do_test walhook-2.3 {
+  execsql { PRAGMA wal_autocheckpoint }
+} {10}
+
+#
+# The database connection is configured with "PRAGMA wal_autocheckpoint = 10".
+# Check that transactions are written to the log file until it contains at
+# least 10 frames, then the database is checkpointed. Subsequent transactions
+# are written into the start of the log file.
+#
+foreach {tn sql dbpages logpages} {
+  4 "CREATE TABLE t4(x PRIMARY KEY, y)"   6   3
+  5 "INSERT INTO t4 VALUES(1, 'one')"     6   5
+  6 "INSERT INTO t4 VALUES(2, 'two')"     6   7
+  7 "INSERT INTO t4 VALUES(3, 'three')"   6   9
+  8 "INSERT INTO t4 VALUES(4, 'four')"    8  11
+  9 "INSERT INTO t4 VALUES(5, 'five')"    8  11
+} {
+  do_test walhook-2.$tn {
+    execsql $sql
+    list [file size test.db] [file size test.db-wal]
+  } [list [expr $dbpages*1024] [log_file_size $logpages 1024]]
+}
+
 catch { db2 close }
 catch { db close }
 finish_test
index 25e252bbb4675b75cf7aa273b6c66dedc6bc36af..d726952804a0a40d98d8c220a1086517399d3286 100644 (file)
@@ -48,7 +48,7 @@ for {set seed 1} {$seed<10} {incr seed} {
     } {ok}
 
     do_test walslow-1.seed=$seed.$iTest.2 {
-      execsql "PRAGMA checkpoint;"
+      execsql "PRAGMA wal_checkpoint;"
       execsql { PRAGMA integrity_check }
     } {ok}
 
index 59f38d3e99dc75943b5614ec83be1605344e4bfb..4aa1e2c2c3547df8a786839f12968a375ada892e 100644 (file)
@@ -241,7 +241,7 @@ proc do_thread_test2 {args} {
 #
 # There is also a single checkpointer thread. It runs the following loop:
 #
-#   1) Execute "PRAGMA checkpoint"
+#   1) Execute "PRAGMA wal_checkpoint"
 #   2) Sleep for 500 ms.
 #
 do_thread_test2 walthread-1 -seconds $seconds(walthread-1) -init {
@@ -295,7 +295,7 @@ do_thread_test2 walthread-1 -seconds $seconds(walthread-1) -init {
 } -thread ckpt 1 {
   set nRun 0
   while {[tt_continue]} {
-    db eval "PRAGMA checkpoint"
+    db eval "PRAGMA wal_checkpoint"
     usleep 500
     incr nRun
   }