github.com/jdgcs/sqlite3@v1.12.1-0.20210908114423-bc5f96e4dd51/testdata/tcl/fts3fault.test (about) 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 set testdir [file dirname $argv0] 14 source $testdir/tester.tcl 15 16 set ::testprefix fts3fault 17 18 # If SQLITE_ENABLE_FTS3 is not defined, omit this file. 19 ifcapable !fts3 { finish_test ; return } 20 21 # Test error handling in the sqlite3Fts3Init() function. This is the 22 # function that registers the FTS3 module and various support functions 23 # with SQLite. 24 # 25 do_faultsim_test 1 -body { 26 sqlite3 db test.db 27 expr 0 28 } -test { 29 catch { db close } 30 } 31 32 # Test error handling in an "ALTER TABLE ... RENAME TO" statement on an 33 # FTS3 table. Specifically, test renaming the table within a transaction 34 # after it has been written to. 35 # 36 faultsim_delete_and_reopen 37 do_execsql_test 2.0 { 38 CREATE VIRTUAL TABLE t1 USING fts3; 39 INSERT INTO t1 VALUES('test renaming the table'); 40 INSERT INTO t1 VALUES(' after it has been written'); 41 } 42 do_faultsim_test 2 -prep { 43 sqlite3 db test.db 44 execsql { 45 BEGIN; 46 INSERT INTO t1 VALUES('registers the FTS3 module'); 47 INSERT INTO t1 VALUES('various support functions'); 48 } 49 } -body { 50 execsql { ALTER TABLE t1 RENAME TO t2 } 51 } -test { 52 faultsim_test_result {0 {}} 53 } 54 55 # Test error handling in the special case where a single prefix query 56 # matches terms that reside on a large range of leaf nodes. 57 # 58 do_test fts3fault-3.0 { 59 sqlite3 db test.db 60 execsql { CREATE VIRTUAL TABLE t3 USING fts4; } 61 execsql { INSERT INTO t3(t3) VALUES('nodesize=50') } 62 execsql { BEGIN } 63 for {set i 0} {$i < 1000} {incr i} { 64 execsql { INSERT INTO t3 VALUES('aaa' || $i) } 65 } 66 execsql { COMMIT } 67 } {} 68 69 do_faultsim_test 3 -faults oom-transient -prep { 70 sqlite3 db test.db 71 execsql { SELECT * FROM t3 WHERE t3 MATCH 'x' } 72 } -body { 73 execsql { SELECT count(rowid) FROM t3 WHERE t3 MATCH 'aa*' } 74 } -test { 75 faultsim_test_result {0 1000} 76 } 77 78 do_test fts3fault-4.0 { 79 faultsim_delete_and_reopen 80 execsql { 81 CREATE VIRTUAL TABLE t4 USING fts4; 82 INSERT INTO t4 VALUES('The British Government called on'); 83 INSERT INTO t4 VALUES('as pesetas then became much'); 84 } 85 } {} 86 faultsim_save_and_close 87 do_faultsim_test 4 -prep { 88 faultsim_restore_and_reopen 89 execsql { SELECT content FROM t4 } 90 } -body { 91 execsql { SELECT optimize(t4) FROM t4 LIMIT 1 } 92 } -test { 93 faultsim_test_result {0 {{Index optimized}}} 94 } 95 96 do_test fts3fault-5.0 { 97 faultsim_delete_and_reopen 98 execsql { 99 CREATE VIRTUAL TABLE t5 USING fts4; 100 INSERT INTO t5 VALUES('The British Government called on'); 101 INSERT INTO t5 VALUES('as pesetas then became much'); 102 } 103 } {} 104 faultsim_save_and_close 105 do_faultsim_test 5 -prep { 106 faultsim_restore_and_reopen 107 execsql { 108 BEGIN; 109 INSERT INTO t5 VALUES('influential in shaping his future outlook'); 110 INSERT INTO t5 VALUES('might be acceptable to the British electorate'); 111 } 112 } -body { 113 execsql { SELECT rowid FROM t5 WHERE t5 MATCH 'british' } 114 } -test { 115 faultsim_test_result {0 {1 4}} 116 } 117 118 do_test fts3fault-6.0 { 119 faultsim_delete_and_reopen 120 execsql { CREATE VIRTUAL TABLE t6 USING fts4 } 121 } {} 122 faultsim_save_and_close 123 do_faultsim_test 6 -prep { 124 faultsim_restore_and_reopen 125 execsql { SELECT rowid FROM t6 } 126 } -body { 127 execsql { DROP TABLE t6 } 128 } -test { 129 faultsim_test_result {0 {}} 130 } 131 132 # Test various malloc failures while processing FTS4 parameters. 133 # 134 do_faultsim_test 7.1 -prep { 135 faultsim_delete_and_reopen 136 } -body { 137 execsql { CREATE VIRTUAL TABLE t1 USING fts4(a, b, matchinfo=fts3) } 138 } -test { 139 faultsim_test_result {0 {}} 140 } 141 do_faultsim_test 7.2 -prep { 142 faultsim_delete_and_reopen 143 } -body { 144 execsql { CREATE VIRTUAL TABLE t1 USING fts4(a, b, matchinfo=fs3) } 145 } -test { 146 faultsim_test_result {1 {unrecognized matchinfo: fs3}} \ 147 {1 {vtable constructor failed: t1}} \ 148 {1 {SQL logic error}} 149 } 150 do_faultsim_test 7.3 -prep { 151 faultsim_delete_and_reopen 152 } -body { 153 execsql { CREATE VIRTUAL TABLE t1 USING fts4(a, b, matchnfo=fts3) } 154 } -test { 155 faultsim_test_result {1 {unrecognized parameter: matchnfo=fts3}} \ 156 {1 {vtable constructor failed: t1}} \ 157 {1 {SQL logic error}} 158 } 159 160 161 proc mit {blob} { 162 set scan(littleEndian) i* 163 set scan(bigEndian) I* 164 binary scan $blob $scan($::tcl_platform(byteOrder)) r 165 return $r 166 } 167 168 do_test 8.0 { 169 faultsim_delete_and_reopen 170 execsql { CREATE VIRTUAL TABLE t8 USING fts4 } 171 execsql "INSERT INTO t8 VALUES('a b c')" 172 execsql "INSERT INTO t8 VALUES('b b b')" 173 execsql "INSERT INTO t8 VALUES('[string repeat {c } 50000]')" 174 execsql "INSERT INTO t8 VALUES('d d d')" 175 execsql "INSERT INTO t8 VALUES('e e e')" 176 execsql "INSERT INTO t8(t8) VALUES('optimize')" 177 faultsim_save_and_close 178 } {} 179 180 ifcapable fts4_deferred { 181 do_faultsim_test 8.1 -faults oom-t* -prep { 182 faultsim_restore_and_reopen 183 db func mit mit 184 } -body { 185 execsql { SELECT mit(matchinfo(t8, 'x')) FROM t8 WHERE t8 MATCH 'a b c' } 186 } -test { 187 faultsim_test_result {0 {{1 1 1 1 4 2 1 5 5}}} 188 } 189 } 190 191 do_faultsim_test 8.2 -faults oom-t* -prep { 192 faultsim_restore_and_reopen 193 db func mit mit 194 } -body { 195 execsql { SELECT mit(matchinfo(t8, 's')) FROM t8 WHERE t8 MATCH 'a b c' } 196 } -test { 197 faultsim_test_result {0 3} 198 } 199 do_faultsim_test 8.3 -prep { 200 faultsim_restore_and_reopen 201 db func mit mit 202 } -body { 203 execsql { SELECT mit(matchinfo(t8, 'a')) FROM t8 WHERE t8 MATCH 'a b c' } 204 } -test { 205 faultsim_test_result {0 10002} 206 } 207 do_faultsim_test 8.4 -prep { 208 faultsim_restore_and_reopen 209 db func mit mit 210 } -body { 211 execsql { SELECT mit(matchinfo(t8, 'l')) FROM t8 WHERE t8 MATCH 'a b c' } 212 } -test { 213 faultsim_test_result {0 3} 214 } 215 216 do_test 9.0 { 217 faultsim_delete_and_reopen 218 execsql { 219 CREATE VIRTUAL TABLE t9 USING fts4(tokenize=porter); 220 INSERT INTO t9 VALUES( 221 'this record is used toooooooooooooooooooooooooooooooooooooo try to' 222 ); 223 SELECT offsets(t9) FROM t9 WHERE t9 MATCH 'to*'; 224 } 225 faultsim_save_and_close 226 } {} 227 do_faultsim_test 9.1 -prep { 228 faultsim_restore_and_reopen 229 } -body { 230 execsql { SELECT offsets(t9) FROM t9 WHERE t9 MATCH 'to*' } 231 } -test { 232 faultsim_test_result {0 {{0 0 20 39 0 0 64 2}}} 233 } 234 235 do_faultsim_test 10.1 -prep { 236 faultsim_delete_and_reopen 237 } -body { 238 execsql { CREATE VIRTUAL TABLE t1 USING fts4(a, b, languageid=d) } 239 } -test { 240 faultsim_test_result {0 {}} 241 } 242 243 #------------------------------------------------------------------------- 244 reset_db 245 do_execsql_test 11.0 { 246 CREATE VIRTUAL TABLE t1 USING fts3(a, b); 247 } 248 faultsim_save_and_close 249 250 do_faultsim_test 11 -faults oom* -prep { 251 faultsim_restore_and_reopen 252 } -body { 253 execsql { DROP TABLE t1 } 254 } -test { 255 faultsim_test_result {0 {}} 256 } 257 258 259 finish_test