]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Fix test cases so that they work with SQLITE_DEFAULT_WAL_SAFETYLEVEL defined.
authordan <dan@noemail.net>
Sat, 25 Jun 2011 16:35:41 +0000 (16:35 +0000)
committerdan <dan@noemail.net>
Sat, 25 Jun 2011 16:35:41 +0000 (16:35 +0000)
FossilOrigin-Name: 8f8b373eed7052e6e93c1805fc1effcf1db09366

12 files changed:
manifest
manifest.uuid
src/btree.c
test/incrvacuum2.test
test/pager1.test
test/superlock.test
test/wal.test
test/wal2.test
test/wal3.test
test/wal5.test
test/wal_common.tcl
test/walmode.test

index e51ce7219d801e777b67fa3acda559054127ea0c..d5c4c7ec0ae1e4cb02fb1b4270d5a9204d1e9f22 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Fix\sthe\sbuild.
-D 2011-06-24T21:47:39.109
+C Fix\stest\scases\sso\sthat\sthey\swork\swith\sSQLITE_DEFAULT_WAL_SAFETYLEVEL\sdefined.
+D 2011-06-25T16:35:41.980
 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f
 F Makefile.in 8410b02448997eb43bdf0ffa482c9bc2d2624e45
 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23
@@ -127,7 +127,7 @@ F src/auth.c 523da7fb4979469955d822ff9298352d6b31de34
 F src/backup.c 986c15232757f2873dff35ee3b35cbf935fc573c
 F src/bitvec.c af50f1c8c0ff54d6bdb7a80e2fceca5a93670bef
 F src/btmutex.c 976f45a12e37293e32cae0281b15a21d48a8aaa7
-F src/btree.c fea8eaab6b7bf0877e35a44827049226e2c397ec
+F src/btree.c 43581d03fc1b0fc8afa7790a26bf680161394d13
 F src/btree.h f5d775cd6cfc7ac32a2535b70e8d2af48ef5f2ce
 F src/btreeInt.h 67978c014fa4f7cc874032dd3aacadd8db656bc3
 F src/build.c 5a428625d21ad409514afb40ad083bee25dd957a
@@ -508,7 +508,7 @@ F test/incrblob3.test 086482e7937202be9f8cf327117a042d8628fe7d
 F test/incrblob_err.test c577c91d4ed9e8336cdb188b15d6ee2a6fe9604e
 F test/incrblobfault.test 917c0292224c64a56ef7215fd633a3a82f805be0
 F test/incrvacuum.test 453d1e490d8f5ad2c9b3a54282a0690d6ae56462
-F test/incrvacuum2.test ae04573b73ad52179f56e194fff0fbe43b509d23
+F test/incrvacuum2.test 08b23884a3acc8f5027385adafede3a0b044e3f9
 F test/incrvacuum_ioerr.test 57d2f5777ab13fa03b87b262a4ea1bad5cfc0291
 F test/index.test b5429732b3b983fa810e3ac867d7ca85dae35097
 F test/index2.test ee83c6b5e3173a3d7137140d945d9a5d4fdfb9d6
@@ -610,7 +610,7 @@ F test/notnull.test cc7c78340328e6112a13c3e311a9ab3127114347
 F test/null.test a8b09b8ed87852742343b33441a9240022108993
 F test/openv2.test af02ed0a9cbc0d2a61b8f35171d4d117e588e4ec
 F test/oserror.test 3fe52e0bd2891a9bf7cdeb639554992453d46301
-F test/pager1.test 4b7c08cab0717a051e9faf093d23ac202a280050
+F test/pager1.test 52725f1e15e02ec651921a7cd1083c3d0052a9c4
 F test/pager2.test 745b911dde3d1f24ae0870bd433dfa83d7c658c1
 F test/pager3.test 3856d9c80839be0668efee1b74811b1b7f7fc95f
 F test/pagerfault.test b0a275779f0b0233809d2644dec94d689357e00a
@@ -690,7 +690,7 @@ F test/stmt.test 78a6764439cfa5abdcbf98d4d084739e81eeec4f
 F test/subquery.test b524f57c9574b2c0347045b4510ef795d4686796
 F test/subselect.test d24fd8757daf97dafd2e889c73ea4c4272dcf4e4
 F test/substr.test 18f57c4ca8a598805c4d64e304c418734d843c1a
-F test/superlock.test 9c567d759fe383abefde0e801e36a3b3aadb082e
+F test/superlock.test b68339e473d26cdeabe784ef14d7522334ec22c3
 F test/sync.test 2bd73b585089c99e76b3e1796c42059b7d89d872
 F test/syscall.test 707c95e4ab7863e13f1293c6b0c76bead30249b3
 F test/sysfault.test c79441d88d23696fbec7b147dba98d42a04f523f
@@ -880,14 +880,14 @@ 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 3ff610479cd005117f54a8c003a8d86432e6f2ac
-F test/wal2.test 6c65a48c23309baec605d8b14dbc41c2d5baceb0
-F test/wal3.test 804be49c55b362c356f2b98cd8bac77145cfa647
+F test/wal.test c2df96d6f209076fe0571054eedfc4879d1c8a3a
+F test/wal2.test aaeac9c0f901cb3a779a49a5100decc615f04d76
+F test/wal3.test a4670279d6ed3fc4e0355d0e77882f7f46d54bbc
 F test/wal4.test 6a68c45bc1ca24a3592ec449ddcb92b29d0e0e87
-F test/wal5.test f06a0427e06db00347e32eb9fa99d6a5c0f2d088
+F test/wal5.test ad9865a6e39bfcf62c96f075e4c31838295b6509
 F test/wal6.test 8df39843b1471dc02993d173937b2c6589e2cb59
 F test/wal7.test 2ae8f427d240099cc4b2dfef63cff44e2a68a1bd
-F test/wal_common.tcl a98f17fba96206122eff624db0ab13ec377be4fe
+F test/wal_common.tcl 15f152fd55703975878741beca6cfa4209d5b3b3
 F test/walbak.test 767e1c9e0ea0cfb907873b332883e66e187fa4bc
 F test/walbig.test 78ac493db2abdb65b9c6cace5b851cc32df1d449
 F test/walcksum.test cf6787f2ee1a6a3da6f0c2b20b9ede5153e4e03f
@@ -895,7 +895,7 @@ F test/walcrash.test 80c1cc3173a0ef09d8303fa556cb0187a36d82ea
 F test/walcrash2.test c032d0040374ae28b41f99fc0cc290b4e2e34f17
 F test/walfault.test 7db81f3dac64ce8897196f199c2909078bcabf8d
 F test/walhook.test c934ac5219fee2b4e7653d291db9107b8dc73bba
-F test/walmode.test feb39956ec6f415fbb9dcb12d91243391c2c4715
+F test/walmode.test 8fe643a94841a1f95186e91e220181429f1188c1
 F test/walnoshm.test a074428046408f4eb5c6a00e09df8cc97ff93317
 F test/walro.test 05769ae10ddce1b6ad41bdd5326ab7ef951c8278
 F test/walshared.test 0befc811dcf0b287efae21612304d15576e35417
@@ -954,7 +954,7 @@ F tool/symbols.sh bc2a3709940d47c8ac8e0a1fdf17ec801f015a00
 F tool/tostr.awk 11760e1b94a5d3dcd42378f3cc18544c06cfa576
 F tool/vdbe-compress.tcl d70ea6d8a19e3571d7ab8c9b75cba86d1173ff0f
 F tool/warnings.sh 347d974d143cf132f953b565fbc03026f19fcb4d
-P 34f0efa2b12e8eb09331768b1524a076baeb34ea
-R 768b5e530139c389ea55389c2df533b2
-U drh
-Z 525590b6735d93e452cf9134dab9e566
+P 97729542d53a407de1bdfeb5fa6d80bbdb4813b6
+R b0d94ba47dd23ef5ad400f41b1e77ddd
+U dan
+Z 21e66d4037d33761682c45f3b2e0d19c
index 1c38a9f5ad008fbbe1059faf5fbfb6744b936d23..9cf83a0b420c47d9a405dbb1a93c54332a7045bc 100644 (file)
@@ -1 +1 @@
-97729542d53a407de1bdfeb5fa6d80bbdb4813b6
\ No newline at end of file
+8f8b373eed7052e6e93c1805fc1effcf1db09366
\ No newline at end of file
index 3a58cbdc21f2ce828e32a97a56c3836eafca45f8..a63759bfb9f93d691416b6fc502c6d95e8cc5291 100644 (file)
@@ -2359,9 +2359,15 @@ static int lockBtree(BtShared *pBt){
 #ifdef SQLITE_DEFAULT_WAL_SAFETYLEVEL
         /* Default to specified safety_level for WAL mode */
         if( pBt->db!=0 && pBt->db->aDb!=0 ){
+          int iDb;
           sqlite3 *db = pBt->db;
-          if( db->aDb[0].safety_level != SQLITE_DEFAULT_WAL_SAFETYLEVEL) {
-            db->aDb[0].safety_level = SQLITE_DEFAULT_WAL_SAFETYLEVEL;
+          Db *aDb = db->aDb;
+          for(iDb=0; iDb<db->nDb; iDb++){
+            if( aDb[iDb].pBt && aDb[iDb].pBt->pBt==pBt ) break;
+          }
+          assert( iDb<db->nDb );
+          if( aDb[iDb].safety_level != SQLITE_DEFAULT_WAL_SAFETYLEVEL) {
+            aDb[iDb].safety_level = SQLITE_DEFAULT_WAL_SAFETYLEVEL;
             sqlite3PagerSetSafetyLevel(pBt->pPager, SQLITE_DEFAULT_WAL_SAFETYLEVEL, 
                                        (db->flags&SQLITE_FullFSync)!=0,
                                        (db->flags&SQLITE_CkptFullFSync)!=0);
index 902517c9494e13570ff8bae7827ca0706f5e81d2..633c642ef27be35e4b96a3d81d5a71e660e1256e 100644 (file)
@@ -15,6 +15,7 @@
 
 set testdir [file dirname $argv0]
 source $testdir/tester.tcl
+source $testdir/wal_common.tcl
 
 # If this build of the library does not support auto-vacuum, omit this
 # whole file.
@@ -188,10 +189,12 @@ ifcapable wal {
     execsql { 
       PRAGMA journal_mode = WAL;
       PRAGMA incremental_vacuum(1);
-      PRAGMA wal_checkpoint;
     }
+  } {wal}
+  do_test 4.2.1 {
+    execsql { PRAGMA wal_checkpoint }
     file size test.db-wal
-  } {1640}
+  } [wal_file_size [wal_frames db 2 1] 512]
 
   do_test 4.3 {
     db close
@@ -205,7 +208,7 @@ ifcapable wal {
       if {$newsz>$maxsz} {set maxsz $newsz}
     }
     set maxsz 
-  } {2176}
+  } [wal_file_size [wal_frames db 3 1] 512]
 }
 
 finish_test
index 5c5f8677c7b6ac1575c9e764ab12553f9a13cc41..6cc9575f4d4d099370bdd3d612cb533d6a28dd11 100644 (file)
@@ -2008,18 +2008,23 @@ do_test pager1-22.2.1 {
   tv filter xSync
   tv script xSyncCb
   proc xSyncCb {args} {incr ::synccount}
-  set ::synccount 0
   sqlite3 db test.db
+
+  # Switch the db to WAL mode. And then execute a SELECT to make sure
+  # that the WAL file is open. Note that this may change the synchronous
+  # setting if DEFAULT_WAL_SAFETYLEVEL is defined.
+  execsql { PRAGMA journal_mode = WAL ; SELECT * FROM ko }
+
+  # Set synchronous=OFF. Insert some data and run a checkpoint. Since
+  # sync=off, this should not cause any calls to the xSync() method.
+  set ::synccount 0
   execsql {
-    PRAGMA journal_mode = WAL;
     PRAGMA synchronous = off;
     INSERT INTO ko DEFAULT VALUES;
+    PRAGMA wal_checkpoint;
   }
-  execsql { PRAGMA wal_checkpoint }
   set synccount
 } {0}
-db close
-tv delete
 
 #-------------------------------------------------------------------------
 # Tests for changing journal mode.
index 7fc8cf5fdfd70ed921cddeee212e2ef37c8db9c5..7924a7853f6eddf0b838e6b1a3713701441ef75a 100644 (file)
@@ -13,6 +13,7 @@
 set testdir [file dirname $argv0]
 source $testdir/tester.tcl
 source $testdir/lock_common.tcl
+source $testdir/wal_common.tcl
 
 set testprefix superlock
 
@@ -77,7 +78,9 @@ do_catchsql_test 3.4 { INSERT INTO t1 VALUES(5, 6)} {1 {database is locked}}
 do_catchsql_test 3.5 { PRAGMA wal_checkpoint }      {0 {1 -1 -1}}
 do_test 3.6 { unlock } {}
 
-do_execsql_test 4.1 { PRAGMA wal_checkpoint } {0 2 2}
+do_execsql_test 4.1 { PRAGMA wal_checkpoint } [
+  list 0 [wal_frames db 1 1] [wal_frames db 1 1]
+]
 
 do_test 4.2 { sqlite3demo_superlock unlock test.db } {unlock}
 do_catchsql_test 4.3 { SELECT * FROM t1 }           {1 {database is locked}}
index 07bae1475401c1e96a5556961b4113dadf808aa8..6d918ad37a75f16aa973b8e690ed224b14f70ada 100644 (file)
@@ -548,8 +548,9 @@ do_multiclient_test tn {
     sql2 { BEGIN; SELECT * FROM t1 }
   } {1 2 3 4 5 6 7 8 9 10}
   do_test wal-10.$tn.12 {
-    catchsql { PRAGMA wal_checkpoint } 
-  } {0 {0 13 13}}   ;# Reader no longer block checkpoints
+    # Reader no longer blocks checkpoint:
+    execsql { PRAGMA wal_checkpoint } 
+  } [list 0 [wal_frames db 8 5] [wal_frames db 8 5]] 
   do_test wal-10.$tn.13 {
     execsql { INSERT INTO t1 VALUES(11, 12) }
     sql2 {SELECT * FROM t1}
@@ -558,8 +559,8 @@ do_multiclient_test tn {
   # Writers do not block checkpoints any more either.
   #
   do_test wal-10.$tn.14 {
-    catchsql { PRAGMA wal_checkpoint } 
-  } {0 {0 15 13}}
+    execsql { PRAGMA wal_checkpoint } 
+  } [list 0 [wal_frames db 9 6] [wal_frames db 8 5]]
 
   # The following series of test cases used to verify another blocking
   # case in WAL - a case which no longer blocks.
@@ -568,11 +569,11 @@ do_multiclient_test tn {
     sql2 { COMMIT; BEGIN; SELECT * FROM t1; }
   } {1 2 3 4 5 6 7 8 9 10 11 12}
   do_test wal-10.$tn.16 {
-    catchsql { PRAGMA wal_checkpoint } 
-  } {0 {0 15 15}}
+    execsql { PRAGMA wal_checkpoint } 
+  } [list 0 [wal_frames db 9 6] [wal_frames db 9 6]]
   do_test wal-10.$tn.17 {
     execsql { PRAGMA wal_checkpoint } 
-  } {0 15 15}
+  } [list 0 [wal_frames db 9 6] [wal_frames db 9 6]]
   do_test wal-10.$tn.18 {
     sql3 { BEGIN; SELECT * FROM t1 }
   } {1 2 3 4 5 6 7 8 9 10 11 12}
@@ -595,13 +596,13 @@ do_multiclient_test tn {
   #
   do_test wal-10.$tn.23 {
     execsql { PRAGMA wal_checkpoint }
-  } {0 17 17}
+  } [list 0 [wal_frames db 10 7] [wal_frames db 10 7]]
   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 wal_checkpoint }
-  } {0 17 17}
+  } [list 0 [wal_frames db 10 7] [wal_frames db 10 7]]
   do_test wal-10.$tn.26 {
     catchsql { INSERT INTO t1 VALUES(15, 16) }
   } {0 {}}
@@ -617,12 +618,12 @@ do_multiclient_test tn {
   } {1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18}
   do_test wal-10.$tn.29 {
     execsql { INSERT INTO t1 VALUES(19, 20) }
-    catchsql { PRAGMA wal_checkpoint }
-  } {0 {0 6 0}}
+    execsql { PRAGMA wal_checkpoint }
+  } [list 0 [wal_frames db 4 2] 0]
   do_test wal-10.$tn.30 {
     code3 { sqlite3_finalize $::STMT }
     execsql { PRAGMA wal_checkpoint }
-  } {0 6 0}
+  } [list 0 [wal_frames db 4 2] 0]
 
   # At one point, if a reader failed to upgrade to a writer because it
   # was reading an old snapshot, the write-locks were not being released.
@@ -660,8 +661,8 @@ do_multiclient_test tn {
     }
   } {a b c d}
   do_test wal-10.$tn.36 {
-    catchsql { PRAGMA wal_checkpoint }
-  } {0 {0 16 16}}
+    execsql { PRAGMA wal_checkpoint }
+  } [list 0 [wal_frames db 11 5] [wal_frames db 11 5]]
   do_test wal-10.$tn.36 {
     sql3 { INSERT INTO t1 VALUES('e', 'f') }
     sql2 { SELECT * FROM t1 }
@@ -669,7 +670,7 @@ do_multiclient_test tn {
   do_test wal-10.$tn.37 {
     sql2 COMMIT
     execsql { PRAGMA wal_checkpoint }
-  } {0 18 18}
+  } [list 0 [wal_frames db 13 5] [wal_frames db 13 5]]
 }
 
 #-------------------------------------------------------------------------
@@ -1057,9 +1058,11 @@ foreach {tn ckpt_cmd ckpt_res ckpt_main ckpt_aux} {
       PRAGMA aux.auto_vacuum = 0;
       PRAGMA main.journal_mode = WAL;
       PRAGMA aux.journal_mode = WAL;
+      SELECT count(*) FROM main.sqlite_master, aux.sqlite_master;
       PRAGMA synchronous = NORMAL;
+      PRAGMA aux.synchronous = FULL;
     }
-  } {wal wal}
+  } {wal wal 0}
 
   do_test wal-16.$tn.2 {
     execsql {
@@ -1129,6 +1132,7 @@ foreach {tn sectorsize logsize} "
       PRAGMA auto_vacuum = 0;
       PRAGMA page_size = 512;
       PRAGMA journal_mode = WAL;
+      SELECT * FROM sqlite_master;
       PRAGMA synchronous = FULL;
     }
     execsql {
@@ -1556,7 +1560,7 @@ ifcapable autovacuum {
   } [expr 3 * 1024]
   do_test 24.5 {
     file size test.db-wal
-  } 2128
+  } [wal_file_size [wal_frames db 1 1] 1024]
 }
 
 db close
index ad69b39380b26844151ba4eaf44060c45f34fb7c..0b304a731564b98d72673b713e6057653c612a6f 100644 (file)
@@ -356,16 +356,20 @@ file delete -force test.db test.db-wal test.db-journal
 # Test that a database connection using a VFS that does not support the
 # xShmXXX interfaces cannot open a WAL database.
 #
-do_test wal2-4.1 {
+do_test wal2-4.1.1 {
   sqlite3 db test.db
   execsql {
     PRAGMA auto_vacuum = 0;
     PRAGMA journal_mode = WAL;
     CREATE TABLE data(x);
     INSERT INTO data VALUES('need xShmOpen to see this');
+  }
+} {wal}
+do_test wal2-4.1.2 {
+  execsql {
     PRAGMA wal_checkpoint;
   }
-} {wal 0 5 5}
+} [list 0 [wal_frames db 3 2] [wal_frames db 3 2]]
 do_test wal2-4.2 {
   db close
   testvfs tvfs -noshm 1
@@ -722,18 +726,22 @@ foreach {tn sql res expected_locks} {
 db close
 tvfs delete
 
-do_test wal2-6.5.1 {
+do_test wal2-6.5.1.1 {
   sqlite3 db test.db
   execsql {
     PRAGMA auto_vacuum = 0;
     PRAGMA journal_mode = wal;
     PRAGMA locking_mode = exclusive;
     CREATE TABLE t2(a, b);
+  }
+} {wal exclusive}
+do_test wal2-6.5.1.2 {
+  execsql {
     PRAGMA wal_checkpoint;
     INSERT INTO t2 VALUES('I', 'II');
     PRAGMA journal_mode;
   }
-} {wal exclusive 0 3 3 wal}
+} [list 0 [wal_frames db 2 1] [wal_frames db 2 1] wal]
 do_test wal2-6.5.2 {
   execsql {
     PRAGMA locking_mode = normal;
@@ -744,7 +752,7 @@ do_test wal2-6.5.2 {
 } {normal exclusive I II III IV}
 do_test wal2-6.5.3 {
   execsql { PRAGMA wal_checkpoint }
-} {0 4 4}
+} [list 0 [wal_frames db 2 2] [wal_frames db 2 2]]
 db close
 
 proc lock_control {method filename handle spec} {
@@ -1178,27 +1186,34 @@ if {$::tcl_platform(platform) == "unix"} {
 #-------------------------------------------------------------------------
 # Test that "PRAGMA checkpoint_fullsync" appears to be working.
 #
-foreach {tn sql reslist} {
-  1 { }                                 {8 0 3 0 5 0}
-  2 { PRAGMA checkpoint_fullfsync = 1 } {8 4 3 2 5 2}
-  3 { PRAGMA checkpoint_fullfsync = 0 } {8 0 3 0 5 0}
+foreach {tn sql} {
+  1 { } 
+  2 { PRAGMA checkpoint_fullfsync = 1 }
+  3 { PRAGMA checkpoint_fullfsync = 0 }
 } {
-  if { $::sqlite_options(default_ckptfullfsync) && $tn == 1} {
-    # checkpoint_fullfsync on by default
-    set reslist {8 4 3 2 5 2}
-  }
-
   faultsim_delete_and_reopen
 
   execsql {PRAGMA auto_vacuum = 0}
   execsql $sql
-  do_execsql_test wal2-14.$tn.1 { PRAGMA journal_mode = WAL } {wal}
+  do_execsql_test wal2-14.$tn.1 { 
+    PRAGMA journal_mode = WAL;
+    PRAGMA wal_autocheckpoint = 10;
+  } {wal 10}
+
+  unset -nocomplain res
+  set res(0,1) {5 0 2 0 2 0}      ;# checkpoint_fullfsync=0 sync=NORMAL
+  set res(0,2) {8 0 3 0 5 0}      ;# checkpoint_fullfsync=0 sync=FULL
+  set res(1,1) {5 4 2 2 2 2}      ;# checkpoint_fullfsync=1 sync=NORMAL
+  set res(1,2) {8 4 3 2 5 2}      ;# checkpoint_fullfsync=1 sync=FULL
+
+  set key1 [db one {PRAGMA checkpoint_fullfsync}]
+  set key2 [db one {PRAGMA main.synchronous}]
+  set reslist $res($key1,$key2)
 
   set sqlite_sync_count 0
   set sqlite_fullsync_count 0
 
   do_execsql_test wal2-14.$tn.2 {
-    PRAGMA wal_autocheckpoint = 10;
     CREATE TABLE t1(a, b);                -- 2 wal syncs
     INSERT INTO t1 VALUES(1, 2);          -- 1 wal sync
     PRAGMA wal_checkpoint;                -- 1 wal sync, 1 db sync
@@ -1207,7 +1222,9 @@ foreach {tn sql reslist} {
       INSERT INTO t1 VALUES(5, 6);
     COMMIT;                               -- 1 wal sync
     PRAGMA wal_checkpoint;                -- 1 wal sync, 1 db sync
-  } {10 0 5 5 0 2 2}
+  } [list 0 [wal_frames db 3 2] [wal_frames db 3 2] \
+          0 [wal_frames db 1 1] [wal_frames db 1 1] \
+  ]
 
   do_test wal2-14.$tn.3 {
     cond_incr_sync_count 1
@@ -1241,22 +1258,22 @@ catch { db close }
 # PRAGMA fullfsync
 # PRAGMA synchronous
 #
-foreach {tn settings commit_sync ckpt_sync} {
-  1  {0 0 off}     {0 0}  {0 0}
-  2  {0 0 normal}  {0 0}  {2 0}
-  3  {0 0 full}    {1 0}  {2 0}
-
-  4  {0 1 off}     {0 0}  {0 0}
-  5  {0 1 normal}  {0 0}  {0 2}
-  6  {0 1 full}    {0 1}  {0 2}
-
-  7  {1 0 off}     {0 0}  {0 0}
-  8  {1 0 normal}  {0 0}  {0 2}
-  9  {1 0 full}    {1 0}  {0 2}
-
-  10 {1 1 off}     {0 0}  {0 0}
-  11 {1 1 normal}  {0 0}  {0 2}
-  12 {1 1 full}    {0 1}  {0 2}
+foreach {tn settings} {
+  1  {0 0 off}    
+  2  {0 0 normal}
+  3  {0 0 full} 
+
+  4  {0 1 off} 
+  5  {0 1 normal} 
+  6  {0 1 full}  
+
+  7  {1 0 off}  
+  8  {1 0 normal}
+  9  {1 0 full} 
+
+  10 {1 1 off} 
+  11 {1 1 normal}
+  12 {1 1 full} 
 } {
   forcedelete test.db
 
@@ -1274,7 +1291,29 @@ foreach {tn settings commit_sync ckpt_sync} {
     PRAGMA checkpoint_fullfsync = [lindex $settings 0];
     PRAGMA fullfsync = [lindex $settings 1];
     PRAGMA synchronous = [lindex $settings 2];
-  " {wal}
+    SELECT count(*) FROM sqlite_master;
+  " {wal 1}
+
+  unset -nocomplain res
+  set res(0,0,0) {{0 0}  {0 0}}
+  set res(0,0,1) {{0 0}  {2 0}}
+  set res(0,0,2) {{1 0}  {2 0}}
+  set res(0,1,0) {{0 0}  {0 0}}
+  set res(0,1,1) {{0 0}  {0 2}}
+  set res(0,1,2) {{0 1}  {0 2}}
+  set res(1,0,0) {{0 0}  {0 0}}
+  set res(1,0,1) {{0 0}  {0 2}}
+  set res(1,0,2) {{1 0}  {0 2}}
+  set res(1,1,0) {{0 0}  {0 0}}
+  set res(1,1,1) {{0 0}  {0 2}}
+  set res(1,1,2) {{0 1}  {0 2}}
+
+  set key1 [db one {PRAGMA checkpoint_fullfsync}]
+  set key2 [db one {PRAGMA fullfsync}]
+  set key3 [db one {PRAGMA synchronous}]
+
+  set commit_sync [lindex $res($key1,$key2,$key3) 0]
+  set ckpt_sync   [lindex $res($key1,$key2,$key3) 1]
 
   do_test 15.$tn.2 {
     set sync(normal) 0
index 13303e2c4dcd11a2c6536546228d721595ae3aba..57ac1654492c64e82e788cb7ea9b47a9a348a67d 100644 (file)
@@ -229,8 +229,9 @@ foreach {tn syncmode synccount} {
     T script sync_counter
     sqlite3 db test.db -vfs T
   
-    execsql "PRAGMA synchronous = $syncmode"
     execsql { PRAGMA journal_mode = WAL }
+    execsql { SELECT * FROM sqlite_master }
+    execsql "PRAGMA synchronous = $syncmode"
 
     set ::syncs [list]
     T filter xSync
@@ -442,7 +443,7 @@ do_test wal3-6.1.2 {
 } {o t t f}
 do_test wal3-6.1.3 {
   execsql { PRAGMA wal_checkpoint } db2
-} {0 7 7}
+} [list 0 [wal_frames db 4 3] [wal_frames db 4 3]]
 
 # At this point the log file has been fully checkpointed. However, 
 # connection [db3] holds a lock that prevents the log from being wrapped.
@@ -531,7 +532,7 @@ proc lock_callback {method file handle spec} {
 }
 do_test wal3-6.2.2 {
   execsql { PRAGMA wal_checkpoint }
-} {0 7 7}
+} [list 0 [wal_frames db 4 3] [wal_frames db 4 3]]
 do_test wal3-6.2.3 {
   set ::R
 } {h h l b}
@@ -628,7 +629,7 @@ T delete
 
 #-------------------------------------------------------------------------
 # 
-do_test wal3-8.1 {
+do_test wal3-8.1.1 {
   file delete -force test.db test.db-journal test.db wal .test.db-conch
   sqlite3 db test.db
   sqlite3 db2 test.db
@@ -639,9 +640,12 @@ do_test wal3-8.1 {
     INSERT INTO b VALUES('Tehran');
     INSERT INTO b VALUES('Qom');
     INSERT INTO b VALUES('Markazi');
-    PRAGMA wal_checkpoint;
   }
-} {wal 0 9 9}
+} {wal}
+
+do_test wal3.8.1.2 {
+  execsql { PRAGMA wal_checkpoint; }
+} [list 0 [wal_frames db 5 4] [wal_frames db 5 4]]
 do_test wal3-8.2 {
   execsql { SELECT * FROM b }
 } {Tehran Qom Markazi}
index 0c700dfc50595e458a584c0a81464e5be8758abc..5ef6345cf1035a49cad11a35fd906b19907a4670 100644 (file)
@@ -197,9 +197,15 @@ foreach {testprefix do_wal_checkpoint} {
         INSERT INTO t2 VALUES(1, 2);
       }
     } {}
-    do_test 2.2.$tn.2 { file_page_counts } {1 5 1 5}
-    do_test 2.1.$tn.3 { code1 { do_wal_checkpoint db } } {0 5 5}
-    do_test 2.1.$tn.4 { file_page_counts } {2 5 2 5}
+    do_test 2.2.$tn.2 { file_page_counts } [
+      list 1 [wal_frames db 3 2] 1 [wal_frames db 3 2]
+    ]
+    do_test 2.1.$tn.3 { code1 { do_wal_checkpoint db } } [
+      list 0 [wal_frames db 3 2] [wal_frames db 3 2]
+    ]
+    do_test 2.1.$tn.4 { file_page_counts } [
+      list 2 [wal_frames db 3 2] 2 [wal_frames db 3 2]
+    ]
   }
 
   do_multiclient_test tn {
@@ -213,10 +219,16 @@ foreach {testprefix do_wal_checkpoint} {
         INSERT INTO t2 VALUES(3, 4);
       }
     } {}
-    do_test 2.2.$tn.2 { file_page_counts } {1 5 1 7}
+    do_test 2.2.$tn.2 { file_page_counts } [
+      list 1 [wal_frames db 3 2] 1 [wal_frames db 4 3]
+    ]
     do_test 2.2.$tn.3 { sql2 { BEGIN; SELECT * FROM t1 } } {1 2}
-    do_test 2.2.$tn.4 { code1 { do_wal_checkpoint db -mode restart } } {1 5 5}
-    do_test 2.2.$tn.5 { file_page_counts } {2 5 2 7}
+    do_test 2.2.$tn.4 { code1 { do_wal_checkpoint db -mode restart } } [
+      list 1 [wal_frames db 3 2] [wal_frames db 3 2]
+    ]
+    do_test 2.2.$tn.5 { file_page_counts } [
+      list 2 [wal_frames db 3 2] 2 [wal_frames db 4 3]
+    ]
   }
 
   do_multiclient_test tn {
@@ -229,19 +241,27 @@ foreach {testprefix do_wal_checkpoint} {
         INSERT INTO t2 VALUES(1, 2);
       }
     } {}
-    do_test 2.3.$tn.2 { file_page_counts } {1 5 1 5}
+    do_test 2.3.$tn.2 { file_page_counts } [
+      list 1 [wal_frames db 3 2] 1 [wal_frames db 3 2]
+    ]
     do_test 2.3.$tn.3 { sql2 { BEGIN; SELECT * FROM t1 } } {1 2}
     do_test 2.3.$tn.4 { sql1 { INSERT INTO t1 VALUES(3, 4) } } {}
     do_test 2.3.$tn.5 { sql1 { INSERT INTO t2 VALUES(3, 4) } } {}
-    do_test 2.3.$tn.6 { file_page_counts } {1 7 1 7}
-    do_test 2.3.$tn.7 { code1 { do_wal_checkpoint db -mode full } } {1 7 5}
+    do_test 2.3.$tn.6 { file_page_counts } [
+      list 1 [wal_frames db 4 3] 1 [wal_frames db 4 3]
+    ]
+    do_test 2.3.$tn.7 { code1 { do_wal_checkpoint db -mode full } } [
+      list 1 [wal_frames db 4 3] [wal_frames db 3 2]
+    ]
     if {$tcl_platform(platform) == "windows"} {
         # on unix, the size_hint is a no-op if no chunk size is set.
         # the windows implementation does not have a similar check,
         # and because of this, the db file size has an extra page.
         do_test 2.3.$tn.8 { file_page_counts } {2 7 2 7}
     } {
-        do_test 2.3.$tn.8 { file_page_counts } {1 7 2 7}
+        do_test 2.3.$tn.8 { file_page_counts } [
+          list 1 [wal_frames db 4 3] 2 [wal_frames db 4 3]
+        ]
     }
   }
 
@@ -301,6 +321,13 @@ foreach {testprefix do_wal_checkpoint} {
         sql3 { BEGIN; SELECT * FROM t1 }
       } {1 2}
 
+      # The value in ckpt_expected assumes that synchronous=FULL. If
+      # synchronous=NORMAL, decrease the WAL size by 2 frames.
+      if {$tn==1 && [db one {PRAGMA main.synchronous}] == 1} {
+        lset ckpt_expected 1 [expr [lindex $ckpt_expected 1] - 2]
+        lset ckpt_expected 2 [expr [lindex $ckpt_expected 2] - 2]
+      }
+  
       do_test 2.4.$tn1.$tn.2 {
         code1 { db busy busyhandler }
         code1 { do_wal_checkpoint db -mode [string tolower $checkpoint] }
index 917ad598f6307567d79c63f58b431e817acb8f61..c2eb500c9ccf4799a615f4aea6f74a4b97ee8d92 100644 (file)
@@ -33,6 +33,20 @@ proc wal_cksum_intlist {ckv1 ckv2 intlist} {
   }
 }
 
+# If the synchronous mode for the main database of db handle $db
+# is either OFF or NORMAL, return $nRight. Otherwise, if it is
+# FULL, return $nWrite+$nTrans.
+#
+proc wal_frames {db nWrite nTrans} {
+  set nRet $nWrite
+  switch -- [$db one {PRAGMA main.synchronous}] {
+    0 { }
+    1 { }
+    default { incr nRet $nTrans }
+  }
+  set nRet
+}
+
 
 # This proc calculates checksums in the same way as those used by SQLite 
 # in WAL files. If the $endian argument is "big", then checksums are
index 0976e935bc3d2b15a93f2e9465832488c99165a5..2e6a6ae4a7048197cce0368bbb5cd19401cc2b5c 100644 (file)
@@ -59,7 +59,15 @@ do_test walmode-1.2 {
   file size test.db
 } {1024}
 
-set expected_sync_count 3
+# Determine how many sync() calls to expect from the "journal_mode=WAL" 
+# command above. Note that if DEFAULT_WAL_SAFETYLEVEL is defined, the
+# safety-level may have been modified while compiling the "journal_mode=WAL"
+# statement.
+switch -- [db eval {PRAGMA main.synchronous}] {
+  0        { set expected_sync_count 0 }
+  1        { set expected_sync_count 2 }
+  default  { set expected_sync_count 3 }
+}
 if {$::tcl_platform(platform)!="windows"} {
   ifcapable dirsync {
     incr expected_sync_count