Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/sqlite/blob/master/ext/rbu/rbuvacuum2.test # sqlite [Ported from github.com/sqlite/sqlite] Fix bugs in and improve the interface to the ".check" command of the CLI. Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `master` Branches Tags History `sqlite / ext / rbu / rbuvacuum2.test` 249 lines ยท 6688 bytes Raw Blame History 1 # 2016 June 1 2 # 3 # The author disclaims copyright to this source code. In place of 4 # a legal notice, here is a blessing: 5 # 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. 9 # 10 #*********************************************************************** 11 # 12 # This file contains tests for the RBU module. More specifically, it 13 # contains tests to ensure that the sqlite3rbu_vacuum() API works as 14 # expected. 15 # 16 17 source [file join [file dirname [info script]] rbu_common.tcl] 18 if_no_rbu_support { finish_test ; return } 19 20 foreach {step} {0 1} { 21 foreach {ttt state} { 22 s state.db t test.db-vacuum n {} 23 } { 24 set ::testprefix rbuvacuum2-$step$ttt 25 26 #------------------------------------------------------------------------- 27 # Test that a database that contains fts3 tables can be vacuumed. 28 # 29 ifcapable fts3 { 30 reset_db 31 do_execsql_test 1.1 { 32 CREATE VIRTUAL TABLE t1 USING fts3(z, y); 33 INSERT INTO t1 VALUES('fix this issue', 'at some point'); 34 } 35 36 do_rbu_vacuum_test 1.2 $step $state 37 38 do_execsql_test 1.3 { 39 SELECT * FROM t1; 40 } {{fix this issue} {at some point}} 41 42 do_execsql_test 1.4 { 43 SELECT rowid FROM t1 WHERE t1 MATCH 'fix'; 44 } {1} 45 46 do_execsql_test 1.5 { 47 INSERT INTO t1 VALUES('a b c', 'd e f'); 48 INSERT INTO t1 VALUES('l h i', 'd e f'); 49 DELETE FROM t1 WHERE docid = 2; 50 INSERT INTO t1 VALUES('a b c', 'x y z'); 51 } 52 53 do_rbu_vacuum_test 1.6 $step $state 54 do_execsql_test 1.7 { 55 INSERT INTO t1(t1) VALUES('integrity-check'); 56 SELECT * FROM t1; 57 } { 58 {fix this issue} {at some point} 59 {l h i} {d e f} 60 {a b c} {x y z} 61 } 62 } 63 64 #------------------------------------------------------------------------- 65 # Test that a database that contains fts5 tables can be vacuumed. 66 # 67 ifcapable fts5 { 68 reset_db 69 do_execsql_test 2.1 { 70 CREATE VIRTUAL TABLE t1 USING fts5(z, y); 71 INSERT INTO t1 VALUES('fix this issue', 'at some point'); 72 } 73 74 do_rbu_vacuum_test 2.2 $step $state 75 76 do_execsql_test 2.3 { 77 SELECT * FROM t1; 78 } {{fix this issue} {at some point}} 79 80 do_execsql_test 2.4 { 81 SELECT rowid FROM t1 ('fix'); 82 } {1} 83 84 do_execsql_test 2.5 { 85 INSERT INTO t1 VALUES('a b c', 'd e f'); 86 INSERT INTO t1 VALUES('l h i', 'd e f'); 87 DELETE FROM t1 WHERE rowid = 2; 88 INSERT INTO t1 VALUES('a b c', 'x y z'); 89 } 90 91 do_rbu_vacuum_test 2.6 $step $state 92 do_execsql_test 2.7 { 93 INSERT INTO t1(t1) VALUES('integrity-check'); 94 SELECT * FROM t1; 95 } { 96 {fix this issue} {at some point} 97 {l h i} {d e f} 98 {a b c} {x y z} 99 } 100 } 101 102 #------------------------------------------------------------------------- 103 # Test that a database that contains an rtree table can be vacuumed. 104 # 105 ifcapable rtree { 106 reset_db 107 do_execsql_test 3.1 { 108 CREATE VIRTUAL TABLE rt USING rtree(id, x1, x2); 109 INSERT INTO rt VALUES(1, 45, 55); 110 INSERT INTO rt VALUES(2, 50, 60); 111 INSERT INTO rt VALUES(3, 55, 65); 112 } 113 114 do_rbu_vacuum_test 3.2 $step $state 115 116 do_execsql_test 3.3 { 117 SELECT * FROM rt; 118 } {1 45.0 55.0 2 50.0 60.0 3 55.0 65.0} 119 120 do_execsql_test 3.4.1 { 121 SELECT rowid FROM rt WHERE x2>51 AND x1 < 51 122 } {1 2} 123 do_execsql_test 3.4.2 { 124 SELECT rowid FROM rt WHERE x2>59 AND x1 < 59 125 } {2 3} 126 127 do_rbu_vacuum_test 3.5 $step $state 128 129 do_execsql_test 3.6.1 { 130 SELECT rowid FROM rt WHERE x2>51 AND x1 < 51 131 } {1 2} 132 do_execsql_test 3.6.2 { 133 SELECT rowid FROM rt WHERE x2>59 AND x1 < 59 134 } {2 3} 135 } 136 137 ifcapable trigger { 138 reset_db 139 do_execsql_test 4.1 { 140 CREATE TABLE t1(a, b, c); 141 INSERT INTO t1 VALUES(1, 2, 3); 142 CREATE VIEW v1 AS SELECT * FROM t1; 143 CREATE TRIGGER tr1 AFTER INSERT ON t1 BEGIN SELECT 1; END; 144 } 145 146 do_execsql_test 4.2 { 147 SELECT * FROM sqlite_master; 148 } { 149 table t1 t1 2 {CREATE TABLE t1(a, b, c)} 150 view v1 v1 0 {CREATE VIEW v1 AS SELECT * FROM t1} 151 trigger tr1 t1 0 {CREATE TRIGGER tr1 AFTER INSERT ON t1 BEGIN SELECT 1; END} 152 } 153 154 do_rbu_vacuum_test 4.3 $step $state 155 do_execsql_test 4.4 { 156 SELECT * FROM sqlite_master; 157 } { 158 table t1 t1 2 {CREATE TABLE t1(a, b, c)} 159 view v1 v1 0 {CREATE VIEW v1 AS SELECT * FROM t1} 160 trigger tr1 t1 0 {CREATE TRIGGER tr1 AFTER INSERT ON t1 BEGIN SELECT 1; END} 161 } 162 } 163 } 164 } 165 166 #------------------------------------------------------------------------- 167 # Test that passing a NULL value as the second argument to 168 # sqlite3rbu_vacuum() causes it to: 169 # 170 # * Use -vacuum as the state db, and 171 # * Set the state db permissions to the same as those on the db file. 172 # 173 db close 174 if {$::tcl_platform(platform) eq "unix"} { 175 forcedelete test.db 176 177 sqlite3 db test.db 178 do_execsql_test 5.0 { 179 CREATE TABLE t1(a, b); 180 INSERT INTO t1 VALUES(1, 2); 181 INSERT INTO t1 VALUES(3, 4); 182 INSERT INTO t1 VALUES(5, 6); 183 INSERT INTO t1 VALUES(7, 8); 184 } 185 db close 186 187 foreach {tn perm} { 188 1 00755 189 2 00666 190 3 00644 191 4 00444 192 } { 193 forcedelete test.db-vacuum 194 195 do_test 5.$tn.1 { 196 file attributes test.db -permissions $perm 197 sqlite3rbu_vacuum rbu test.db 198 rbu step 199 } {SQLITE_OK} 200 201 do_test 5.$tn.2 { file exists test.db-vacuum } 1 202 # The result pattern might be 00xxx or 0oxxx depending on which 203 # version of TCL is being used. So make perm2 into a regexp that 204 # will match either 205 regsub {^00} $perm {0.} perm2 206 do_test 5.$tn.3 { file attributes test.db-vacuum -permissions} /$perm2/ 207 rbu close 208 } 209 } 210 211 #------------------------------------------------------------------------- 212 # Test the outcome of some other connection running a checkpoint while 213 # the incremental checkpoint is suspended. 214 # 215 reset_db 216 do_execsql_test 6.0 { 217 CREATE TABLE t1(a INTEGER PRIMARY KEY, b, c); 218 CREATE INDEX i1b ON t1(b); 219 CREATE INDEX i1c ON t1(c); 220 INSERT INTO t1 VALUES(1, 2, 3); 221 INSERT INTO t1 VALUES(4, 5, 6); 222 } 223 forcedelete test.db2 224 225 do_test 6.1 { 226 sqlite3rbu_vacuum rbu test.db test.db2 227 while {[rbu state]!="checkpoint"} { rbu step } 228 rbu close 229 } {SQLITE_OK} 230 231 do_test 6.2 { 232 execsql { SELECT 1 FROM sqlite_master LIMIT 1 } 233 execsql { PRAGMA wal_checkpoint } 234 execsql { SELECT 1 FROM sqlite_master LIMIT 1 } 235 } {1} 236 237 do_test 6.3 { 238 sqlite3rbu_vacuum rbu test.db test.db2 239 while {[rbu step]!="SQLITE_DONE"} { rbu step } 240 rbu close 241 execsql { PRAGMA integrity_check } 242 } {ok} 243 244 do_test 6.4 { 245 sqlite3rbu_vacuum rbu test.db test.db-vactmp 246 list [catch { rbu close } msg] $msg 247 } {1 SQLITE_MISUSE} 248 249 finish_test