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/fts5/test/fts5faultI.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 / fts5 / test / fts5faultI.test` 349 lines ยท 7894 bytes Raw Blame History 1 # 2010 June 15 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]] fts5_common.tcl] 14 source $testdir/malloc_common.tcl 15 set testprefix fts5faultI 16 17 # If SQLITE_ENABLE_FTS5 is not defined, omit this file. 18 ifcapable !fts5 { 19 finish_test 20 return 21 } 22 23 set ::testprefix fts5faultI 24 25 do_execsql_test 1.0 { 26 PRAGMA encoding = utf16; 27 CREATE VIRTUAL TABLE t1 USING fts5(x, locale=1); 28 INSERT INTO t1 VALUES('origintext unicode61 ascii porter trigram'); 29 } 30 31 faultsim_save_and_close 32 faultsim_restore_and_reopen 33 34 do_faultsim_test 1 -faults oom* -prep { 35 } -body { 36 execsql { 37 SELECT rowid FROM t1(fts5_locale('en_US', 'origintext')); 38 } 39 } -test { 40 faultsim_test_result {0 1} 41 } 42 43 do_faultsim_test 2 -faults oom* -prep { 44 faultsim_restore_and_reopen 45 execsql { 46 SELECT * FROM t1('ascii'); 47 } 48 } -body { 49 execsql { 50 UPDATE t1 SET rowid=rowid+1; 51 } 52 } -test { 53 faultsim_test_result {0 {}} 54 } 55 56 fts5_aux_test_functions db 57 do_faultsim_test 3 -faults oom* -prep { 58 } -body { 59 execsql { 60 SELECT fts5_columnlocale(t1, 0) FROM t1('unicode*'); 61 } 62 } -test { 63 faultsim_test_result {0 {{}}} {1 SQLITE_NOMEM} 64 } 65 66 #------------------------------------------------------------------------- 67 reset_db 68 do_execsql_test 4.0 { 69 CREATE VIRTUAL TABLE w1 USING fts5(a); 70 } 71 faultsim_save_and_close 72 73 do_faultsim_test 4 -faults oom* -prep { 74 faultsim_restore_and_reopen 75 execsql { 76 BEGIN; 77 INSERT INTO w1 VALUES('token token token'); 78 } 79 } -body { 80 execsql { 81 INSERT INTO w1(w1, rank) VALUES('rank', 'bm25()'); 82 } 83 } -test { 84 faultsim_test_result {0 {}} 85 } 86 87 do_faultsim_test 5 -faults oom* -prep { 88 faultsim_restore_and_reopen 89 execsql { 90 BEGIN; 91 INSERT INTO w1 VALUES('one'); 92 SAVEPOINT one; 93 INSERT INTO w1 VALUES('two'); 94 ROLLBACK TO one; 95 } 96 97 } -body { 98 execsql { 99 INSERT INTO w1 VALUES('string'); 100 } 101 } -test { 102 faultsim_test_result {0 {}} 103 } 104 105 #------------------------------------------------------------------------- 106 reset_db 107 do_execsql_test 5.0 { 108 CREATE VIRTUAL TABLE w1 USING fts5(a); 109 INSERT INTO w1 VALUES('one two three'); 110 } 111 fts5_aux_test_functions db 112 113 do_faultsim_test 5 -faults oom* -prep { 114 } -body { 115 execsql { 116 SELECT fts5_test_insttoken(w1, 0, 0) FROM w1('two'); 117 } 118 } -test { 119 faultsim_test_result {0 two} {1 SQLITE_NOMEM} 120 } 121 122 #------------------------------------------------------------------------- 123 reset_db 124 do_execsql_test 6.0 { 125 CREATE VIRTUAL TABLE w1 USING fts5(a); 126 INSERT INTO w1 VALUES('one two three'); 127 } 128 fts5_aux_test_functions db 129 faultsim_save_and_close 130 131 do_faultsim_test 6 -faults oom* -prep { 132 faultsim_restore_and_reopen 133 db eval { 134 BEGIN; 135 INSERT INTO w1 VALUES('four five six'); 136 SAVEPOINT abc; 137 INSERT INTO w1 VALUES('seven eight nine'); 138 SAVEPOINT def; 139 INSERT INTO w1 VALUES('ten eleven twelve'); 140 } 141 } -body { 142 execsql { 143 RELEASE abc; 144 } 145 } -test { 146 faultsim_test_result {0 {}} 147 } 148 149 #------------------------------------------------------------------------- 150 reset_db 151 do_execsql_test 7.0 { 152 CREATE VIRTUAL TABLE w1 USING fts5(a); 153 INSERT INTO w1 VALUES('one two three'); 154 INSERT INTO w1 VALUES('three two one'); 155 DELETE FROM w1_content WHERE rowid=1; 156 } 157 158 faultsim_save_and_close 159 160 do_faultsim_test 7 -faults oom* -prep { 161 faultsim_restore_and_reopen 162 db eval { SELECT * FROM w1 } 163 } -body { 164 execsql { 165 PRAGMA integrity_check; 166 } 167 } -test { 168 } 169 170 #------------------------------------------------------------------------- 171 reset_db 172 fts5_tclnum_register db 173 fts5_aux_test_functions db 174 175 do_execsql_test 8.0 { 176 CREATE VIRTUAL TABLE ft USING fts5( 177 x, tokenize = "tclnum query", detail=columns 178 ); 179 INSERT INTO ft VALUES('one two three i ii iii'); 180 INSERT INTO ft VALUES('four five six iv v vi'); 181 INSERT INTO ft VALUES('eight nine ten viii ix x'); 182 } {} 183 184 do_faultsim_test 8.1 -faults oom* -prep { 185 } -body { 186 execsql { 187 SELECT fts5_test_collist (ft) FROM ft('one two'); 188 } 189 } -test { 190 faultsim_test_result {0 {{0.0 1.0}}} {1 {SQL logic error}} {1 SQLITE_NOMEM} 191 } 192 193 do_faultsim_test 8.2 -faults oom* -prep { 194 } -body { 195 execsql { 196 SELECT rowid FROM ft('one two') ORDER BY rank; 197 } 198 } -test { 199 faultsim_test_result {0 1} {1 {SQL logic error}} {1 SQLITE_NOMEM} 200 } 201 202 #------------------------------------------------------------------------- 203 reset_db 204 205 do_execsql_test 9.0 { 206 CREATE VIRTUAL TABLE ft USING fts5(x); 207 INSERT INTO ft VALUES('one two three i ii iii'); 208 INSERT INTO ft VALUES('four five six iv v vi'); 209 INSERT INTO ft VALUES('eight nine ten viii ix x'); 210 } {} 211 212 faultsim_save_and_close 213 214 do_faultsim_test 9.1 -faults oom* -prep { 215 faultsim_restore_and_reopen 216 } -body { 217 execsql { 218 UPDATE ft SET rowid=4 WHERE rowid=1 219 } 220 } -test { 221 faultsim_test_result {0 {}} 222 } 223 224 do_faultsim_test 9.2 -faults oom* -prep { 225 faultsim_restore_and_reopen 226 } -body { 227 execsql { 228 SELECT rowid FROM ft WHERE x MATCH 'one AND two AND three' 229 } 230 } -test { 231 faultsim_test_result {0 1} 232 } 233 234 #------------------------------------------------------------------------- 235 reset_db 236 237 do_execsql_test 10.0 { 238 CREATE VIRTUAL TABLE ft USING fts5(x, locale=1); 239 INSERT INTO ft VALUES(fts5_locale('hello', 'one two three i ii iii')); 240 INSERT INTO ft VALUES('four five six iv v vi'); 241 INSERT INTO ft VALUES('eight nine ten viii ix x'); 242 } {} 243 244 do_execsql_test 10.1 { 245 SELECT fts5_get_locale(ft, 0) FROM ft WHERE x MATCH 'one AND two AND three' 246 } {hello} 247 248 faultsim_save_and_close 249 do_faultsim_test 10.1 -faults oom* -prep { 250 faultsim_restore_and_reopen 251 } -body { 252 execsql { 253 SELECT fts5_get_locale(ft, 0) FROM ft WHERE x MATCH 'one AND two AND three' 254 } 255 } -test { 256 faultsim_test_result {0 hello} 257 } 258 259 breakpoint 260 faultsim_save_and_close 261 do_faultsim_test 10.2 -faults oom-t* -prep { 262 faultsim_restore_and_reopen 263 } -body { 264 execsql { 265 INSERT INTO ft VALUES(zeroblob(10000)); 266 } 267 } -test { 268 faultsim_test_result {0 {}} 269 } 270 271 #------------------------------------------------------------------------- 272 reset_db 273 274 do_execsql_test 11.0 { 275 CREATE VIRTUAL TABLE f1 USING fts5(content); 276 CREATE TABLE g1(id, content); 277 INSERT INTO g1 VALUES(30000, 'a b c'); 278 INSERT INTO g1 VALUES(40000, 'd e f'); 279 } 280 281 faultsim_save_and_close 282 283 do_faultsim_test 11 -faults oom* -prep { 284 faultsim_restore_and_reopen 285 } -body { 286 execsql { 287 INSERT INTO f1(rowid, content) SELECT id, content FROM g1; 288 } 289 } -test { 290 faultsim_test_result {0 {}} 291 } 292 293 #------------------------------------------------------------------------- 294 reset_db 295 296 ifcapable foreignkey { 297 do_execsql_test 12.0 { 298 CREATE VIRTUAL TABLE f1 USING fts5(content); 299 CREATE TABLE p1(a INTEGER PRIMARY KEY); 300 CREATE TABLE c1(b REFERENCES p1 DEFERRABLE INITIALLY DEFERRED); 301 } 302 303 faultsim_save_and_close 304 305 do_faultsim_test 12 -faults oom* -prep { 306 faultsim_restore_and_reopen 307 execsql { 308 PRAGMA foreign_keys = 1; 309 BEGIN; 310 INSERT INTO c1 VALUES(123); 311 SAVEPOINT xyz; 312 } 313 } -body { 314 execsql { 315 INSERT INTO f1 VALUES('a b c'); 316 ROLLBACK TO xyz; 317 COMMIT; 318 } 319 } -test { 320 execsql { SELECT 123 } 321 faultsim_test_result \ 322 {1 {FOREIGN KEY constraint failed}} \ 323 {1 {out of memory}} \ 324 {1 {constraint failed}} 325 } 326 } 327 328 #------------------------------------------------------------------------- 329 reset_db 330 331 do_execsql_test 13.0 { 332 CREATE VIRTUAL TABLE t1 USING fts5(a, b); 333 INSERT INTO t1 VALUES('abc def', X'123456'); 334 } 335 faultsim_save_and_close 336 337 338 do_faultsim_test 13 -faults oom* -prep { 339 faultsim_restore_and_reopen 340 } -body { 341 execsql { 342 UPDATE t1 SET a='def abc' 343 } 344 } -test { 345 faultsim_test_result {0 {}} 346 } 347 348 finish_test 349