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