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 or missing database}}
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 or missing database}}
161 set scan(littleEndian) i*
162 set scan(bigEndian) I*
163 binary scan $blob $scan($::tcl_platform(byteOrder)) r
168 faultsim_delete_and_reopen
169 execsql { CREATE VIRTUAL TABLE t8 USING fts4 }
170 execsql "INSERT INTO t8 VALUES('a b c')"
171 execsql "INSERT INTO t8 VALUES('b b b')"
172 execsql "INSERT INTO t8 VALUES('[string repeat {c } 50000]')"
173 execsql "INSERT INTO t8 VALUES('d d d')"
174 execsql "INSERT INTO t8 VALUES('e e e')"
175 execsql "INSERT INTO t8(t8) VALUES('optimize')"
176 faultsim_save_and_close
179 do_faultsim_test 8.1 -prep {
180 faultsim_restore_and_reopen
183 execsql { SELECT mit(matchinfo(t8, 'x')) FROM t8 WHERE t8 MATCH 'a b c' }
185 faultsim_test_result {0 {{1 1 1 1 4 2 1 5 5}}}
187 do_faultsim_test 8.2 -faults oom-t* -prep {
188 faultsim_restore_and_reopen
191 execsql { SELECT mit(matchinfo(t8, 's')) FROM t8 WHERE t8 MATCH 'a b c' }
193 faultsim_test_result {0 3}
195 do_faultsim_test 8.3 -prep {
196 faultsim_restore_and_reopen
199 execsql { SELECT mit(matchinfo(t8, 'a')) FROM t8 WHERE t8 MATCH 'a b c' }
201 faultsim_test_result {0 10002}
203 do_faultsim_test 8.4 -prep {
204 faultsim_restore_and_reopen
207 execsql { SELECT mit(matchinfo(t8, 'l')) FROM t8 WHERE t8 MATCH 'a b c' }
209 faultsim_test_result {0 3}
213 faultsim_delete_and_reopen
215 CREATE VIRTUAL TABLE t9 USING fts4(tokenize=porter);
216 INSERT INTO t9 VALUES(
217 'this record is used toooooooooooooooooooooooooooooooooooooo try to'
219 SELECT offsets(t9) FROM t9 WHERE t9 MATCH 'to*';
221 faultsim_save_and_close
223 do_faultsim_test 9.1 -prep {
224 faultsim_restore_and_reopen
226 execsql { SELECT offsets(t9) FROM t9 WHERE t9 MATCH 'to*' }
228 faultsim_test_result {0 {{0 0 20 39 0 0 64 2}}}