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