OLD | NEW |
1 # 2010 December 1 | 1 # 2010 December 1 |
2 # | 2 # |
3 # The author disclaims copyright to this source code. In place of | 3 # The author disclaims copyright to this source code. In place of |
4 # a legal notice, here is a blessing: | 4 # a legal notice, here is a blessing: |
5 # | 5 # |
6 # May you do good and not evil. | 6 # May you do good and not evil. |
7 # May you find forgiveness for yourself and forgive others. | 7 # May you find forgiveness for yourself and forgive others. |
8 # May you share freely, never taking more than you give. | 8 # May you share freely, never taking more than you give. |
9 # | 9 # |
10 #*********************************************************************** | 10 #*********************************************************************** |
11 # This file implements regression tests for SQLite library. The | 11 # This file implements regression tests for SQLite library. The |
12 # focus of this file is testing the operation of the library in | 12 # focus of this file is testing the operation of the library in |
13 # "PRAGMA journal_mode=WAL" mode. | 13 # "PRAGMA journal_mode=WAL" mode. |
14 # | 14 # |
15 | 15 |
16 set testdir [file dirname $argv0] | 16 set testdir [file dirname $argv0] |
| 17 set testprefix wal6 |
17 source $testdir/tester.tcl | 18 source $testdir/tester.tcl |
18 source $testdir/lock_common.tcl | 19 source $testdir/lock_common.tcl |
19 source $testdir/wal_common.tcl | 20 source $testdir/wal_common.tcl |
20 source $testdir/malloc_common.tcl | 21 source $testdir/malloc_common.tcl |
21 ifcapable !wal {finish_test ; return } | 22 ifcapable !wal {finish_test ; return } |
22 | 23 |
23 #------------------------------------------------------------------------- | 24 #------------------------------------------------------------------------- |
24 # Changing to WAL mode in one connection forces the change in others. | 25 # Changing to WAL mode in one connection forces the change in others. |
25 # | 26 # |
26 db close | 27 db close |
27 forcedelete test.db | 28 forcedelete test.db |
28 | 29 |
29 set all_journal_modes {delete persist truncate memory off} | 30 set all_journal_modes {delete persist truncate memory off} |
30 foreach jmode $all_journal_modes { | 31 foreach jmode $all_journal_modes { |
31 | 32 |
32 » do_test wal6-1.0.$jmode { | 33 do_test wal6-1.0.$jmode { |
33 sqlite3 db test.db | 34 sqlite3 db test.db |
34 execsql "PRAGMA journal_mode = $jmode;" | 35 execsql "PRAGMA journal_mode = $jmode;" |
35 » } $jmode | 36 } $jmode |
36 | 37 |
37 » do_test wal6-1.1.$jmode { | 38 do_test wal6-1.1.$jmode { |
38 » execsql { | 39 execsql { |
39 » CREATE TABLE t1(a INTEGER PRIMARY KEY, b); | 40 CREATE TABLE t1(a INTEGER PRIMARY KEY, b); |
40 » INSERT INTO t1 VALUES(1,2); | 41 INSERT INTO t1 VALUES(1,2); |
41 » SELECT * FROM t1; | 42 SELECT * FROM t1; |
42 » } | 43 } |
43 » } {1 2} | 44 } {1 2} |
44 | 45 |
45 # Under Windows, you'll get an error trying to delete | 46 # Under Windows, you'll get an error trying to delete |
46 # a file this is already opened. For now, make sure | 47 # a file this is already opened. Close the first connection |
47 # we get that error, then close the first connection | |
48 # so the other tests work. | 48 # so the other tests work. |
49 if {$tcl_platform(platform)=="windows"} { | 49 if {$tcl_platform(platform)=="windows"} { |
50 if {$jmode=="persist" || $jmode=="truncate"} { | 50 if {$jmode=="persist" || $jmode=="truncate"} { |
51 » do_test wal6-1.2.$jmode.win { | 51 db close |
52 » sqlite3 db2 test.db | |
53 » catchsql { | |
54 » » PRAGMA journal_mode=WAL; | |
55 » } db2 | |
56 » } {1 {disk I/O error}} | |
57 » db2 close | |
58 » db close | |
59 } | 52 } |
60 } | 53 } |
61 | 54 |
62 » do_test wal6-1.2.$jmode { | 55 do_test wal6-1.2.$jmode { |
63 » sqlite3 db2 test.db | 56 sqlite3 db2 test.db |
64 » execsql { | 57 execsql { |
65 » » PRAGMA journal_mode=WAL; | 58 PRAGMA journal_mode=WAL; |
66 » » INSERT INTO t1 VALUES(3,4); | 59 INSERT INTO t1 VALUES(3,4); |
67 » » SELECT * FROM t1 ORDER BY a; | 60 SELECT * FROM t1 ORDER BY a; |
68 » } db2 | 61 } db2 |
69 » } {wal 1 2 3 4} | 62 } {wal 1 2 3 4} |
70 | 63 |
71 if {$tcl_platform(platform)=="windows"} { | 64 if {$tcl_platform(platform)=="windows"} { |
72 if {$jmode=="persist" || $jmode=="truncate"} { | 65 if {$jmode=="persist" || $jmode=="truncate"} { |
73 » sqlite3 db test.db | 66 sqlite3 db test.db |
74 } | 67 } |
75 } | 68 } |
76 | 69 |
77 » do_test wal6-1.3.$jmode { | 70 do_test wal6-1.3.$jmode { |
78 » execsql { | 71 execsql { |
79 » » SELECT * FROM t1 ORDER BY a; | 72 SELECT * FROM t1 ORDER BY a; |
80 » } | 73 } |
81 » } {1 2 3 4} | 74 } {1 2 3 4} |
82 | 75 |
83 » db close | 76 db close |
84 » db2 close | 77 db2 close |
85 forcedelete test.db | 78 forcedelete test.db |
86 | 79 |
87 } | 80 } |
88 | 81 |
| 82 #------------------------------------------------------------------------- |
| 83 # Test that SQLITE_BUSY_SNAPSHOT is returned as expected. |
| 84 # |
| 85 reset_db |
| 86 sqlite3 db2 test.db |
| 87 |
| 88 do_execsql_test 2.1 { |
| 89 PRAGMA journal_mode = WAL; |
| 90 CREATE TABLE t1(a PRIMARY KEY, b TEXT); |
| 91 INSERT INTO t1 VALUES(1, 'one'); |
| 92 INSERT INTO t1 VALUES(2, 'two'); |
| 93 BEGIN; |
| 94 SELECT * FROM t1; |
| 95 } {wal 1 one 2 two} |
| 96 |
| 97 do_test 2.2 { |
| 98 execsql { |
| 99 SELECT * FROM t1; |
| 100 INSERT INTO t1 VALUES(3, 'three'); |
| 101 } db2 |
| 102 } {1 one 2 two} |
| 103 |
| 104 do_catchsql_test 2.3 { |
| 105 INSERT INTO t1 VALUES('x', 'x') |
| 106 } {1 {database is locked}} |
| 107 |
| 108 do_test 2.4 { |
| 109 list [sqlite3_errcode db] [sqlite3_extended_errcode db] |
| 110 } {SQLITE_BUSY SQLITE_BUSY_SNAPSHOT} |
| 111 |
| 112 do_execsql_test 2.5 { |
| 113 SELECT * FROM t1; |
| 114 COMMIT; |
| 115 INSERT INTO t1 VALUES('x', 'x') |
| 116 } {1 one 2 two} |
| 117 |
| 118 proc test3 {prefix} { |
| 119 do_test $prefix.1 { |
| 120 execsql { SELECT count(*) FROM t1 } |
| 121 } {0} |
| 122 do_test $prefix.2 { |
| 123 execsql { INSERT INTO t1 VALUES('x', 'x') } db2 |
| 124 } {} |
| 125 do_test $prefix.3 { |
| 126 execsql { INSERT INTO t1 VALUES('y', 'y') } |
| 127 } {} |
| 128 do_test $prefix.4 { |
| 129 execsql { SELECT count(*) FROM t1 } |
| 130 } {2} |
| 131 } |
| 132 |
| 133 do_execsql_test 2.6.1 { DELETE FROM t1 } |
| 134 test3 2.6.2 |
| 135 |
| 136 db func test3 test3 |
| 137 do_execsql_test 2.6.3 { DELETE FROM t1 } |
| 138 db eval {SELECT test3('2.6.4')} |
| 139 |
| 140 do_test 2.x { |
| 141 db2 close |
| 142 } {} |
| 143 |
| 144 #------------------------------------------------------------------------- |
| 145 # Check that if BEGIN IMMEDIATE fails, it does not leave the user with |
| 146 # an open read-transaction (unless one was already open before the BEGIN |
| 147 # IMMEDIATE). Even if there are other active VMs. |
| 148 # |
| 149 |
| 150 proc test4 {prefix} { |
| 151 do_test $prefix.1 { |
| 152 catchsql { BEGIN IMMEDIATE } |
| 153 } {1 {database is locked}} |
| 154 |
| 155 do_test $prefix.2 { |
| 156 execsql { COMMIT } db2 |
| 157 } {} |
| 158 |
| 159 do_test $prefix.3 { |
| 160 execsql { BEGIN IMMEDIATE } |
| 161 } {} |
| 162 do_test $prefix.4 { |
| 163 execsql { COMMIT } |
| 164 } {} |
| 165 } |
| 166 |
| 167 reset_db |
| 168 sqlite3 db2 test.db |
| 169 do_execsql_test 3.1 { |
| 170 PRAGMA journal_mode = WAL; |
| 171 CREATE TABLE ab(a PRIMARY KEY, b); |
| 172 } {wal} |
| 173 |
| 174 do_test 3.2.1 { |
| 175 execsql { |
| 176 BEGIN; |
| 177 INSERT INTO ab VALUES(1, 2); |
| 178 } db2 |
| 179 } {} |
| 180 test4 3.2.2 |
| 181 |
| 182 db func test4 test4 |
| 183 do_test 3.3.1 { |
| 184 execsql { |
| 185 BEGIN; |
| 186 INSERT INTO ab VALUES(3, 4); |
| 187 } db2 |
| 188 } {} |
| 189 |
| 190 db eval {SELECT test4('3.3.2')} |
| 191 |
| 192 do_test 3.x { |
| 193 db2 close |
| 194 } {} |
| 195 |
89 finish_test | 196 finish_test |
90 | 197 |
OLD | NEW |