1# 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 28db wal_hook wal_hook 29 30set ::wal_hook [list] 31proc wal_hook {zDb nEntry} { 32 lappend ::wal_hook $zDb $nEntry 33 return 0 34} 35 36do_test walhook-1.1 { 37 execsql { CREATE TABLE t1(i PRIMARY KEY, j) } 38 set ::wal_hook 39} {main 3} 40do_test walhook-1.2 { 41 set ::wal_hook [list] 42 execsql { INSERT INTO t1 VALUES(1, 'one') } 43 set ::wal_hook 44} {main 5} 45do_test walhook-1.3 { 46 proc wal_hook {args} { return 1 } 47 execsql { INSERT INTO t1 VALUES(2, 'two') } 48 file size test.db 49} [expr 3*1024] 50 51do_test walhook-1.4 { 52 proc wal_hook {zDb nEntry} { 53 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 62 proc wal_hook {zDb nEntry} { 63 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 73