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 }
23 # Test error handling in the sqlite3Fts3Init() function. This is the
24 # function that registers the FTS3 module and various support functions
27 do_faultsim_test 1 -body {
34 # Test error handling in an "ALTER TABLE ... RENAME TO" statement on an
35 # FTS3 table. Specifically, test renaming the table within a transaction
36 # after it has been written to.
38 faultsim_delete_and_reopen
40 CREATE VIRTUAL TABLE t1 USING fts3;
41 INSERT INTO t1 VALUES('test renaming the table');
42 INSERT INTO t1 VALUES(' after it has been written');
44 do_faultsim_test 2 -prep {
48 INSERT INTO t1 VALUES('registers the FTS3 module');
49 INSERT INTO t1 VALUES('various support functions');
52 execsql { ALTER TABLE t1 RENAME TO t2 }
54 faultsim_test_result {0 {}}
57 # Test error handling in the special case where a single prefix query
58 # matches terms that reside on a large range of leaf nodes.
60 do_test fts3fault-3.0 {
62 execsql { CREATE VIRTUAL TABLE t3 USING fts4; }
63 execsql { INSERT INTO t3(t3) VALUES('nodesize=50') }
65 for {set i 0} {$i < 1000} {incr i} {
66 execsql { INSERT INTO t3 VALUES('aaa' || $i) }
71 do_faultsim_test 3 -faults oom-transient -prep {
73 execsql { SELECT * FROM t3 WHERE t3 MATCH 'x' }
75 execsql { SELECT count(rowid) FROM t3 WHERE t3 MATCH 'aa*' }
77 faultsim_test_result {0 1000}
80 do_test fts3fault-4.0 {
81 faultsim_delete_and_reopen
83 CREATE VIRTUAL TABLE t4 USING fts4;
84 INSERT INTO t4 VALUES('The British Government called on');
85 INSERT INTO t4 VALUES('as pesetas then became much');
88 faultsim_save_and_close
89 do_faultsim_test 4 -prep {
90 faultsim_restore_and_reopen
91 execsql { SELECT content FROM t4 }
93 execsql { SELECT optimize(t4) FROM t4 LIMIT 1 }
95 faultsim_test_result {0 {{Index optimized}}}
98 do_test fts3fault-5.0 {
99 faultsim_delete_and_reopen
101 CREATE VIRTUAL TABLE t5 USING fts4;
102 INSERT INTO t5 VALUES('The British Government called on');
103 INSERT INTO t5 VALUES('as pesetas then became much');
106 faultsim_save_and_close
107 do_faultsim_test 5 -prep {
108 faultsim_restore_and_reopen
111 INSERT INTO t5 VALUES('influential in shaping his future outlook');
112 INSERT INTO t5 VALUES('might be acceptable to the British electorate');
115 execsql { SELECT rowid FROM t5 WHERE t5 MATCH 'british' }
117 faultsim_test_result {0 {1 4}}
120 do_test fts3fault-6.0 {
121 faultsim_delete_and_reopen
122 execsql { CREATE VIRTUAL TABLE t6 USING fts4 }
124 faultsim_save_and_close
125 do_faultsim_test 6 -prep {
126 faultsim_restore_and_reopen
127 execsql { SELECT rowid FROM t6 }
129 execsql { DROP TABLE t6 }
131 faultsim_test_result {0 {}}
134 # Test various malloc failures while processing FTS4 parameters.
136 do_faultsim_test 7.1 -prep {
137 faultsim_delete_and_reopen
139 execsql { CREATE VIRTUAL TABLE t1 USING fts4(a, b, matchinfo=fts3) }
141 faultsim_test_result {0 {}}
143 do_faultsim_test 7.2 -prep {
144 faultsim_delete_and_reopen
146 execsql { CREATE VIRTUAL TABLE t1 USING fts4(a, b, matchinfo=fs3) }
148 faultsim_test_result {1 {unrecognized matchinfo: fs3}} \
149 {1 {vtable constructor failed: t1}} \
150 {1 {SQL logic error or missing database}}
152 do_faultsim_test 7.3 -prep {
153 faultsim_delete_and_reopen
155 execsql { CREATE VIRTUAL TABLE t1 USING fts4(a, b, matchnfo=fts3) }
157 faultsim_test_result {1 {unrecognized parameter: matchnfo=fts3}} \
158 {1 {vtable constructor failed: t1}} \
159 {1 {SQL logic error or missing database}}
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 do_faultsim_test 8.1 -faults oom-t* -prep {
185 faultsim_restore_and_reopen
188 execsql { SELECT mit(matchinfo(t8, 'x')) FROM t8 WHERE t8 MATCH 'a b c' }
190 faultsim_test_result {0 {{1 1 1 1 4 2 1 5 5}}}
193 do_faultsim_test 8.2 -faults oom-t* -prep {
194 faultsim_restore_and_reopen
197 execsql { SELECT mit(matchinfo(t8, 's')) FROM t8 WHERE t8 MATCH 'a b c' }
199 faultsim_test_result {0 3}
201 do_faultsim_test 8.3 -prep {
202 faultsim_restore_and_reopen
205 execsql { SELECT mit(matchinfo(t8, 'a')) FROM t8 WHERE t8 MATCH 'a b c' }
207 faultsim_test_result {0 10002}
209 do_faultsim_test 8.4 -prep {
210 faultsim_restore_and_reopen
213 execsql { SELECT mit(matchinfo(t8, 'l')) FROM t8 WHERE t8 MATCH 'a b c' }
215 faultsim_test_result {0 3}
219 faultsim_delete_and_reopen
221 CREATE VIRTUAL TABLE t9 USING fts4(tokenize=porter);
222 INSERT INTO t9 VALUES(
223 'this record is used toooooooooooooooooooooooooooooooooooooo try to'
225 SELECT offsets(t9) FROM t9 WHERE t9 MATCH 'to*';
227 faultsim_save_and_close
229 do_faultsim_test 9.1 -prep {
230 faultsim_restore_and_reopen
232 execsql { SELECT offsets(t9) FROM t9 WHERE t9 MATCH 'to*' }
234 faultsim_test_result {0 {{0 0 20 39 0 0 64 2}}}