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 # Test error handling in the sqlite3Fts3Init() function. This is the
22 # function that registers the FTS3 module and various support functions
25 do_faultsim_test 1 -body {
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.
36 faultsim_delete_and_reopen
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');
42 do_faultsim_test 2 -prep {
46 INSERT INTO t1 VALUES('registers the FTS3 module');
47 INSERT INTO t1 VALUES('various support functions');
50 execsql { ALTER TABLE t1 RENAME TO t2 }
52 faultsim_test_result {0 {}}
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.
58 do_test fts3fault-3.0 {
60 execsql { CREATE VIRTUAL TABLE t3 USING fts4; }
61 execsql { INSERT INTO t3(t3) VALUES('nodesize=50') }
63 for {set i 0} {$i < 1000} {incr i} {
64 execsql { INSERT INTO t3 VALUES('aaa' || $i) }
69 do_faultsim_test 3 -faults oom-transient -prep {
71 execsql { SELECT * FROM t3 WHERE t3 MATCH 'x' }
73 execsql { SELECT count(rowid) FROM t3 WHERE t3 MATCH 'aa*' }
75 faultsim_test_result {0 1000}
78 do_test fts3fault-4.0 {
79 faultsim_delete_and_reopen
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');
86 faultsim_save_and_close
87 do_faultsim_test 4 -prep {
88 faultsim_restore_and_reopen
89 execsql { SELECT content FROM t4 }
91 execsql { SELECT optimize(t4) FROM t4 LIMIT 1 }
93 faultsim_test_result {0 {{Index optimized}}}
96 do_test fts3fault-5.0 {
97 faultsim_delete_and_reopen
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');
104 faultsim_save_and_close
105 do_faultsim_test 5 -prep {
106 faultsim_restore_and_reopen
109 INSERT INTO t5 VALUES('influential in shaping his future outlook');
110 INSERT INTO t5 VALUES('might be acceptable to the British electorate');
113 execsql { SELECT rowid FROM t5 WHERE t5 MATCH 'british' }
115 faultsim_test_result {0 {1 4}}
118 do_test fts3fault-6.0 {
119 faultsim_delete_and_reopen
120 execsql { CREATE VIRTUAL TABLE t6 USING fts4 }
122 faultsim_save_and_close
123 do_faultsim_test 6 -prep {
124 faultsim_restore_and_reopen
125 execsql { SELECT rowid FROM t6 }
127 execsql { DROP TABLE t6 }
129 faultsim_test_result {0 {}}
132 # Test various malloc failures while processing FTS4 parameters.
134 do_faultsim_test 7.1 -prep {
135 faultsim_delete_and_reopen
137 execsql { CREATE VIRTUAL TABLE t1 USING fts4(a, b, matchinfo=fts3) }
139 faultsim_test_result {0 {}}
141 do_faultsim_test 7.2 -prep {
142 faultsim_delete_and_reopen
144 execsql { CREATE VIRTUAL TABLE t1 USING fts4(a, b, matchinfo=fs3) }
146 faultsim_test_result {1 {unrecognized matchinfo: fs3}} \
147 {1 {vtable constructor failed: t1}} \
148 {1 {SQL logic error}}
150 do_faultsim_test 7.3 -prep {
151 faultsim_delete_and_reopen
153 execsql { CREATE VIRTUAL TABLE t1 USING fts4(a, b, matchnfo=fts3) }
155 faultsim_test_result {1 {unrecognized parameter: matchnfo=fts3}} \
156 {1 {vtable constructor failed: t1}} \
157 {1 {SQL logic error}}
162 set scan(littleEndian) i*
163 set scan(bigEndian) I*
164 binary scan $blob $scan($::tcl_platform(byteOrder)) r
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
180 ifcapable fts4_deferred {
181 do_faultsim_test 8.1 -faults oom-t* -prep {
182 faultsim_restore_and_reopen
185 execsql { SELECT mit(matchinfo(t8, 'x')) FROM t8 WHERE t8 MATCH 'a b c' }
187 faultsim_test_result {0 {{1 1 1 1 4 2 1 5 5}}}
191 do_faultsim_test 8.2 -faults oom-t* -prep {
192 faultsim_restore_and_reopen
195 execsql { SELECT mit(matchinfo(t8, 's')) FROM t8 WHERE t8 MATCH 'a b c' }
197 faultsim_test_result {0 3}
199 do_faultsim_test 8.3 -prep {
200 faultsim_restore_and_reopen
203 execsql { SELECT mit(matchinfo(t8, 'a')) FROM t8 WHERE t8 MATCH 'a b c' }
205 faultsim_test_result {0 10002}
207 do_faultsim_test 8.4 -prep {
208 faultsim_restore_and_reopen
211 execsql { SELECT mit(matchinfo(t8, 'l')) FROM t8 WHERE t8 MATCH 'a b c' }
213 faultsim_test_result {0 3}
217 faultsim_delete_and_reopen
219 CREATE VIRTUAL TABLE t9 USING fts4(tokenize=porter);
220 INSERT INTO t9 VALUES(
221 'this record is used toooooooooooooooooooooooooooooooooooooo try to'
223 SELECT offsets(t9) FROM t9 WHERE t9 MATCH 'to*';
225 faultsim_save_and_close
227 do_faultsim_test 9.1 -prep {
228 faultsim_restore_and_reopen
230 execsql { SELECT offsets(t9) FROM t9 WHERE t9 MATCH 'to*' }
232 faultsim_test_result {0 {{0 0 20 39 0 0 64 2}}}
235 do_faultsim_test 10.1 -prep {
236 faultsim_delete_and_reopen
238 execsql { CREATE VIRTUAL TABLE t1 USING fts4(a, b, languageid=d) }
240 faultsim_test_result {0 {}}