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 #***********************************************************************
13 source [file join [file dirname [info script]] rbu_common.tcl]
14 if_no_rbu_support { finish_test ; return }
15 set ::testprefix rbuexlock
19 set journalmode delete
20 if {[permutation]=="inmemory_journal"} {
21 set journalmode memory
24 # Create a simple RBU database. That expects to write to a table:
26 # CREATE TABLE t1(a INTEGER PRIMARY KEY, b, c);
28 proc create_rbu {filename} {
30 sqlite3 rbu1 $filename
32 CREATE TABLE data_t1(a, b, c, rbu_control);
33 INSERT INTO data_t1 VALUES(10, random(), random(), 0);
34 INSERT INTO data_t1 VALUES(20, random(), random(), 0);
35 INSERT INTO data_t1 VALUES(30, random(), random(), 0);
36 INSERT INTO data_t1 VALUES(40, random(), random(), 0);
37 INSERT INTO data_t1 VALUES(50, random(), random(), 0);
38 INSERT INTO data_t1 VALUES(60, random(), random(), 0);
39 INSERT INTO data_t1 VALUES(70, random(), random(), 0);
40 INSERT INTO data_t1 VALUES(80, random(), random(), 0);
49 CREATE TABLE t1(a PRIMARY KEY, b INT, c INT);
50 CREATE INDEX t1b ON t1(b);
51 CREATE INDEX t1c ON t1(c);
52 INSERT INTO t1 VALUES(1, 2, 3);
57 sqlite3rbu rbu file:test.db?rbu_exclusive_checkpoint=1 rbu1.db
60 do_catchsql_test 1.1.1 { SELECT * FROM t1 } {0 {1 2 3}}
63 for {set ii 0} {$ii < 10} {incr ii} {
68 do_catchsql_test 1.2.1 { SELECT * FROM t1 } {0 {1 2 3}}
70 db eval {PRAGMA journal_mode}
74 while {[file exists test.db-wal]==0} {
78 do_catchsql_test 1.3.1 { SELECT * FROM t1 } {1 {database is locked}}
80 db eval {PRAGMA journal_mode}
87 do_catchsql_test 1.4.1 { SELECT * FROM t1 } {1 {database is locked}}
89 db eval {PRAGMA journal_mode}
96 file exists test.db-wal
99 sqlite3rbu rbu file:test.db?rbu_exclusive_checkpoint=1 rbu1.db
100 file exists test.db-wal
102 do_catchsql_test 1.5.2 { SELECT * FROM t1 } {1 {database is locked}}
104 db eval {PRAGMA journal_mode}
111 do_catchsql_test 1.6.1 { SELECT * FROM t1 } {1 {database is locked}}
113 db eval {PRAGMA journal_mode}
117 while {[rbu step]=="SQLITE_OK"} {}
120 do_catchsql_test 1.7.2 { SELECT count(*) FROM t1 } {0 9}
122 db eval {PRAGMA journal_mode}
126 do_execsql_test 2.0 {
127 CREATE TABLE t1(a PRIMARY KEY, b INT, c INT);
128 CREATE INDEX t1b ON t1(b);
129 CREATE INDEX t1c ON t1(c);
130 INSERT INTO t1 VALUES(1, 2, 3);
135 sqlite3rbu rbu file:test.db?rbu_exclusive_checkpoint=0 rbu1.db
138 do_catchsql_test 2.1.1 { SELECT * FROM t1 } {0 {1 2 3}}
141 for {set ii 0} {$ii < 10} {incr ii} {
146 do_catchsql_test 2.2.1 { SELECT * FROM t1 } {0 {1 2 3}}
149 while {[file exists test.db-wal]==0} {
154 llength [db eval {SELECT * FROM t1}]
157 db eval {PRAGMA journal_mode}
164 llength [db eval {SELECT * FROM t1}]
167 db eval {PRAGMA journal_mode}
173 db eval {PRAGMA journal_mode}
175 do_execsql_test 2.5.1 {
181 sqlite3rbu rbu file:test.db?rbu_exclusive_checkpoint=0 rbu1.db
186 set rc [catch {rbu close} msg]
188 } {1 {SQLITE_ERROR - cannot update wal mode database}}
189 db eval {PRAGMA journal_mode=DELETE}
193 sqlite3rbu rbu file:test.db?rbu_exclusive_checkpoint=0 rbu1.db
198 set rc [catch {rbu close} msg]
205 sqlite3rbu rbu file:test.db?rbu_exclusive_checkpoint=0 rbu1.db