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
20 # Run the RBU in file $rbu on target database $target until completion.
22 proc run_rbu {target rbu} {
23 sqlite3rbu rbu $target $rbu
24 while { [rbu step]=="SQLITE_OK" } {}
28 forcedelete test.db-oal rbu.db
34 #--------------------------------------------------------------------
35 # Test that for an RBU to be applied, no corruption results if the
36 # affinities on the source and target table do not match.
39 CREATE TABLE x1(a INTEGER PRIMARY KEY, b TEXT, c REAL);
40 CREATE INDEX i1 ON x1(b, c);
46 CREATE TABLE data_x1(a, b, c, rbu_control);
47 INSERT INTO data_x1 VALUES(1, '123', '123', 0);
48 INSERT INTO data_x1 VALUES(2, 123, 123, 0);
51 run_rbu test.db rbu.db
55 PRAGMA integrity_check;
58 #--------------------------------------------------------------------
59 # Test that NULL values may not be inserted into INTEGER PRIMARY KEY
66 CREATE TABLE x1(a INTEGER PRIMARY KEY, b TEXT, c REAL);
67 CREATE INDEX i1 ON x1(b, c);
72 CREATE TABLE data_x1(a, b, c, rbu_control);
73 INSERT INTO data_x1 VALUES(NULL, 'a', 'b', 0);
77 CREATE TABLE data_x1(c, b, a, rbu_control);
78 INSERT INTO data_x1 VALUES('b', 'a', NULL, 0);
86 list [catch { run_rbu test.db rbu.db } msg] $msg
87 } {1 {SQLITE_MISMATCH - datatype mismatch}}
89 do_execsql_test 2.1.2 {
90 PRAGMA integrity_check;
94 #--------------------------------------------------------------------
95 # Test that missing columns are detected.
100 do_execsql_test 2.0 {
101 CREATE TABLE x1(a INTEGER PRIMARY KEY, b, c);
102 CREATE INDEX i1 ON x1(b, c);
108 CREATE TABLE data_x1(a, b, rbu_control);
109 INSERT INTO data_x1 VALUES(1, 'a', 0);
112 list [catch { run_rbu test.db rbu.db } msg] $msg
113 } {1 {SQLITE_ERROR - column missing from data_x1: c}}
115 do_execsql_test 2.2 {
116 PRAGMA integrity_check;
119 # Also extra columns.
121 do_execsql_test 2.3 {
122 CREATE TABLE x2(a INTEGER PRIMARY KEY, b, c);
123 CREATE INDEX i2 ON x2(b, c);
130 CREATE TABLE data_x2(a, b, c, d, rbu_control);
131 INSERT INTO data_x2 VALUES(1, 'a', 2, 3, 0);
134 list [catch { run_rbu test.db rbu.db } msg] $msg
137 do_execsql_test 2.5 {
138 PRAGMA integrity_check;
142 #-------------------------------------------------------------------------
143 # Test that sqlite3rbu_create_vfs() returns an error if the requested
144 # parent VFS is unknown.
146 # And that nothing disasterous happens if a VFS name passed to
147 # sqlite3rbu_destroy_vfs() is unknown or not an RBU vfs.
150 list [catch {sqlite3rbu_create_vfs xyz nosuchparent} msg] $msg
151 } {1 SQLITE_NOTFOUND}
154 sqlite3rbu_destroy_vfs nosuchvfs
155 sqlite3rbu_destroy_vfs unix
156 sqlite3rbu_destroy_vfs win32
159 #-------------------------------------------------------------------------
160 # Test that it is an error to specify an explicit VFS that does not
161 # include rbu VFS functionality.
165 sqlite3rbu rbu file:test.db?vfs=tvfs rbu.db
166 list [catch { rbu step } msg] $msg
169 list [catch { rbu close } msg] $msg
170 } {1 {SQLITE_ERROR - rbu vfs not found}}
173 #-------------------------------------------------------------------------
174 # Test a large rbu update to ensure that wal_autocheckpoint does not get
179 do_execsql_test 5.1 {
180 CREATE TABLE x1(a, b, c, PRIMARY KEY(a)) WITHOUT ROWID;
181 CREATE INDEX i1 ON x1(a);
183 ATTACH 'rbu.db' AS rbu;
184 CREATE TABLE rbu.data_x1(a, b, c, rbu_control);
186 SELECT randomblob(300), randomblob(300), 1
188 SELECT randomblob(300), randomblob(300), c+1 FROM s WHERE c<2000
190 INSERT INTO data_x1 SELECT a, b, c, 0 FROM s;
194 sqlite3rbu rbu test.db rbu.db
195 while {[rbu step]=="SQLITE_OK" && [file exists test.db-wal]==0} {}
200 expr {[file size test.db-wal] > (1024 * 1200)}
203 do_test 6.1 { sqlite3rbu_internal_test } {}