blob: 913f9baa0583a9fb4b54336ccbd2f534ff58f677 [file] [log] [blame]
dan16690ed2011-02-03 10:56:00 +00001# 2011 February 3
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
15set ::testprefix fts3fault2
16
dan60939d02011-03-29 15:40:55 +000017# If SQLITE_ENABLE_FTS3 is not defined, omit this file.
18ifcapable !fts3 { finish_test ; return }
19
dan16690ed2011-02-03 10:56:00 +000020do_test 1.0 {
21 execsql {
22 CREATE VIRTUAL TABLE t1 USING fts4(x);
23 INSERT INTO t1 VALUES('a b c');
24 INSERT INTO t1 VALUES('c d e');
25 CREATE VIRTUAL TABLE terms USING fts4aux(t1);
26 }
27 faultsim_save_and_close
28} {}
29
30do_faultsim_test 1.1 -prep {
31 faultsim_restore_and_reopen
32 db eval {SELECT * FROM sqlite_master}
33} -body {
34 execsql "CREATE VIRTUAL TABLE terms2 USING fts4aux(t1)"
35} -test {
36 faultsim_test_result {0 {}}
37}
38
39do_faultsim_test 1.2 -prep {
40 faultsim_restore_and_reopen
41 db eval {SELECT * FROM sqlite_master}
42} -body {
43 execsql "SELECT * FROM terms"
44} -test {
danbb7e77c2011-02-05 14:37:57 +000045 faultsim_test_result {0 {a * 1 1 a 0 1 1 b * 1 1 b 0 1 1 c * 2 2 c 0 2 2 d * 1 1 d 0 1 1 e * 1 1 e 0 1 1}}
dan16690ed2011-02-03 10:56:00 +000046}
47
48do_faultsim_test 1.3 -prep {
49 faultsim_restore_and_reopen
50 db eval {SELECT * FROM sqlite_master}
51} -body {
52 execsql "SELECT * FROM terms WHERE term>'a' AND TERM < 'd'"
53} -test {
danbb7e77c2011-02-05 14:37:57 +000054 faultsim_test_result {0 {b * 1 1 b 0 1 1 c * 2 2 c 0 2 2}}
dan16690ed2011-02-03 10:56:00 +000055}
56
57do_faultsim_test 1.4 -prep {
58 faultsim_restore_and_reopen
59 db eval {SELECT * FROM sqlite_master}
60} -body {
61 execsql "SELECT * FROM terms WHERE term='c'"
62} -test {
danbb7e77c2011-02-05 14:37:57 +000063 faultsim_test_result {0 {c * 2 2 c 0 2 2}}
dan16690ed2011-02-03 10:56:00 +000064}
65
danbb7e77c2011-02-05 14:37:57 +000066do_test 2.0 {
67 faultsim_delete_and_reopen
68 execsql {
69 CREATE VIRTUAL TABLE tx USING fts4(a, b);
70 INSERT INTO tx VALUES('a b c', 'x y z');
71 CREATE VIRTUAL TABLE terms2 USING fts4aux(tx);
72 }
73 faultsim_save_and_close
74} {}
dan16690ed2011-02-03 10:56:00 +000075
danbb7e77c2011-02-05 14:37:57 +000076do_faultsim_test 2.1 -prep {
77 faultsim_restore_and_reopen
78 db eval {SELECT * FROM sqlite_master}
79} -body {
80 execsql "SELECT * FROM terms2"
81} -test {
82 faultsim_test_result {0 {a * 1 1 a 0 1 1 b * 1 1 b 0 1 1 c * 1 1 c 0 1 1 x * 1 1 x 1 1 1 y * 1 1 y 1 1 1 z * 1 1 z 1 1 1}}
83}
dan16690ed2011-02-03 10:56:00 +000084
dan49fc3362011-10-04 19:41:50 +000085do_faultsim_test 3.0 -faults oom* -prep {
86 faultsim_delete_and_reopen
87 db eval { CREATE TABLE 'xx yy'(a, b); }
88} -body {
89 execsql {
90 CREATE VIRTUAL TABLE tt USING fts4(content="xx yy");
91 }
92} -test {
93 faultsim_test_result {0 {}}
94}
95
96do_faultsim_test 3.1 -faults oom* -prep {
97 faultsim_delete_and_reopen
98 db func zip zip
99 db func unzip unzip
100} -body {
101 execsql {
102 CREATE VIRTUAL TABLE tt USING fts4(compress=zip, uncompress=unzip);
103 }
104} -test {
105 faultsim_test_result {0 {}}
106}
107
dan8361b182011-10-05 06:07:00 +0000108do_test 4.0 {
109 faultsim_delete_and_reopen
110 execsql {
111 CREATE VIRTUAL TABLE ft USING fts4(a, b);
112 INSERT INTO ft VALUES('U U T C O', 'F N D E S');
113 INSERT INTO ft VALUES('P H X G B', 'I D M R U');
114 INSERT INTO ft VALUES('P P X D M', 'Y V N T C');
115 INSERT INTO ft VALUES('Z L Q O W', 'D F U N Q');
116 INSERT INTO ft VALUES('A J D U P', 'C H M Q E');
117 INSERT INTO ft VALUES('P S A O H', 'S Z C W D');
118 INSERT INTO ft VALUES('T B N L W', 'C A K T I');
119 INSERT INTO ft VALUES('K E Z L O', 'L L Y C E');
120 INSERT INTO ft VALUES('C R E S V', 'Q V F W P');
121 INSERT INTO ft VALUES('S K H G W', 'R W Q F G');
122 }
123 faultsim_save_and_close
124} {}
125do_faultsim_test 4.1 -prep {
126 faultsim_restore_and_reopen
127 db eval {SELECT * FROM sqlite_master}
128} -body {
129 execsql { INSERT INTO ft(ft) VALUES('rebuild') }
130} -test {
131 faultsim_test_result {0 {}}
132}
133
dan7946c532012-05-26 18:28:14 +0000134ifcapable fts3_unicode {
135 do_test 5.0 {
136 faultsim_delete_and_reopen
137 execsql {
138 CREATE VIRTUAL TABLE ft USING fts4(a, tokenize=unicode61);
139 }
140 faultsim_save_and_close
141 } {}
142
143 do_faultsim_test 5.1 -faults oom* -prep {
144 faultsim_restore_and_reopen
145 db eval {SELECT * FROM sqlite_master}
146 } -body {
147 execsql { INSERT INTO ft VALUES('the quick brown fox'); }
148 execsql { INSERT INTO ft VALUES(
149 'theunusuallylongtokenthatjustdragsonandonandonandthendragsonsomemoreeof'
150 );
151 }
152 execsql { SELECT docid FROM ft WHERE ft MATCH 'th*' }
153 } -test {
154 faultsim_test_result {0 {1 2}}
dancf9f6f12012-05-26 15:44:08 +0000155 }
dancf9f6f12012-05-26 15:44:08 +0000156}
157
dane3cdbad2015-04-06 11:04:51 +0000158reset_db
159do_test 6.0 {
160 execsql {
161 CREATE VIRTUAL TABLE t6 USING fts4(x,order=DESC);
162 INSERT INTO t6(docid, x) VALUES(-1,'a b');
163 INSERT INTO t6(docid, x) VALUES(1, 'b');
164 }
165 faultsim_save_and_close
166} {}
167
168do_faultsim_test 6.1 -faults oom* -prep {
169 faultsim_restore_and_reopen
170 db eval {SELECT * FROM sqlite_master}
171} -body {
172 execsql { SELECT docid FROM t6 WHERE t6 MATCH '"a* b"' }
173} -test {
174 faultsim_test_result {0 -1}
175}
176
dan624edac2017-04-17 16:07:25 +0000177#-------------------------------------------------------------------------
178# Inject faults into a query for an N-byte prefix that uses a prefix=N+1
179# index.
180reset_db
181do_execsql_test 7.0 {
182 CREATE VIRTUAL TABLE t7 USING fts4(x,prefix=2);
183 INSERT INTO t7 VALUES('the quick brown fox');
184 INSERT INTO t7 VALUES('jumped over the');
185 INSERT INTO t7 VALUES('lazy dog');
186}
187do_faultsim_test 7.1 -faults oom* -body {
188 execsql { SELECT docid FROM t7 WHERE t7 MATCH 't*' }
189} -test {
190 faultsim_test_result {0 {1 2}}
191}
192
dana059e992017-04-19 07:33:52 +0000193#-------------------------------------------------------------------------
194# Inject faults into a opening an existing fts3 table that has been
195# upgraded to add an %_stat table.
196#
197reset_db
198do_execsql_test 8.0 {
199 CREATE VIRTUAL TABLE t8 USING fts3;
200 INSERT INTO t8 VALUES('the quick brown fox');
201 INSERT INTO t8 VALUES('jumped over the');
202 INSERT INTO t8 VALUES('lazy dog');
203 INSERT INTO t8(t8) VALUES('automerge=8');
204 SELECT name FROM sqlite_master WHERE name LIKE 't8%';
205} {
206 t8 t8_content t8_segments t8_segdir t8_stat
207}
208faultsim_save_and_close
209
210do_faultsim_test 8.1 -faults oom* -prep {
211 faultsim_restore_and_reopen
212} -body {
213 execsql { INSERT INTO t8 VALUES('one two three') }
214} -test {
215 faultsim_test_result {0 {}}
216}
217
dan03437f72022-07-12 15:17:50 +0000218set ::TMPDBERROR [list 1 \
219 {unable to open a temporary database file for storing temporary tables}
220]
dana059e992017-04-19 07:33:52 +0000221do_faultsim_test 8.2 -faults oom* -prep {
222 faultsim_restore_and_reopen
223} -body {
224 execsql { ALTER TABLE t8 RENAME TO t8ii }
225} -test {
dan03437f72022-07-12 15:17:50 +0000226 faultsim_test_result {0 {}} $::TMPDBERROR
dana059e992017-04-19 07:33:52 +0000227}
228
229#-------------------------------------------------------------------------
230reset_db
231set chunkconfig [fts3_configure_incr_load 1 1]
232do_execsql_test 9.0 {
233 PRAGMA page_size = 512;
234 CREATE VIRTUAL TABLE t9 USING fts3;
235 WITH s(i) AS (
236 SELECT 1 UNION ALL SELECT i+1 FROM s WHERE i<50
237 )
238 INSERT INTO t9 SELECT 'one two three' FROM s;
239}
240
241do_faultsim_test 8.2 -faults io* -body {
242 execsql { SELECT count(*) FROM t9 WHERE t9 MATCH '"one two three"' }
243} -test {
244 faultsim_test_result {0 50}
245}
246
247eval fts3_configure_incr_load $chunkconfig
248
249
dan16690ed2011-02-03 10:56:00 +0000250finish_test