3 # The author disclaims copyright to this source code. In place of
4 # a legal notice, here is a blessing:
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.
10 #***********************************************************************
13 set testdir [file dirname $argv0]
14 source $testdir/tester.tcl
16 set ::testprefix fts3fault
18 # If SQLITE_ENABLE_FTS3 is not defined, omit this file.
19 ifcapable !fts3 { finish_test ; return }
21 set ::TMPDBERROR [list 1 \
22 {unable to open a temporary database file for storing temporary tables}
25 # Test error handling in the sqlite3Fts3Init() function. This is the
26 # function that registers the FTS3 module and various support functions
29 do_faultsim_test 1 -body {
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.
40 faultsim_delete_and_reopen
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');
46 do_faultsim_test 2 -prep {
50 INSERT INTO t1 VALUES('registers the FTS3 module');
51 INSERT INTO t1 VALUES('various support functions');
54 execsql { ALTER TABLE t1 RENAME TO t2 }
56 faultsim_test_result {0 {}} $::TMPDBERROR
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.
62 do_test fts3fault-3.0 {
64 execsql { CREATE VIRTUAL TABLE t3 USING fts4; }
65 execsql { INSERT INTO t3(t3) VALUES('nodesize=50') }
67 for {set i 0} {$i < 1000} {incr i} {
68 execsql { INSERT INTO t3 VALUES('aaa' || $i) }
73 do_faultsim_test 3 -faults oom-transient -prep {
75 execsql { SELECT * FROM t3 WHERE t3 MATCH 'x' }
77 execsql { SELECT count(rowid) FROM t3 WHERE t3 MATCH 'aa*' }
79 faultsim_test_result {0 1000}
82 do_test fts3fault-4.0 {
83 faultsim_delete_and_reopen
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');
90 faultsim_save_and_close
91 do_faultsim_test 4 -prep {
92 faultsim_restore_and_reopen
93 execsql { SELECT content FROM t4 }
95 execsql { SELECT optimize(t4) FROM t4 LIMIT 1 }
97 faultsim_test_result {0 {{Index optimized}}}
100 do_test fts3fault-5.0 {
101 faultsim_delete_and_reopen
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');
108 faultsim_save_and_close
109 do_faultsim_test 5 -prep {
110 faultsim_restore_and_reopen
113 INSERT INTO t5 VALUES('influential in shaping his future outlook');
114 INSERT INTO t5 VALUES('might be acceptable to the British electorate');
117 execsql { SELECT rowid FROM t5 WHERE t5 MATCH 'british' }
119 faultsim_test_result {0 {1 4}}
122 do_test fts3fault-6.0 {
123 faultsim_delete_and_reopen
124 execsql { CREATE VIRTUAL TABLE t6 USING fts4 }
126 faultsim_save_and_close
127 do_faultsim_test 6 -prep {
128 faultsim_restore_and_reopen
129 execsql { SELECT rowid FROM t6 }
131 execsql { DROP TABLE t6 }
133 faultsim_test_result {0 {}}
136 # Test various malloc failures while processing FTS4 parameters.
138 do_faultsim_test 7.1 -prep {
139 faultsim_delete_and_reopen
141 execsql { CREATE VIRTUAL TABLE t1 USING fts4(a, b, matchinfo=fts3) }
143 faultsim_test_result {0 {}}
145 do_faultsim_test 7.2 -prep {
146 faultsim_delete_and_reopen
148 execsql { CREATE VIRTUAL TABLE t1 USING fts4(a, b, matchinfo=fs3) }
150 faultsim_test_result {1 {unrecognized matchinfo: fs3}} \
151 {1 {vtable constructor failed: t1}} \
152 {1 {SQL logic error}}
154 do_faultsim_test 7.3 -prep {
155 faultsim_delete_and_reopen
157 execsql { CREATE VIRTUAL TABLE t1 USING fts4(a, b, matchnfo=fts3) }
159 faultsim_test_result {1 {unrecognized parameter: matchnfo=fts3}} \
160 {1 {vtable constructor failed: t1}} \
161 {1 {SQL logic error}}
166 set scan(littleEndian) i*
167 set scan(bigEndian) I*
168 binary scan $blob $scan($::tcl_platform(byteOrder)) r
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
184 ifcapable fts4_deferred {
185 do_faultsim_test 8.1 -faults oom-t* -prep {
186 faultsim_restore_and_reopen
189 execsql { SELECT mit(matchinfo(t8, 'x')) FROM t8 WHERE t8 MATCH 'a b c' }
191 faultsim_test_result {0 {{1 1 1 1 4 2 1 5 5}}}
195 do_faultsim_test 8.2 -faults oom-t* -prep {
196 faultsim_restore_and_reopen
199 execsql { SELECT mit(matchinfo(t8, 's')) FROM t8 WHERE t8 MATCH 'a b c' }
201 faultsim_test_result {0 3} $::TMPDBERROR
203 do_faultsim_test 8.3 -prep {
204 faultsim_restore_and_reopen
207 execsql { SELECT mit(matchinfo(t8, 'a')) FROM t8 WHERE t8 MATCH 'a b c' }
209 faultsim_test_result {0 10002}
211 do_faultsim_test 8.4 -prep {
212 faultsim_restore_and_reopen
215 execsql { SELECT mit(matchinfo(t8, 'l')) FROM t8 WHERE t8 MATCH 'a b c' }
217 faultsim_test_result {0 3}
221 faultsim_delete_and_reopen
223 CREATE VIRTUAL TABLE t9 USING fts4(tokenize=porter);
224 INSERT INTO t9 VALUES(
225 'this record is used toooooooooooooooooooooooooooooooooooooo try to'
227 SELECT offsets(t9) FROM t9 WHERE t9 MATCH 'to*';
229 faultsim_save_and_close
231 do_faultsim_test 9.1 -prep {
232 faultsim_restore_and_reopen
234 execsql { SELECT offsets(t9) FROM t9 WHERE t9 MATCH 'to*' }
236 faultsim_test_result {0 {{0 0 20 39 0 0 64 2}}}
239 do_faultsim_test 10.1 -prep {
240 faultsim_delete_and_reopen
242 execsql { CREATE VIRTUAL TABLE t1 USING fts4(a, b, languageid=d) }
244 faultsim_test_result {0 {}}
247 #-------------------------------------------------------------------------
249 do_execsql_test 11.0 {
250 CREATE VIRTUAL TABLE t1 USING fts3(a, b);
252 faultsim_save_and_close
254 do_faultsim_test 11 -faults oom* -prep {
255 faultsim_restore_and_reopen
257 execsql { DROP TABLE t1 }
259 faultsim_test_result {0 {}}