dan | 8d22a17 | 2010-04-19 18:03:51 +0000 | [diff] [blame] | 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 | |
| 16 | set testdir [file dirname $argv0] |
| 17 | source $testdir/tester.tcl |
| 18 | |
dan | 5cf5353 | 2010-05-01 16:40:20 +0000 | [diff] [blame^] | 19 | ifcapable !wal {finish_test ; return } |
| 20 | |
dan | 8d22a17 | 2010-04-19 18:03:51 +0000 | [diff] [blame] | 21 | proc 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 | } |
| 29 | sqlite3_wal db test.db |
drh | 833bf96 | 2010-04-28 14:42:19 +0000 | [diff] [blame] | 30 | db wal_hook wal_hook |
dan | 8d22a17 | 2010-04-19 18:03:51 +0000 | [diff] [blame] | 31 | |
drh | 833bf96 | 2010-04-28 14:42:19 +0000 | [diff] [blame] | 32 | set ::wal_hook [list] |
| 33 | proc wal_hook {zDb nEntry} { |
| 34 | lappend ::wal_hook $zDb $nEntry |
dan | 8d22a17 | 2010-04-19 18:03:51 +0000 | [diff] [blame] | 35 | return 0 |
| 36 | } |
| 37 | |
| 38 | do_test walhook-1.1 { |
| 39 | execsql { CREATE TABLE t1(i PRIMARY KEY, j) } |
drh | 833bf96 | 2010-04-28 14:42:19 +0000 | [diff] [blame] | 40 | set ::wal_hook |
dan | 8d22a17 | 2010-04-19 18:03:51 +0000 | [diff] [blame] | 41 | } {main 3} |
| 42 | do_test walhook-1.2 { |
drh | 833bf96 | 2010-04-28 14:42:19 +0000 | [diff] [blame] | 43 | set ::wal_hook [list] |
dan | 8d22a17 | 2010-04-19 18:03:51 +0000 | [diff] [blame] | 44 | execsql { INSERT INTO t1 VALUES(1, 'one') } |
drh | 833bf96 | 2010-04-28 14:42:19 +0000 | [diff] [blame] | 45 | set ::wal_hook |
dan | 8d22a17 | 2010-04-19 18:03:51 +0000 | [diff] [blame] | 46 | } {main 5} |
| 47 | do_test walhook-1.3 { |
drh | 833bf96 | 2010-04-28 14:42:19 +0000 | [diff] [blame] | 48 | proc wal_hook {args} { return 1 } |
dan | 8d22a17 | 2010-04-19 18:03:51 +0000 | [diff] [blame] | 49 | execsql { INSERT INTO t1 VALUES(2, 'two') } |
| 50 | file size test.db |
| 51 | } [expr 3*1024] |
| 52 | |
| 53 | do_test walhook-1.4 { |
drh | 833bf96 | 2010-04-28 14:42:19 +0000 | [diff] [blame] | 54 | proc wal_hook {zDb nEntry} { |
dan | 8d22a17 | 2010-04-19 18:03:51 +0000 | [diff] [blame] | 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 | |
| 62 | do_test walhook-1.5 { |
| 63 | sqlite3_wal db2 test.db |
drh | 833bf96 | 2010-04-28 14:42:19 +0000 | [diff] [blame] | 64 | proc wal_hook {zDb nEntry} { |
dan | 8d22a17 | 2010-04-19 18:03:51 +0000 | [diff] [blame] | 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 | |
| 72 | catch { db2 close } |
| 73 | catch { db close } |
| 74 | finish_test |