3 # The author disclaims copyright to this source code. In place of
4 # a legal notice, here is a blessing:
6 # May you do good and not evil.
7 # May you find forgiveness for yourself and forgive others.
8 # May you share freely, never taking more than you give.
10 #***********************************************************************
11 # This file implements regression tests for SQLite library. The
12 # focus of this file is testing the operation of the library in
13 # "PRAGMA journal_mode=WAL" mode.
16 set testdir [file dirname $argv0]
17 source $testdir/tester.tcl
18 source $testdir/wal_common.tcl
19 source $testdir/malloc_common.tcl
23 ifcapable !wal {finish_test ; return }
28 # walback-1.*: Simple tests.
30 # walback-2.*: Test backups when the source db is modified mid-backup.
32 # walback-3.*: Backup of WAL sources into rollback destinations, and
36 # Make sure a simple backup from a WAL database works.
40 PRAGMA synchronous = NORMAL;
41 PRAGMA page_size = 1024;
42 PRAGMA auto_vacuum = 0;
43 PRAGMA journal_mode = wal;
45 CREATE TABLE t1(a PRIMARY KEY, b);
46 INSERT INTO t1 VALUES('I', 'one');
51 file delete -force bak.db bak.db-journal bak.db-wal
59 PRAGMA main.journal_mode;
63 execsql { PRAGMA integrity_check } db2
67 # Try a VACUUM on a WAL database.
72 PRAGMA main.journal_mode;
76 list [file size test.db] [file size test.db-wal]
77 } [list 1024 [wal_file_size 6 1024]]
79 execsql { PRAGMA wal_checkpoint }
80 list [file size test.db] [file size test.db-wal]
81 } [list [expr 3*1024] [wal_file_size 6 1024]]
84 CREATE TABLE t2(a, b);
85 INSERT INTO t2 SELECT * FROM t1;
88 list [file size test.db] [file size test.db-wal]
89 } [list [expr 3*1024] [wal_file_size 6 1024]]
92 list [file size test.db] [file size test.db-wal]
93 } [list [expr 3*1024] [wal_file_size 8 1024]]
95 execsql { PRAGMA wal_checkpoint }
96 list [file size test.db] [file size test.db-wal]
97 } [list [expr 2*1024] [wal_file_size 8 1024]]
99 #-------------------------------------------------------------------------
100 # Backups when the source db is modified mid-backup.
104 PRAGMA integrity_check;
105 SELECT md5sum(a, b) FROM t1;
112 execsql { PRAGMA journal_mode = WAL }
114 CREATE TABLE t1(a PRIMARY KEY, b);
116 INSERT INTO t1 VALUES(randomblob(500), randomblob(500));
117 INSERT INTO t1 SELECT randomblob(500), randomblob(500) FROM t1; /* 2 */
118 INSERT INTO t1 SELECT randomblob(500), randomblob(500) FROM t1; /* 4 */
119 INSERT INTO t1 SELECT randomblob(500), randomblob(500) FROM t1; /* 8 */
120 INSERT INTO t1 SELECT randomblob(500), randomblob(500) FROM t1; /* 16 */
121 INSERT INTO t1 SELECT randomblob(500), randomblob(500) FROM t1; /* 32 */
122 INSERT INTO t1 SELECT randomblob(500), randomblob(500) FROM t1; /* 64 */
129 string compare [sig db] [sig db2]
133 sqlite3_backup B db2 main db main
135 execsql { UPDATE t1 SET b = randomblob(500) }
136 list [B step 1000] [B finish]
137 } {SQLITE_DONE SQLITE_OK}
139 string compare [sig db] [sig db2]
145 execsql { PRAGMA cache_size = 10 }
146 sqlite3_backup B db2 main db main
150 UPDATE t1 SET b = randomblob(500);
152 expr [file size test.db-wal] > 10*1024
159 list [B step 1000] [B finish]
160 } {SQLITE_DONE SQLITE_OK}
162 string compare [sig db] [sig db2]
168 execsql { PRAGMA cache_size = 10 }
169 sqlite3_backup B db2 main db main
173 UPDATE t1 SET b = randomblob(500);
175 expr [file size test.db-wal] > 10*1024
177 do_test walbak-2.10 {
180 do_test walbak-2.11 {
183 list [B step 1000] [B finish]
184 } {SQLITE_DONE SQLITE_OK}
185 do_test walbak-2.12 {
186 string compare [sig db] [sig db2]
191 #-------------------------------------------------------------------------
192 # Run some backup operations to copy back and forth between WAL and:
194 # walbak-3.1.*: an in-memory database
196 # walbak-3.2.*: a temporary database
198 # walbak-3.3.*: a database in rollback mode.
200 # walbak-3.4.*: a database in rollback mode that (initially) uses a
201 # different page-size.
203 # Check that this does not confuse any connected clients.
209 db eval { PRAGMA page_size = 1024 ; PRAGMA journal_mode = WAL }
210 db2 eval { PRAGMA page_size = 1024 }
216 db eval { PRAGMA page_size = 1024 ; PRAGMA journal_mode = WAL }
217 db2 eval { PRAGMA page_size = 1024 }
223 db eval { PRAGMA page_size = 1024 ; PRAGMA journal_mode = WAL }
224 db2 eval { PRAGMA page_size = 1024 ; PRAGMA journal_mode = PERSIST }
230 db eval { PRAGMA page_size = 1024 ; PRAGMA journal_mode = WAL }
232 PRAGMA page_size = 2048;
233 PRAGMA journal_mode = PERSIST;
239 foreach f [glob -nocomplain test.db*] { file delete -force $f }
243 do_test walbak-3.$tn.1 {
245 CREATE TABLE t1(a, b);
246 INSERT INTO t1 VALUES(1, 2);
247 INSERT INTO t1 VALUES(3, 4);
252 do_test walbak-3.$tn.2 {
253 sqlite3_backup B db2 main db main
256 execsql { SELECT * FROM t1 } db2
259 do_test walbak-3.$tn.3 {
261 INSERT INTO t1 VALUES(5, 6);
262 INSERT INTO t1 VALUES(7, 8);
267 do_test walbak-3.$tn.4 {
268 sqlite3_backup B db main db2 main
271 execsql { SELECT * FROM t1 }