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 #***********************************************************************
12 # This file contains tests for the RBU module. More specifically, it
13 # contains tests to ensure that the sqlite3rbu_vacuum() API works as
17 source [file join [file dirname [info script]] rbu_common.tcl]
20 set ::testprefix rbuvacuum2-$step
22 #-------------------------------------------------------------------------
23 # Test that a database that contains fts3 tables can be vacuumed.
28 CREATE VIRTUAL TABLE t1 USING fts3(z, y);
29 INSERT INTO t1 VALUES('fix this issue', 'at some point');
32 do_rbu_vacuum_test 1.2 $step
36 } {{fix this issue} {at some point}}
39 SELECT rowid FROM t1 WHERE t1 MATCH 'fix';
43 INSERT INTO t1 VALUES('a b c', 'd e f');
44 INSERT INTO t1 VALUES('l h i', 'd e f');
45 DELETE FROM t1 WHERE docid = 2;
46 INSERT INTO t1 VALUES('a b c', 'x y z');
49 do_rbu_vacuum_test 1.6 $step
51 INSERT INTO t1(t1) VALUES('integrity-check');
54 {fix this issue} {at some point}
60 #-------------------------------------------------------------------------
61 # Test that a database that contains fts5 tables can be vacuumed.
66 CREATE VIRTUAL TABLE t1 USING fts5(z, y);
67 INSERT INTO t1 VALUES('fix this issue', 'at some point');
70 do_rbu_vacuum_test 2.2 $step
74 } {{fix this issue} {at some point}}
77 SELECT rowid FROM t1 ('fix');
81 INSERT INTO t1 VALUES('a b c', 'd e f');
82 INSERT INTO t1 VALUES('l h i', 'd e f');
83 DELETE FROM t1 WHERE rowid = 2;
84 INSERT INTO t1 VALUES('a b c', 'x y z');
87 do_rbu_vacuum_test 2.6 $step
89 INSERT INTO t1(t1) VALUES('integrity-check');
92 {fix this issue} {at some point}
98 #-------------------------------------------------------------------------
99 # Test that a database that contains an rtree table can be vacuumed.
103 do_execsql_test 3.1 {
104 CREATE VIRTUAL TABLE rt USING rtree(id, x1, x2);
105 INSERT INTO rt VALUES(1, 45, 55);
106 INSERT INTO rt VALUES(2, 50, 60);
107 INSERT INTO rt VALUES(3, 55, 65);
110 do_rbu_vacuum_test 3.2 $step
112 do_execsql_test 3.3 {
114 } {1 45.0 55.0 2 50.0 60.0 3 55.0 65.0}
116 do_execsql_test 3.4.1 {
117 SELECT rowid FROM rt WHERE x2>51 AND x1 < 51
119 do_execsql_test 3.4.2 {
120 SELECT rowid FROM rt WHERE x2>59 AND x1 < 59
123 do_rbu_vacuum_test 3.5 $step
125 do_execsql_test 3.6.1 {
126 SELECT rowid FROM rt WHERE x2>51 AND x1 < 51
128 do_execsql_test 3.6.2 {
129 SELECT rowid FROM rt WHERE x2>59 AND x1 < 59
135 do_execsql_test 4.1 {
136 CREATE TABLE t1(a, b, c);
137 INSERT INTO t1 VALUES(1, 2, 3);
138 CREATE VIEW v1 AS SELECT * FROM t1;
139 CREATE TRIGGER tr1 AFTER INSERT ON t1 BEGIN SELECT 1; END;
142 do_execsql_test 4.2 {
143 SELECT * FROM sqlite_master;
145 table t1 t1 2 {CREATE TABLE t1(a, b, c)}
146 view v1 v1 0 {CREATE VIEW v1 AS SELECT * FROM t1}
147 trigger tr1 t1 0 {CREATE TRIGGER tr1 AFTER INSERT ON t1 BEGIN SELECT 1; END}
150 do_rbu_vacuum_test 4.3 $step
151 do_execsql_test 4.4 {
152 SELECT * FROM sqlite_master;
154 table t1 t1 2 {CREATE TABLE t1(a, b, c)}
155 view v1 v1 0 {CREATE VIEW v1 AS SELECT * FROM t1}
156 trigger tr1 t1 0 {CREATE TRIGGER tr1 AFTER INSERT ON t1 BEGIN SELECT 1; END}
161 #-------------------------------------------------------------------------
162 # Test that passing a NULL value as the second argument to
163 # sqlite3rbu_vacuum() causes it to:
165 # * Use <database>-vacuum as the state db, and
166 # * Set the state db permissions to the same as those on the db file.
169 if {$::tcl_platform(platform)=="unix"} {
173 do_execsql_test 5.0 {
174 CREATE TABLE t1(a, b);
175 INSERT INTO t1 VALUES(1, 2);
176 INSERT INTO t1 VALUES(3, 4);
177 INSERT INTO t1 VALUES(5, 6);
178 INSERT INTO t1 VALUES(7, 8);
188 forcedelete test.db-vacuum
191 file attributes test.db -permissions $perm
192 sqlite3rbu_vacuum rbu test.db
196 do_test 5.$tn.2 { file exists test.db-vacuum } 1
197 do_test 5.$tn.3 { file attributes test.db-vacuum -permissions} $perm
202 #-------------------------------------------------------------------------
203 # Test the outcome of some other connection running a checkpoint while
204 # the incremental checkpoint is suspended.
207 do_execsql_test 6.0 {
208 CREATE TABLE t1(a INTEGER PRIMARY KEY, b, c);
209 CREATE INDEX i1b ON t1(b);
210 CREATE INDEX i1c ON t1(c);
211 INSERT INTO t1 VALUES(1, 2, 3);
212 INSERT INTO t1 VALUES(4, 5, 6);
217 sqlite3rbu_vacuum rbu test.db test.db2
218 while {[rbu state]!="checkpoint"} { rbu step }
222 do_execsql_test 6.2 {
223 SELECT 1 FROM sqlite_master LIMIT 1;
224 PRAGMA wal_checkpoint;
228 sqlite3rbu_vacuum rbu test.db test.db2
229 while {[rbu step]!="SQLITE_DONE"} { rbu step }
231 execsql { PRAGMA integrity_check }