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 }
18 # Run the RBU in file $rbu on target database $target until completion.
20 proc run_rbu {target rbu} {
21 sqlite3rbu rbu $target $rbu
22 while { [rbu step]=="SQLITE_OK" } {}
26 forcedelete test.db-oal rbu.db
29 #--------------------------------------------------------------------
30 # Test that for an RBU to be applied, no corruption results if the
31 # affinities on the source and target table do not match.
34 CREATE TABLE x1(a INTEGER PRIMARY KEY, b TEXT, c REAL);
35 CREATE INDEX i1 ON x1(b, c);
41 CREATE TABLE data_x1(a, b, c, rbu_control);
42 INSERT INTO data_x1 VALUES(1, '123', '123', 0);
43 INSERT INTO data_x1 VALUES(2, 123, 123, 0);
46 run_rbu test.db rbu.db
50 PRAGMA integrity_check;
53 #--------------------------------------------------------------------
54 # Test that NULL values may not be inserted into INTEGER PRIMARY KEY
61 CREATE TABLE x1(a INTEGER PRIMARY KEY, b TEXT, c REAL);
62 CREATE INDEX i1 ON x1(b, c);
67 CREATE TABLE data_x1(a, b, c, rbu_control);
68 INSERT INTO data_x1 VALUES(NULL, 'a', 'b', 0);
72 CREATE TABLE data_x1(c, b, a, rbu_control);
73 INSERT INTO data_x1 VALUES('b', 'a', NULL, 0);
81 list [catch { run_rbu test.db rbu.db } msg] $msg
82 } {1 {SQLITE_MISMATCH - datatype mismatch}}
84 do_execsql_test 2.1.2 {
85 PRAGMA integrity_check;
89 #--------------------------------------------------------------------
90 # Test that missing columns are detected.
96 CREATE TABLE x1(a INTEGER PRIMARY KEY, b, c);
97 CREATE INDEX i1 ON x1(b, c);
103 CREATE TABLE data_x1(a, b, rbu_control);
104 INSERT INTO data_x1 VALUES(1, 'a', 0);
107 list [catch { run_rbu test.db rbu.db } msg] $msg
108 } {1 {SQLITE_ERROR - column missing from data_x1: c}}
110 do_execsql_test 2.2 {
111 PRAGMA integrity_check;
114 # Also extra columns.
116 do_execsql_test 2.3 {
117 CREATE TABLE x2(a INTEGER PRIMARY KEY, b, c);
118 CREATE INDEX i2 ON x2(b, c);
125 CREATE TABLE data_x2(a, b, c, d, rbu_control);
126 INSERT INTO data_x2 VALUES(1, 'a', 2, 3, 0);
129 list [catch { run_rbu test.db rbu.db } msg] $msg
132 do_execsql_test 2.5 {
133 PRAGMA integrity_check;
137 #-------------------------------------------------------------------------
138 # Test that sqlite3rbu_create_vfs() returns an error if the requested
139 # parent VFS is unknown.
141 # And that nothing disasterous happens if a VFS name passed to
142 # sqlite3rbu_destroy_vfs() is unknown or not an RBU vfs.
145 list [catch {sqlite3rbu_create_vfs xyz nosuchparent} msg] $msg
146 } {1 SQLITE_NOTFOUND}
149 sqlite3rbu_destroy_vfs nosuchvfs
150 sqlite3rbu_destroy_vfs unix
151 sqlite3rbu_destroy_vfs win32
154 #-------------------------------------------------------------------------
155 # Test that it is an error to specify an explicit VFS that does not
156 # include rbu VFS functionality.
160 sqlite3rbu rbu file:test.db?vfs=tvfs rbu.db
161 list [catch { rbu step } msg] $msg
164 list [catch { rbu close } msg] $msg
165 } {1 {SQLITE_ERROR - rbu vfs not found}}
168 #-------------------------------------------------------------------------
169 # Test a large rbu update to ensure that wal_autocheckpoint does not get
174 do_execsql_test 5.1 {
175 CREATE TABLE x1(a, b, c, PRIMARY KEY(a)) WITHOUT ROWID;
176 CREATE INDEX i1 ON x1(a);
178 ATTACH 'rbu.db' AS rbu;
179 CREATE TABLE rbu.data_x1(a, b, c, rbu_control);
181 SELECT randomblob(300), randomblob(300), 1
183 SELECT randomblob(300), randomblob(300), c+1 FROM s WHERE c<2000
185 INSERT INTO data_x1 SELECT a, b, c, 0 FROM s;
189 sqlite3rbu rbu test.db rbu.db
190 while {[rbu step]=="SQLITE_OK" && [file exists test.db-wal]==0} {}
195 expr {[file size test.db-wal] > (1024 * 1200)}
198 do_test 6.1 { sqlite3rbu_internal_test } {}