3 # The author disclaims copyright to this source code. In place of
4 # a legal notice, here is a blessing:
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.
10 #***********************************************************************
11 # This file implements regression tests for SQLite library. The
12 # focus of this file is testing that WAL databases may be accessed without
13 # using the xShm primitives if the connection is in exclusive-mode.
16 set testdir [file dirname $argv0]
17 source $testdir/tester.tcl
18 set testprefix walnoshm
19 ifcapable !wal {finish_test ; return }
23 testvfs tvfs -default 1 -iversion 1
26 #--------------------------------------------------------------------------
27 # Test that when using a version 1 VFS, a database can only be converted
28 # to WAL mode after setting locking_mode=EXCLUSIVE. Also, test that if a
29 # WAL database is opened using heap-memory for the WAL index, the connection
30 # cannot change back to locking_mode=NORMAL while the database is still in
34 CREATE TABLE t1(x, y);
35 INSERT INTO t1 VALUES(1, 2);
39 PRAGMA journal_mode = WAL;
42 do_test 1.3 { file exists test.db-wal } {0}
45 PRAGMA locking_mode = exclusive;
46 PRAGMA journal_mode = WAL;
49 do_test 1.5 { file exists test.db-wal } {1}
51 do_execsql_test 1.6 { INSERT INTO t1 VALUES(3, 4) }
54 PRAGMA locking_mode = normal;
57 PRAGMA journal_mode = delete;
58 PRAGMA main.locking_mode;
61 PRAGMA locking_mode = normal;
63 do_execsql_test 1.10 {
66 do_test 1.11 { file exists test.db-wal } {0}
68 #-------------------------------------------------------------------------
70 # 2.1.*: Test that a connection using a version 1 VFS can open a WAL database
71 # and convert it to rollback mode if it is set to use
72 # locking_mode=exclusive.
74 # 2.2.*: Test that if the exclusive lock cannot be obtained while attempting
75 # the above, the operation fails and the WAL file is not opened.
77 do_execsql_test 2.1.1 {
78 CREATE TABLE t2(x, y);
79 INSERT INTO t2 VALUES('a', 'b');
80 INSERT INTO t2 VALUES('c', 'd');
82 do_execsql_test 2.1.2 {
83 PRAGMA locking_mode = exclusive;
84 PRAGMA journal_mode = WAL;
85 INSERT INTO t2 VALUES('e', 'f');
86 INSERT INTO t2 VALUES('g', 'h');
90 file copy -force test.db test2.db
91 file copy -force test.db-wal test2.db-wal
93 catchsql { SELECT * FROM t2 } db2
94 } {1 {unable to open database file}}
96 catchsql { PRAGMA journal_mode = delete } db2
97 } {1 {unable to open database file}}
100 PRAGMA locking_mode = exclusive;
101 PRAGMA journal_mode = delete;
104 } {exclusive delete a b c d e f g h}
107 file copy -force test.db test2.db
108 file copy -force test.db-wal test2.db-wal
109 sqlite3 db3 test2.db -vfs tvfsshm
111 execsql { SELECT * FROM t2 } db3
115 execsql { PRAGMA locking_mode = exclusive } db2
116 catchsql { PRAGMA journal_mode = delete } db2
117 } {1 {database is locked}}
120 # This is to test that [db2] is not holding a PENDING lock (which can
121 # happen when an attempt to obtain an EXCLUSIVE lock fails).
122 sqlite3 db4 test2.db -vfs tvfsshm
123 execsql { SELECT * FROM t2 } db4
127 catchsql { SELECT * FROM t2 } db2
128 } {1 {database is locked}}
132 sqlite3 db4 test2.db -vfs tvfsshm
133 execsql { SELECT * FROM t2 } db4
139 execsql { SELECT * FROM t2 } db2
145 #-------------------------------------------------------------------------
147 # 3.1: Test that if locking_mode=EXCLUSIVE is set after the wal file is
148 # opened, it is possible to drop back to locking_mode=NORMAL.
150 # 3.2: Test that if locking_mode=EXCLUSIVE is set before the wal file is
154 sqlite3 db test.db -vfs tvfsshm
157 PRAGMA locking_mode = EXCLUSIVE;
158 INSERT INTO t1 VALUES(5, 6);
159 PRAGMA locking_mode = NORMAL;
160 INSERT INTO t1 VALUES(7, 8);
162 sqlite3 db2 test.db -vfs tvfsshm
163 execsql { SELECT * FROM t1 } db2
168 sqlite3 db test.db -vfs tvfsshm
170 PRAGMA locking_mode = EXCLUSIVE;
171 INSERT INTO t1 VALUES(9, 10);
172 PRAGMA locking_mode = NORMAL;
173 INSERT INTO t1 VALUES(11, 12);
175 sqlite3 db2 test.db -vfs tvfsshm
176 catchsql { SELECT * FROM t1 } db2
177 } {1 {database is locked}}