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