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 rbu11
18 #--------------------------------------------------------------------
19 # Test that the xAccess() method of an rbu vfs handles queries other
20 # than SQLITE_ACCESS_EXISTS correctly. The test code below causes
21 # SQLite to call xAccess(SQLITE_ACCESS_READWRITE) on the directory
22 # path argument passed to "PRAGMA temp_store_directory".
25 sqlite3rbu_create_vfs -default rbu ""
27 catchsql { PRAGMA temp_store_directory = '/no/such/directory' }
28 } {1 {not a writable directory}}
31 catchsql " PRAGMA temp_store_directory = '[pwd]' "
35 catchsql " PRAGMA temp_store_directory = '' "
40 sqlite3rbu_destroy_vfs rbu
43 #--------------------------------------------------------------------
44 # Try to trick rbu into operating on a database opened in wal mode.
48 CREATE TABLE t1(a PRIMARY KEY, b, c);
49 INSERT INTO t1 VALUES(1, 2, 3);
50 PRAGMA journal_mode = 'wal';
51 CREATE TABLE t2(d PRIMARY KEY, e, f);
61 CREATE TABLE data_t1(a, b, c, rbu_control);
62 INSERT INTO data_t1 VALUES(4, 5, 6, 0);
63 INSERT INTO data_t1 VALUES(7, 8, 9, 0);
68 hexio_write test.db 18 0101
69 file exists test.db-wal
73 sqlite3rbu rbu test.db rbu.db
78 list [catch {rbu close} msg] $msg
79 } {1 {SQLITE_ERROR - cannot update wal mode database}}
81 #--------------------------------------------------------------------
82 # Test a constraint violation message with an unusual table name.
83 # Specifically, one for which the first character is a codepoint
84 # smaller than 30 (character '0').
88 CREATE TABLE "(t1)"(a PRIMARY KEY, b, c);
89 INSERT INTO "(t1)" VALUES(1, 2, 3);
90 INSERT INTO "(t1)" VALUES(4, 5, 6);
98 CREATE TABLE "data_(t1)"(a, b, c, rbu_control);
99 INSERT INTO "data_(t1)" VALUES(4, 8, 9, 0);
103 sqlite3rbu rbu test.db rbu.db
106 } {SQLITE_CONSTRAINT}
109 list [catch {rbu close} msg] $msg
110 } {1 {SQLITE_CONSTRAINT - UNIQUE constraint failed: (t1).a}}
112 #--------------------------------------------------------------------
113 # Check that once an RBU update has been applied, attempting to apply
114 # it a second time is a no-op (as the state stored in the RBU database is
115 # "all steps completed").
118 do_execsql_test 4.1 {
119 CREATE TABLE "(t1)"(a, b, c, PRIMARY KEY(c, b, a));
120 INSERT INTO "(t1)" VALUES(1, 2, 3);
121 INSERT INTO "(t1)" VALUES(4, 5, 6);
129 CREATE TABLE "data_(t1)"(a, b, c, rbu_control);
130 INSERT INTO "data_(t1)" VALUES(7, 8, 9, 0);
131 INSERT INTO "data_(t1)" VALUES(1, 2, 3, 1);
135 sqlite3rbu rbu test.db rbu.db
136 while {[rbu step]=="SQLITE_OK"} { }
141 sqlite3rbu rbu test.db rbu.db
151 dbo eval { INSERT INTO rbu_state VALUES(100, 100) }
153 sqlite3rbu rbu test.db rbu.db
157 list [catch {rbu close} msg] $msg
161 dbo eval { DELETE FROM rbu_state WHERE k = 100 }
165 # Also, check that an invalid state value in the rbu_state table is
166 # detected and reported as corruption.
169 dbo eval { UPDATE rbu_state SET v = v*-1 WHERE k = 1 }
171 sqlite3rbu rbu test.db rbu.db
175 list [catch {rbu close} msg] $msg
179 dbo eval { UPDATE rbu_state SET v = v*-1 WHERE k = 1 }
185 dbo eval { UPDATE rbu_state SET v = 1 WHERE k = 1 }
186 dbo eval { UPDATE rbu_state SET v = 'nosuchtable' WHERE k = 2 }
188 sqlite3rbu rbu test.db rbu.db
192 list [catch {rbu close} msg] $msg
193 } {1 {SQLITE_ERROR - rbu_state mismatch error}}