blob: 21defd282fd406c5fc7d1e4616da3982d08599df [file] [log] [blame]
dane25ac092010-10-25 19:01:25 +00001# 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
13set testdir [file dirname $argv0]
14source $testdir/tester.tcl
15
16set ::testprefix fts3fault
17
danacf19872010-11-11 11:43:01 +000018# If SQLITE_ENABLE_FTS3 is not defined, omit this file.
19ifcapable !fts3 { finish_test ; return }
20
danf703b422022-07-11 21:40:34 +000021set ::TMPDBERROR [list 1 \
22 {unable to open a temporary database file for storing temporary tables}
23]
24
dane25ac092010-10-25 19:01:25 +000025# 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#
29do_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#
40faultsim_delete_and_reopen
41do_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}
46do_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 {
danf703b422022-07-11 21:40:34 +000056 faultsim_test_result {0 {}} $::TMPDBERROR
dane25ac092010-10-25 19:01:25 +000057}
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#
62do_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
73do_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
82do_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} {}
90faultsim_save_and_close
91do_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
100do_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} {}
108faultsim_save_and_close
109do_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
122do_test fts3fault-6.0 {
123 faultsim_delete_and_reopen
124 execsql { CREATE VIRTUAL TABLE t6 USING fts4 }
125} {}
126faultsim_save_and_close
127do_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
danaf4c2142010-11-02 17:41:52 +0000136# Test various malloc failures while processing FTS4 parameters.
137#
138do_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}
145do_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}} \
dan9fc160c2011-10-31 06:52:51 +0000151 {1 {vtable constructor failed: t1}} \
drha690ff32017-07-07 19:43:23 +0000152 {1 {SQL logic error}}
danaf4c2142010-11-02 17:41:52 +0000153}
154do_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}} \
dan9fc160c2011-10-31 06:52:51 +0000160 {1 {vtable constructor failed: t1}} \
drha690ff32017-07-07 19:43:23 +0000161 {1 {SQL logic error}}
danc2f16cb2010-11-25 17:49:28 +0000162}
163
dana90579d2015-07-08 17:59:08 +0000164
danc2f16cb2010-11-25 17:49:28 +0000165proc 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
172do_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
dan7b458512017-05-10 13:36:04 +0000184ifcapable 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 }
danc2f16cb2010-11-25 17:49:28 +0000193}
dana90579d2015-07-08 17:59:08 +0000194
danc2f16cb2010-11-25 17:49:28 +0000195do_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 {
danf703b422022-07-11 21:40:34 +0000201 faultsim_test_result {0 3} $::TMPDBERROR
danc2f16cb2010-11-25 17:49:28 +0000202}
203do_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}
211do_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
220do_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} {}
231do_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
danddf47472017-04-17 13:38:09 +0000239do_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
dan12937152019-01-21 17:57:31 +0000247#-------------------------------------------------------------------------
248reset_db
249do_execsql_test 11.0 {
250 CREATE VIRTUAL TABLE t1 USING fts3(a, b);
251}
252faultsim_save_and_close
253
254do_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
dane25ac092010-10-25 19:01:25 +0000263finish_test