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/rbumisc.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 / rbumisc.test` 262 lines ยท 6426 bytes Raw Blame History 1 # 2014 August 30 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 13 source [file join [file dirname [info script]] rbu_common.tcl] 14 if_no_rbu_support { finish_test ; return } 15 set ::testprefix rbumisc 16 17 proc populate_rbu_db {} { 18 forcedelete rbu.db 19 sqlite3 rbu rbu.db 20 rbu eval { 21 CREATE TABLE data_x1(a, b, c, rbu_control); 22 INSERT INTO data_x1 VALUES(1, 1, 1, 0); 23 INSERT INTO data_x1 VALUES(2, 2, 2, 0); 24 25 CREATE TABLE dat(a, b, c, rbu_control); 26 CREATE TABLE "data x1"(a, b, c, rbu_control); 27 CREATE TABLE datax1(a, b, c, rbu_control); 28 CREATE TABLE data_(a, b, c, rbu_control); 29 30 INSERT INTO "data x1" VALUES(3, 3, 3, 0); 31 INSERT INTO datax1 VALUES(3, 3, 3, 0); 32 INSERT INTO data_ VALUES(3, 3, 3, 0); 33 INSERT INTO dat VALUES(3, 3, 3, 0); 34 } 35 rbu close 36 } 37 38 #------------------------------------------------------------------------- 39 # Ensure that RBU is not confused by oddly named tables in an RBU 40 # database. 41 # 42 do_execsql_test 1.0 { 43 CREATE TABLE x1(a, b, c INTEGER PRIMARY KEY); 44 } 45 do_test 1.1 { 46 populate_rbu_db 47 } {} 48 49 do_test 1.2 { 50 step_rbu test.db rbu.db 51 db eval { SELECT * FROM x1 } 52 } {1 1 1 2 2 2} 53 54 do_test 1.3 { 55 db eval { DELETE FROM x1 } 56 sqlite3 rbu rbu.db 57 rbu eval { DELETE FROM rbu_state } 58 rbu close 59 step_rbu test.db rbu.db 60 db eval { SELECT * FROM x1 } 61 } {1 1 1 2 2 2} 62 63 do_test 1.4 { 64 db eval { DELETE FROM x1 } 65 populate_rbu_db 66 67 sqlite3rbu rbu test.db rbu.db 68 rbu step 69 rbu step 70 rbu close 71 72 forcecopy test.db-oal test.db-wal 73 sqlite3rbu rbu test.db rbu.db 74 rbu step 75 list [catch { rbu close } msg] $msg 76 } {1 {SQLITE_ERROR - cannot update wal mode database}} 77 78 #------------------------------------------------------------------------- 79 # Test the effect of a wal file appearing after the target database has 80 # been opened, but before it has been locked. 81 # 82 catch { db close } 83 testvfs tvfs -default 1 84 85 for {set N 1} {$N < 10} {incr N} { 86 reset_db 87 populate_rbu_db 88 do_execsql_test 2.$N.0 { 89 CREATE TABLE x1(a, b, c INTEGER PRIMARY KEY); 90 } 91 92 set nAccessCnt 0 93 do_test 2.$N.1 { 94 sqlite3rbu rbu test.db rbu.db 95 rbu step 96 rbu step 97 rbu close 98 } {SQLITE_OK} 99 100 tvfs script xAccess 101 tvfs filter xAccess 102 set nAccessCnt 0 103 proc xAccess {method file args} { 104 global nAccessCnt 105 if {[file tail $file]=="test.db-wal"} { 106 incr nAccessCnt -1 107 if {$nAccessCnt==0} { 108 set fd [open test.db-wal w] 109 puts -nonewline $fd [string repeat 0 2000] 110 close $fd 111 } 112 } 113 return SQLITE_OK 114 } 115 116 foreach r { 117 {1 {SQLITE_ERROR - cannot update wal mode database}} 118 {0 SQLITE_OK} 119 {1 {SQLITE_CANTOPEN - unable to open database file}} 120 } { 121 set RES($r) 1 122 } 123 do_test 2.$N.2 { 124 set ::nAccessCnt $N 125 set res [list [catch { 126 sqlite3rbu rbu test.db rbu.db 127 rbu step 128 rbu close 129 } msg ] $msg] 130 set RES($res) 131 } {1} 132 catch {rbu close} 133 } 134 catch {db close} 135 catch {tvfs delete} 136 137 #------------------------------------------------------------------------- 138 testvfs tvfs -default 1 139 reset_db 140 populate_rbu_db 141 do_execsql_test 3.0 { 142 CREATE TABLE x1(a, b, c INTEGER PRIMARY KEY); 143 } 144 145 tvfs script xFileControl 146 tvfs filter xFileControl 147 148 proc xFileControl {method file verb args} { 149 if {$verb=="ZIPVFS" && [info exists ::zipvfs_filecontrol]} { 150 return $::zipvfs_filecontrol 151 } 152 return "SQLITE_NOTFOUND" 153 } 154 155 breakpoint 156 foreach {tn ret err} { 157 1 SQLITE_OK 0 158 2 SQLITE_ERROR 1 159 3 SQLITE_NOTFOUND 0 160 4 SQLITE_OMIT 1 161 } { 162 set ::zipvfs_filecontrol $ret 163 do_test 3.$tn.1 { 164 catch { 165 sqlite3rbu rbu test.db rbu.db 166 rbu step 167 rbu close 168 } 169 } $err 170 } 171 catch {db close} 172 catch {tvfs delete} 173 174 #------------------------------------------------------------------------- 175 reset_db 176 do_execsql_test 4.0 { 177 BEGIN; 178 CREATE TABLE t1 (c1 INTEGER PRIMARY KEY, 179 c2 TEXT, c3 TEXT, c4 TEXT, c5 TEXT, 180 c6 TEXT, c7 TEXT, c8 TEXT, c9 TEXT, 181 c10 TEXT, c11 TEXT, c12 TEXT, c13 TEXT, 182 c14 TEXT, c15 TEXT, c16 TEXT, c17 TEXT 183 ); 184 CREATE INDEX idx1 ON t1( 185 c1, c2, c3, c4, c5, c6, c7, c8, 186 c9, c10, c11, c12, c13, c14, c15, c16, 187 c17 188 ); 189 COMMIT; 190 } 191 192 do_test 4.1 { 193 forcedelete rbu.db 194 sqlite3 rbu rbu.db 195 rbu eval { 196 BEGIN; 197 CREATE TABLE data_t1 (c1 INTEGER, 198 c2 TEXT, c3 TEXT, c4 TEXT, c5 TEXT, 199 c6 TEXT, c7 TEXT, c8 TEXT, c9 TEXT, 200 c10 TEXT, c11 TEXT, c12 TEXT, c13 TEXT, 201 c14 TEXT, c15 TEXT, c16 TEXT, c17 TEXT, 202 rbu_control INTEGER 203 ); 204 INSERT INTO data_t1 VALUES(100,'v_c2','v_c3','v_c4','v_c5','v_c6','v_c7','v_c8','v_c9','v_c10','v_c11','v_c12','v_c13','v_c14','v_c15','v_c16','v_c17',0); 205 COMMIT; 206 } 207 rbu close 208 } {} 209 210 do_test 4.2 { 211 sqlite3rbu rbu test.db rbu.db 212 while {"SQLITE_OK"==[rbu step]} { } 213 rbu close 214 } {SQLITE_DONE} 215 216 217 # UPDATE and DELETE operations on rows written before a column 218 # with a non-NULL DEFAULT was added using ALTER TABLE ADD COLUMN. 219 # 220 foreach {tn wo def} { 221 1 "" 'EUR' 222 2 "WITHOUT ROWID" 'EUR' 223 3 "" x'00ff' 224 4 "WITHOUT ROWID" x'00ff' 225 5 "" -1.5 226 6 "WITHOUT ROWID" -1.5 227 } { 228 reset_db 229 do_execsql_test 5.$tn.0 " 230 CREATE TABLE item(id INTEGER PRIMARY KEY, name TEXT) $wo; 231 INSERT INTO item VALUES(1, 'bolt'), (2, 'nut'), (3, 'washer'); 232 ALTER TABLE item ADD COLUMN currency NOT NULL DEFAULT $def; 233 CREATE INDEX item_currency ON item(currency); 234 " 235 236 do_test 5.$tn.1 { 237 forcedelete rbu.db 238 sqlite3 rbu rbu.db 239 rbu eval { 240 CREATE TABLE data_item(id, name, currency, rbu_control); 241 INSERT INTO data_item VALUES(1, 'bolt-m8', NULL, '.x.'); 242 INSERT INTO data_item VALUES(2, NULL, NULL, 1); 243 } 244 rbu close 245 run_rbu test.db rbu.db 246 } {SQLITE_DONE} 247 248 do_execsql_test 5.$tn.2 " 249 SELECT id, name, currency IS $def FROM item; 250 " {1 bolt-m8 1 3 washer 1} 251 252 do_execsql_test 5.$tn.3 { 253 PRAGMA integrity_check; 254 } {ok} 255 256 do_execsql_test 5.$tn.4 " 257 SELECT count(*) FROM item WHERE currency = $def; 258 SELECT count(*) FROM item NOT INDEXED WHERE currency = $def; 259 " {2 2} 260 } 261 262 finish_test