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.
15 # More specifically, this file contains regression tests for the
16 # sqlite3_wal_hook() mechanism, including the sqlite3_wal_autocheckpoint()
17 # and "PRAGMA wal_autocheckpoint" convenience interfaces.
20 set testdir [file dirname $argv0]
21 source $testdir/tester.tcl
22 source $testdir/wal_common.tcl
24 ifcapable !wal {finish_test ; return }
27 proc wal_hook {zDb nEntry} {
28 lappend ::wal_hook $zDb $nEntry
35 PRAGMA page_size = 1024;
36 PRAGMA auto_vacuum = 0;
37 PRAGMA journal_mode = wal;
38 PRAGMA synchronous = normal;
39 CREATE TABLE t1(i PRIMARY KEY, j);
46 execsql { INSERT INTO t1 VALUES(1, 'one') }
50 proc wal_hook {args} { db eval {PRAGMA wal_checkpoint}; return 0 }
51 execsql { INSERT INTO t1 VALUES(2, 'two') }
55 proc wal_hook {zDb nEntry} {
56 execsql { PRAGMA wal_checkpoint }
59 execsql { CREATE TABLE t2(a, b) }
65 proc wal_hook {zDb nEntry} {
66 execsql { PRAGMA wal_checkpoint } db2
69 execsql { CREATE TABLE t3(a PRIMARY KEY, b) }
77 execsql { PRAGMA synchronous = NORMAL }
78 execsql { PRAGMA wal_autocheckpoint }
81 execsql { PRAGMA wal_autocheckpoint = 10}
84 execsql { PRAGMA wal_autocheckpoint }
88 # The database connection is configured with "PRAGMA wal_autocheckpoint = 10".
89 # Check that transactions are written to the log file until it contains at
90 # least 10 frames, then the database is checkpointed. Subsequent transactions
91 # are written into the start of the log file.
93 foreach {tn sql dbpages logpages} {
94 4 "CREATE TABLE t4(x PRIMARY KEY, y)" 6 3
95 5 "INSERT INTO t4 VALUES(1, 'one')" 6 5
96 6 "INSERT INTO t4 VALUES(2, 'two')" 6 7
97 7 "INSERT INTO t4 VALUES(3, 'three')" 6 9
98 8 "INSERT INTO t4 VALUES(4, 'four')" 8 11
99 9 "INSERT INTO t4 VALUES(5, 'five')" 8 11
101 do_test walhook-2.$tn {
103 list [file size test.db] [file size test.db-wal]
104 } [list [expr $dbpages*1024] [wal_file_size $logpages 1024]]