blob: 49f07dda53a4cf42330d9c938647566f502b7bab [file] [log] [blame]
dan8d22a172010-04-19 18:03:51 +00001# 2010 April 19
2#
3# The author disclaims copyright to this source code. In place of
4# a legal notice, here is a blessing:
5#
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.
9#
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.
14#
15
16set testdir [file dirname $argv0]
17source $testdir/tester.tcl
18
dan5cf53532010-05-01 16:40:20 +000019ifcapable !wal {finish_test ; return }
20
dan8d22a172010-04-19 18:03:51 +000021proc sqlite3_wal {args} {
22 eval sqlite3 $args
23 [lindex $args 0] eval {
24 PRAGMA journal_mode = wal;
25 PRAGMA synchronous = normal;
26 PRAGMA page_size = 1024;
27 }
28}
29sqlite3_wal db test.db
drh833bf962010-04-28 14:42:19 +000030db wal_hook wal_hook
dan8d22a172010-04-19 18:03:51 +000031
drh833bf962010-04-28 14:42:19 +000032set ::wal_hook [list]
33proc wal_hook {zDb nEntry} {
34 lappend ::wal_hook $zDb $nEntry
dan8d22a172010-04-19 18:03:51 +000035 return 0
36}
37
38do_test walhook-1.1 {
39 execsql { CREATE TABLE t1(i PRIMARY KEY, j) }
drh833bf962010-04-28 14:42:19 +000040 set ::wal_hook
dan8d22a172010-04-19 18:03:51 +000041} {main 3}
42do_test walhook-1.2 {
drh833bf962010-04-28 14:42:19 +000043 set ::wal_hook [list]
dan8d22a172010-04-19 18:03:51 +000044 execsql { INSERT INTO t1 VALUES(1, 'one') }
drh833bf962010-04-28 14:42:19 +000045 set ::wal_hook
dan8d22a172010-04-19 18:03:51 +000046} {main 5}
47do_test walhook-1.3 {
drh833bf962010-04-28 14:42:19 +000048 proc wal_hook {args} { return 1 }
dan8d22a172010-04-19 18:03:51 +000049 execsql { INSERT INTO t1 VALUES(2, 'two') }
50 file size test.db
51} [expr 3*1024]
52
53do_test walhook-1.4 {
drh833bf962010-04-28 14:42:19 +000054 proc wal_hook {zDb nEntry} {
dan8d22a172010-04-19 18:03:51 +000055 execsql { PRAGMA checkpoint }
56 return 0
57 }
58 execsql { CREATE TABLE t2(a, b) }
59 file size test.db
60} [expr 4*1024]
61
62do_test walhook-1.5 {
63 sqlite3_wal db2 test.db
drh833bf962010-04-28 14:42:19 +000064 proc wal_hook {zDb nEntry} {
dan8d22a172010-04-19 18:03:51 +000065 execsql { PRAGMA checkpoint } db2
66 return 0
67 }
68 execsql { CREATE TABLE t3(a PRIMARY KEY, b) }
69 file size test.db
70} [expr 6*1024]
71
72catch { db2 close }
73catch { db close }
74finish_test