Index: third_party/sqlite/src/test/wal.test |
diff --git a/third_party/sqlite/src/test/wal.test b/third_party/sqlite/src/test/wal.test |
index 1aa70e0525154568a542ab46bf655b043e0710b8..675be73791a7946c97f32de73dd154c8fb32ee2e 100644 |
--- a/third_party/sqlite/src/test/wal.test |
+++ b/third_party/sqlite/src/test/wal.test |
@@ -25,7 +25,7 @@ ifcapable !wal {finish_test ; return } |
proc reopen_db {} { |
catch { db close } |
- file delete -force test.db test.db-wal test.db-wal-summary |
+ forcedelete test.db test.db-wal test.db-wal-summary |
sqlite3_wal db test.db |
} |
@@ -211,8 +211,8 @@ do_test wal-4.4.5 { |
execsql { SELECT count(*) FROM t2 } |
} {1} |
do_test wal-4.4.6 { |
- file copy -force test.db test2.db |
- file copy -force test.db-wal test2.db-wal |
+ forcecopy test.db test2.db |
+ forcecopy test.db-wal test2.db-wal |
sqlite3 db2 test2.db |
execsql { SELECT count(*) FROM t2 ; SELECT count(*) FROM t1 } db2 |
} {1 2} |
@@ -269,8 +269,8 @@ do_test wal-4.5.5 { |
execsql { SELECT count(*) FROM t2 ; SELECT count(*) FROM t1 } |
} {1 2} |
do_test wal-4.5.6 { |
- file copy -force test.db test2.db |
- file copy -force test.db-wal test2.db-wal |
+ forcecopy test.db test2.db |
+ forcecopy test.db-wal test2.db-wal |
sqlite3 db2 test2.db |
execsql { SELECT count(*) FROM t2 ; SELECT count(*) FROM t1 } db2 |
} {1 2} |
@@ -322,7 +322,7 @@ do_test wal-5.4 { |
INSERT INTO t3 VALUES('abc'); |
} |
catchsql { INSERT INTO t3 VALUES('abc') } |
-} {1 {column x is not unique}} |
+} {1 {UNIQUE constraint failed: t3.x}} |
do_test wal-5.5 { |
execsql { |
COMMIT; |
@@ -334,7 +334,7 @@ db close |
foreach sector {512 4096} { |
sqlite3_simulate_device -sectorsize $sector |
foreach pgsz {512 1024 2048 4096} { |
- file delete -force test.db test.db-wal |
+ forcedelete test.db test.db-wal |
do_test wal-6.$sector.$pgsz.1 { |
sqlite3 db test.db -vfs devsym |
execsql " |
@@ -357,7 +357,7 @@ foreach sector {512 4096} { |
} |
do_test wal-7.1 { |
- file delete -force test.db test.db-wal |
+ forcedelete test.db test.db-wal |
sqlite3_wal db test.db |
execsql { |
PRAGMA page_size = 1024; |
@@ -377,7 +377,7 @@ do_test wal-7.2 { |
do_test wal-8.1 { |
reopen_db |
catch { db close } |
- file delete -force test.db test.db-wal |
+ forcedelete test.db test.db-wal |
sqlite3 db test.db |
db function blob blob |
@@ -416,6 +416,7 @@ do_test wal-8.3 { |
do_test wal-9.1 { |
reopen_db |
execsql { |
+ PRAGMA cache_size=2000; |
CREATE TABLE t1(x PRIMARY KEY); |
INSERT INTO t1 VALUES(blob(900)); |
INSERT INTO t1 VALUES(blob(900)); |
@@ -435,9 +436,9 @@ do_test wal-9.2 { |
} {ok} |
do_test wal-9.3 { |
- file delete -force test2.db test2.db-wal |
- file copy test.db test2.db |
- file copy test.db-wal test2.db-wal |
+ forcedelete test2.db test2.db-wal |
+ copy_file test.db test2.db |
+ copy_file test.db-wal test2.db-wal |
sqlite3_wal db3 test2.db |
execsql {PRAGMA integrity_check } db3 |
} {ok} |
@@ -545,7 +546,7 @@ do_multiclient_test tn { |
} {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 |
+ } {0 {0 7 7}} ;# Reader no longer block checkpoints |
do_test wal-10.$tn.13 { |
execsql { INSERT INTO t1 VALUES(11, 12) } |
sql2 {SELECT * FROM t1} |
@@ -555,7 +556,7 @@ do_multiclient_test tn { |
# |
do_test wal-10.$tn.14 { |
catchsql { PRAGMA wal_checkpoint } |
- } {0 {0 15 13}} |
+ } {0 {0 8 7}} |
# The following series of test cases used to verify another blocking |
# case in WAL - a case which no longer blocks. |
@@ -565,10 +566,10 @@ do_multiclient_test tn { |
} {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}} |
+ } {0 {0 8 8}} |
do_test wal-10.$tn.17 { |
execsql { PRAGMA wal_checkpoint } |
- } {0 15 15} |
+ } {0 8 8} |
do_test wal-10.$tn.18 { |
sql3 { BEGIN; SELECT * FROM t1 } |
} {1 2 3 4 5 6 7 8 9 10 11 12} |
@@ -591,13 +592,13 @@ do_multiclient_test tn { |
# |
do_test wal-10.$tn.23 { |
execsql { PRAGMA wal_checkpoint } |
- } {0 17 17} |
+ } {0 9 9} |
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} |
+ } {0 9 9} |
do_test wal-10.$tn.26 { |
catchsql { INSERT INTO t1 VALUES(15, 16) } |
} {0 {}} |
@@ -614,11 +615,11 @@ do_multiclient_test tn { |
do_test wal-10.$tn.29 { |
execsql { INSERT INTO t1 VALUES(19, 20) } |
catchsql { PRAGMA wal_checkpoint } |
- } {0 {0 6 0}} |
+ } {0 {0 3 0}} |
do_test wal-10.$tn.30 { |
code3 { sqlite3_finalize $::STMT } |
execsql { PRAGMA wal_checkpoint } |
- } {0 6 0} |
+ } {0 3 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. |
@@ -657,7 +658,7 @@ do_multiclient_test tn { |
} {a b c d} |
do_test wal-10.$tn.36 { |
catchsql { PRAGMA wal_checkpoint } |
- } {0 {0 16 16}} |
+ } {0 {0 8 8}} |
do_test wal-10.$tn.36 { |
sql3 { INSERT INTO t1 VALUES('e', 'f') } |
sql2 { SELECT * FROM t1 } |
@@ -665,7 +666,7 @@ do_multiclient_test tn { |
do_test wal-10.$tn.37 { |
sql2 COMMIT |
execsql { PRAGMA wal_checkpoint } |
- } {0 18 18} |
+ } {0 9 9} |
} |
#------------------------------------------------------------------------- |
@@ -726,6 +727,9 @@ do_test wal-11.9 { |
list [expr [file size test.db]/1024] [log_deleted test.db-wal] |
} {37 1} |
sqlite3_wal db test.db |
+set nWal 39 |
+if {[permutation]!="mmap"} {set nWal 37} |
+ifcapable !mmap {set nWal 37} |
do_test wal-11.10 { |
execsql { |
PRAGMA cache_size = 10; |
@@ -734,7 +738,7 @@ do_test wal-11.10 { |
SELECT count(*) FROM t1; |
} |
list [expr [file size test.db]/1024] [file size test.db-wal] |
-} [list 37 [wal_file_size 37 1024]] |
+} [list 37 [wal_file_size $nWal 1024]] |
do_test wal-11.11 { |
execsql { |
SELECT count(*) FROM t1; |
@@ -744,7 +748,7 @@ do_test wal-11.11 { |
} {32 16} |
do_test wal-11.12 { |
list [expr [file size test.db]/1024] [file size test.db-wal] |
-} [list 37 [wal_file_size 37 1024]] |
+} [list 37 [wal_file_size $nWal 1024]] |
do_test wal-11.13 { |
execsql { |
INSERT INTO t1 VALUES( blob(900) ); |
@@ -754,7 +758,7 @@ do_test wal-11.13 { |
} {17 ok} |
do_test wal-11.14 { |
list [expr [file size test.db]/1024] [file size test.db-wal] |
-} [list 37 [wal_file_size 37 1024]] |
+} [list 37 [wal_file_size $nWal 1024]] |
#------------------------------------------------------------------------- |
@@ -786,8 +790,8 @@ do_test wal-12.3 { |
list [expr [file size test.db]/1024] [expr [file size test.db-wal]/1044] |
} {3 2} |
do_test wal-12.4 { |
- file copy -force test.db test2.db |
- file copy -force test.db-wal test2.db-wal |
+ forcecopy test.db test2.db |
+ forcecopy test.db-wal test2.db-wal |
sqlite3_wal db2 test2.db |
execsql { SELECT * FROM t2 } db2 |
} {B 1} |
@@ -804,8 +808,8 @@ do_test wal-12.5 { |
execsql { SELECT * FROM t2 } |
} {B 2} |
do_test wal-12.6 { |
- file copy -force test.db test2.db |
- file copy -force test.db-wal test2.db-wal |
+ forcecopy test.db test2.db |
+ forcecopy test.db-wal test2.db-wal |
sqlite3_wal db2 test2.db |
execsql { SELECT * FROM t2 } db2 |
} {B 2} |
@@ -848,7 +852,6 @@ do_test wal-13.1.2 { |
sqlite3 db test.db |
execsql { SELECT * FROM t2 } |
} {B 2} |
-breakpoint |
do_test wal-13.1.3 { |
db close |
file exists test.db-wal |
@@ -909,7 +912,7 @@ do_multiclient_test tn { |
catch { db close } |
catch { db2 close } |
catch { db3 close } |
-file delete -force test.db test.db-wal |
+forcedelete test.db test.db-wal |
sqlite3 db test.db |
sqlite3 db2 test.db |
do_test wal-14 { |
@@ -947,7 +950,7 @@ catch { db2 close } |
# The following block of tests - wal-15.* - focus on testing the |
# implementation of the sqlite3_wal_checkpoint() interface. |
# |
-file delete -force test.db test.db-wal |
+forcedelete test.db test.db-wal |
sqlite3 db test.db |
do_test wal-15.1 { |
execsql { |
@@ -1039,12 +1042,12 @@ foreach {tn ckpt_cmd ckpt_res ckpt_main ckpt_aux} { |
5 {sqlite3_wal_checkpoint db aux} SQLITE_OK 0 1 |
6 {sqlite3_wal_checkpoint db temp} SQLITE_OK 0 0 |
7 {db eval "PRAGMA main.wal_checkpoint"} {0 10 10} 1 0 |
- 8 {db eval "PRAGMA aux.wal_checkpoint"} {0 16 16} 0 1 |
+ 8 {db eval "PRAGMA aux.wal_checkpoint"} {0 13 13} 0 1 |
9 {db eval "PRAGMA temp.wal_checkpoint"} {0 -1 -1} 0 0 |
} { |
do_test wal-16.$tn.1 { |
- file delete -force test2.db test2.db-wal test2.db-journal |
- file delete -force test.db test.db-wal test.db-journal |
+ forcedelete test2.db test2.db-wal test2.db-journal |
+ forcedelete test.db test.db-wal test.db-journal |
sqlite3 db test.db |
execsql { |
@@ -1053,7 +1056,8 @@ 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; |
- PRAGMA synchronous = NORMAL; |
+ PRAGMA main.synchronous = NORMAL; |
+ PRAGMA aux.synchronous = NORMAL; |
} |
} {wal wal} |
@@ -1071,7 +1075,7 @@ foreach {tn ckpt_cmd ckpt_res ckpt_main ckpt_aux} { |
} [list [expr 1*1024] [wal_file_size 10 1024]] |
do_test wal-16.$tn.3 { |
list [file size test2.db] [file size test2.db-wal] |
- } [list [expr 1*1024] [wal_file_size 16 1024]] |
+ } [list [expr 1*1024] [wal_file_size 13 1024]] |
do_test wal-16.$tn.4 [list eval $ckpt_cmd] $ckpt_res |
@@ -1081,7 +1085,7 @@ foreach {tn ckpt_cmd ckpt_res ckpt_main ckpt_aux} { |
do_test wal-16.$tn.6 { |
list [file size test2.db] [file size test2.db-wal] |
- } [list [expr ($ckpt_aux ? 7 : 1)*1024] [wal_file_size 16 1024]] |
+ } [list [expr ($ckpt_aux ? 7 : 1)*1024] [wal_file_size 13 1024]] |
catch { db close } |
} |
@@ -1116,7 +1120,7 @@ foreach {tn sectorsize logsize} " |
6 4096 [wal_file_size 176 512] |
7 8192 [wal_file_size 184 512] |
" { |
- file delete -force test.db test.db-wal test.db-journal |
+ forcedelete test.db test.db-wal test.db-journal |
sqlite3_simulate_device -sectorsize $sectorsize |
sqlite3 db test.db -vfs devsym |
@@ -1124,6 +1128,7 @@ foreach {tn sectorsize logsize} " |
execsql { |
PRAGMA auto_vacuum = 0; |
PRAGMA page_size = 512; |
+ PRAGMA cache_size = -2000; |
PRAGMA journal_mode = WAL; |
PRAGMA synchronous = FULL; |
} |
@@ -1160,7 +1165,7 @@ sqlite3_test_control_pending_byte $old_pending_byte |
# wal-18.2.* When the page-size field that occurs at the start of a log |
# file is a power of 2 greater than 16384 or smaller than 512. |
# |
-file delete -force test.db test.db-wal test.db-journal |
+forcedelete test.db test.db-wal test.db-journal |
do_test wal-18.0 { |
sqlite3 db test.db |
execsql { |
@@ -1178,8 +1183,8 @@ do_test wal-18.0 { |
INSERT INTO t1 VALUES(5, 6); -- frames 5 and 6 |
} |
- file copy -force test.db testX.db |
- file copy -force test.db-wal testX.db-wal |
+ forcecopy test.db testX.db |
+ forcecopy test.db-wal testX.db-wal |
db close |
list [file size testX.db] [file size testX.db-wal] |
} [list [expr 3*1024] [wal_file_size 6 1024]] |
@@ -1195,8 +1200,8 @@ foreach {nFrame result} { |
6 {0 0 1 2 3 4 5 6} |
} { |
do_test wal-18.1.$nFrame { |
- file copy -force testX.db test.db |
- file copy -force testX.db-wal test.db-wal |
+ forcecopy testX.db test.db |
+ forcecopy testX.db-wal test.db-wal |
hexio_write test.db-wal [expr 24 + $nFrame*(24+1024) + 20] 00000000 |
@@ -1220,10 +1225,11 @@ proc logcksum {ckv1 ckv2 blob} { |
upvar $ckv1 c1 |
upvar $ckv2 c2 |
- set scanpattern I* |
- if {$::tcl_platform(byteOrder) eq "littleEndian"} { |
- set scanpattern i* |
- } |
+ # Since the magic number at the start of the -wal file header is |
+ # 931071618 that indicates that the content should always be read as |
+ # little-endian. |
+ # |
+ set scanpattern i* |
binary scan $blob $scanpattern values |
foreach {v1 v2} $values { |
@@ -1232,7 +1238,7 @@ proc logcksum {ckv1 ckv2 blob} { |
} |
} |
-file copy -force test.db testX.db |
+forcecopy test.db testX.db |
foreach {tn pgsz works} { |
1 128 0 |
2 256 0 |
@@ -1253,8 +1259,8 @@ foreach {tn pgsz works} { |
} |
for {set pg 1} {$pg <= 3} {incr pg} { |
- file copy -force testX.db test.db |
- file delete -force test.db-wal |
+ forcecopy testX.db test.db |
+ forcedelete test.db-wal |
# Check that the database now exists and consists of three pages. And |
# that there is no associated wal file. |
@@ -1321,7 +1327,7 @@ foreach {tn pgsz works} { |
# snapshot. |
# |
do_test wal-19.1 { |
- file delete -force test.db test.db-wal test.db-journal |
+ forcedelete test.db test.db-wal test.db-journal |
sqlite3 db test.db |
sqlite3 db2 test.db |
execsql { |
@@ -1370,7 +1376,7 @@ do_test wal-19.4 { |
# |
do_test wal-20.1 { |
catch {db close} |
- file delete -force test.db test.db-wal test.db-journal |
+ forcedelete test.db test.db-wal test.db-journal |
sqlite3 db test.db |
execsql { |
PRAGMA journal_mode = WAL; |
@@ -1474,9 +1480,13 @@ foreach pgsz {512 1024 2048 4096 8192 16384 32768 65536} { |
# Test that when 1 or more pages are recovered from a WAL file, |
# sqlite3_log() is invoked to report this to the user. |
# |
-set walfile [file nativename [file join [pwd] test.db-wal]] |
+ifcapable curdir { |
+ set walfile [file nativename [file join [get_pwd] test.db-wal]] |
+} else { |
+ set walfile test.db-wal |
+} |
catch {db close} |
-file delete -force test.db |
+forcedelete test.db |
do_test wal-23.1 { |
faultsim_delete_and_reopen |
execsql { |
@@ -1501,10 +1511,10 @@ do_test wal-23.3 { |
faultsim_restore_and_reopen |
execsql { SELECT * FROM t1 } |
} {1 2 3 4} |
-set nPage [expr 2+$AUTOVACUUM] |
do_test wal-23.4 { |
set ::log |
-} [list SQLITE_OK "Recovered $nPage frames from WAL file $walfile"] |
+} [list SQLITE_NOTICE_RECOVER_WAL \ |
+ "recovered 2 frames from WAL file $walfile"] |
ifcapable autovacuum { |
@@ -1550,9 +1560,13 @@ ifcapable autovacuum { |
} |
file size test.db |
} [expr 3 * 1024] |
+ |
+ # WAL file now contains a single frame - the new root page for table t1. |
+ # It would be two frames (the new root page and a padding frame) if the |
+ # ZERO_DAMAGE flag were not set. |
do_test 24.5 { |
file size test.db-wal |
- } 2128 |
+ } [wal_file_size 1 1024] |
} |
db close |
@@ -1560,4 +1574,17 @@ sqlite3_shutdown |
test_sqlite3_log |
sqlite3_initialize |
+# Make sure PRAGMA journal_mode=WAL works with ATTACHED databases in |
+# all journal modes. |
+# |
+foreach mode {OFF MEMORY PERSIST DELETE TRUNCATE WAL} { |
+ delete_file test.db test2.db |
+ sqlite3 db test.db |
+ do_test wal-25.$mode { |
+ db eval "PRAGMA journal_mode=$mode" |
+ db eval {ATTACH 'test2.db' AS t2; PRAGMA journal_mode=WAL;} |
+ } {wal} |
+ db close |
+} |
+ |
finish_test |