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 if {![info exists testdir]} {
14 set testdir [file join [file dirname [info script]] .. .. test]
16 source $testdir/tester.tcl
17 set ::testprefix rbu11
20 #--------------------------------------------------------------------
21 # Test that the xAccess() method of an rbu vfs handles queries other
22 # than SQLITE_ACCESS_EXISTS correctly. The test code below causes
23 # SQLite to call xAccess(SQLITE_ACCESS_READWRITE) on the directory
24 # path argument passed to "PRAGMA temp_store_directory".
27 sqlite3rbu_create_vfs -default rbu ""
29 catchsql { PRAGMA temp_store_directory = '/no/such/directory' }
30 } {1 {not a writable directory}}
33 catchsql " PRAGMA temp_store_directory = '[pwd]' "
37 catchsql " PRAGMA temp_store_directory = '' "
42 sqlite3rbu_destroy_vfs rbu
45 #--------------------------------------------------------------------
46 # Try to trick rbu into operating on a database opened in wal mode.
50 CREATE TABLE t1(a PRIMARY KEY, b, c);
51 INSERT INTO t1 VALUES(1, 2, 3);
52 PRAGMA journal_mode = 'wal';
53 CREATE TABLE t2(d PRIMARY KEY, e, f);
63 CREATE TABLE data_t1(a, b, c, rbu_control);
64 INSERT INTO data_t1 VALUES(4, 5, 6, 0);
65 INSERT INTO data_t1 VALUES(7, 8, 9, 0);
70 hexio_write test.db 18 0101
71 file exists test.db-wal
75 sqlite3rbu rbu test.db rbu.db
80 list [catch {rbu close} msg] $msg
81 } {1 {SQLITE_ERROR - cannot update wal mode database}}
83 #--------------------------------------------------------------------
84 # Test a constraint violation message with an unusual table name.
85 # Specifically, one for which the first character is a codepoint
86 # smaller than 30 (character '0').
90 CREATE TABLE "(t1)"(a PRIMARY KEY, b, c);
91 INSERT INTO "(t1)" VALUES(1, 2, 3);
92 INSERT INTO "(t1)" VALUES(4, 5, 6);
100 CREATE TABLE "data_(t1)"(a, b, c, rbu_control);
101 INSERT INTO "data_(t1)" VALUES(4, 8, 9, 0);
105 sqlite3rbu rbu test.db rbu.db
108 } {SQLITE_CONSTRAINT}
111 list [catch {rbu close} msg] $msg
112 } {1 {SQLITE_CONSTRAINT - UNIQUE constraint failed: (t1).a}}
114 #--------------------------------------------------------------------
115 # Check that once an RBU update has been applied, attempting to apply
116 # it a second time is a no-op (as the state stored in the RBU database is
117 # "all steps completed").
120 do_execsql_test 4.1 {
121 CREATE TABLE "(t1)"(a, b, c, PRIMARY KEY(c, b, a));
122 INSERT INTO "(t1)" VALUES(1, 2, 3);
123 INSERT INTO "(t1)" VALUES(4, 5, 6);
131 CREATE TABLE "data_(t1)"(a, b, c, rbu_control);
132 INSERT INTO "data_(t1)" VALUES(7, 8, 9, 0);
133 INSERT INTO "data_(t1)" VALUES(1, 2, 3, 1);
137 sqlite3rbu rbu test.db rbu.db
138 while {[rbu step]=="SQLITE_OK"} { }
143 sqlite3rbu rbu test.db rbu.db
153 dbo eval { INSERT INTO rbu_state VALUES(100, 100) }
155 sqlite3rbu rbu test.db rbu.db
159 list [catch {rbu close} msg] $msg
163 dbo eval { DELETE FROM rbu_state WHERE k = 100 }
167 # Also, check that an invalid state value in the rbu_state table is
168 # detected and reported as corruption.
171 dbo eval { UPDATE rbu_state SET v = v*-1 WHERE k = 1 }
173 sqlite3rbu rbu test.db rbu.db
177 list [catch {rbu close} msg] $msg
181 dbo eval { UPDATE rbu_state SET v = v*-1 WHERE k = 1 }
187 dbo eval { UPDATE rbu_state SET v = 1 WHERE k = 1 }
188 dbo eval { UPDATE rbu_state SET v = 'nosuchtable' WHERE k = 2 }
190 sqlite3rbu rbu test.db rbu.db
194 list [catch {rbu close} msg] $msg
195 } {1 {SQLITE_ERROR - rbu_state mismatch error}}