blob: a33b43a0056ab83a1570e2c479d6cf7b255ef548 [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
19proc sqlite3_wal {args} {
20 eval sqlite3 $args
21 [lindex $args 0] eval {
22 PRAGMA journal_mode = wal;
23 PRAGMA synchronous = normal;
24 PRAGMA page_size = 1024;
25 }
26}
27sqlite3_wal db test.db
drh833bf962010-04-28 14:42:19 +000028db wal_hook wal_hook
dan8d22a172010-04-19 18:03:51 +000029
drh833bf962010-04-28 14:42:19 +000030set ::wal_hook [list]
31proc wal_hook {zDb nEntry} {
32 lappend ::wal_hook $zDb $nEntry
dan8d22a172010-04-19 18:03:51 +000033 return 0
34}
35
36do_test walhook-1.1 {
37 execsql { CREATE TABLE t1(i PRIMARY KEY, j) }
drh833bf962010-04-28 14:42:19 +000038 set ::wal_hook
dan8d22a172010-04-19 18:03:51 +000039} {main 3}
40do_test walhook-1.2 {
drh833bf962010-04-28 14:42:19 +000041 set ::wal_hook [list]
dan8d22a172010-04-19 18:03:51 +000042 execsql { INSERT INTO t1 VALUES(1, 'one') }
drh833bf962010-04-28 14:42:19 +000043 set ::wal_hook
dan8d22a172010-04-19 18:03:51 +000044} {main 5}
45do_test walhook-1.3 {
drh833bf962010-04-28 14:42:19 +000046 proc wal_hook {args} { return 1 }
dan8d22a172010-04-19 18:03:51 +000047 execsql { INSERT INTO t1 VALUES(2, 'two') }
48 file size test.db
49} [expr 3*1024]
50
51do_test walhook-1.4 {
drh833bf962010-04-28 14:42:19 +000052 proc wal_hook {zDb nEntry} {
dan8d22a172010-04-19 18:03:51 +000053 execsql { PRAGMA checkpoint }
54 return 0
55 }
56 execsql { CREATE TABLE t2(a, b) }
57 file size test.db
58} [expr 4*1024]
59
60do_test walhook-1.5 {
61 sqlite3_wal db2 test.db
drh833bf962010-04-28 14:42:19 +000062 proc wal_hook {zDb nEntry} {
dan8d22a172010-04-19 18:03:51 +000063 execsql { PRAGMA checkpoint } db2
64 return 0
65 }
66 execsql { CREATE TABLE t3(a PRIMARY KEY, b) }
67 file size test.db
68} [expr 6*1024]
69
70catch { db2 close }
71catch { db close }
72finish_test