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 #*************************************************************************
12 # This file is focused on OOM errors.
15 source [file join [file dirname [info script]] fts5_common.tcl]
16 source $testdir/malloc_common.tcl
17 set testprefix fts5fault9
19 # If SQLITE_ENABLE_FTS3 is defined, omit this file.
25 foreach_detail_mode $testprefix {
27 if {"%DETAIL%" != "none"} continue
29 fts5_aux_test_functions db
32 CREATE VIRTUAL TABLE t1 USING fts5(a, b, detail=%DETAIL%);
33 INSERT INTO t1(t1, rank) VALUES('pgsz', 32);
34 WITH seq(s) AS ( SELECT 1 UNION ALL SELECT s+1 FROM seq WHERE s<50)
35 INSERT INTO t1 SELECT 'x x x y y y', 'a b c d e f' FROM seq;
38 do_faultsim_test 1 -faults oom-* -body {
39 execsql { SELECT count(*) FROM t1('x AND y') }
41 faultsim_test_result {0 50}
45 CREATE VIRTUAL TABLE t2 USING fts5(a, b, detail=%DETAIL%);
46 INSERT INTO t2(t2, rank) VALUES('pgsz', 32);
47 INSERT INTO t2 VALUES('abc cba', 'cba abc');
48 INSERT INTO t2 VALUES('abc cba', 'cba abc');
49 INSERT INTO t2 VALUES('abc cba', 'cba abc');
51 INSERT INTO t2 VALUES('axy cyx', 'cyx axy');
52 INSERT INTO t2 VALUES('axy cyx', 'cyx axy');
53 INSERT INTO t2 VALUES('axy cyx', 'cyx axy');
56 do_faultsim_test 2 -faults oom-* -body {
57 execsql { SELECT count(*) FROM t2('a* AND c*') }
59 faultsim_test_result {0 6}
64 CREATE VIRTUAL TABLE t3 USING fts5(a, detail=%DETAIL%);
65 INSERT INTO t3 VALUES('a x x a x a a a');
66 INSERT INTO t3 VALUES('x a a x a x x x');
69 do_faultsim_test 3.1 -faults oom-* -body {
70 execsql { SELECT highlight(t3, 0, '[', ']') FROM t3('a') }
72 faultsim_test_result {0 {{[a] x x [a] x [a] [a] [a]} {x [a] [a] x [a] x x x}}}
75 do_faultsim_test 3.2 -faults oom-t* -body {
76 execsql { SELECT fts5_test_poslist2(t3) FROM t3('x') }
78 faultsim_test_result \
79 {0 {{0.0.1 0.0.2 0.0.4} {0.0.0 0.0.3 0.0.5 0.0.6 0.0.7}}} \
83 #-------------------------------------------------------------------------
84 # Test OOM injection with the xPhraseFirstColumn() API and a tokenizer
85 # uses query synonyms.
87 fts5_tclnum_register db
89 CREATE VIRTUAL TABLE t4 USING fts5(x, y, z, detail=%DETAIL%, tokenize=tclnum);
90 INSERT INTO t4 VALUES('one two three', '1 2 3', 'i ii iii');
91 INSERT INTO t4 VALUES('1 2 3', 'i ii iii', 'one two three');
92 INSERT INTO t4 VALUES('i ii iii', 'one two three', 'i ii iii');
94 INSERT INTO t4 VALUES('a1 a2 a3', 'a4 a5 a6', 'a7 a8 a9');
95 INSERT INTO t4 VALUES('b1 b2 b3', 'b4 b5 b6', 'b7 b8 b9');
96 INSERT INTO t4 VALUES('c1 c2 c3', 'c4 c5 c6', 'c7 c8 c9');
99 do_faultsim_test 4.1 -faults oom-t* -body {
100 execsql { SELECT rowid, fts5_test_collist(t4) FROM t4('2') }
102 faultsim_test_result \
103 {0 {1 {0.0 0.1 0.2} 2 {0.0 0.1 0.2} 3 {0.0 0.1 0.2}}} \
104 {1 SQLITE_NOMEM} {1 SQLITE_ERROR} {1 {SQL logic error}}
107 do_faultsim_test 4.2 -faults oom-t* -body {
108 execsql { SELECT rowid, fts5_test_collist(t4) FROM t4('a5 OR b5 OR c5') }
110 faultsim_test_result \
111 {0 {4 {0.0 0.1 0.2} 5 {1.0 1.1 1.2} 6 {2.0 2.1 2.2}}} \
112 {1 SQLITE_NOMEM} {1 SQLITE_ERROR} {1 {SQL logic error}}
116 #-------------------------------------------------------------------------
117 # An OOM within an "ORDER BY rank" query.
119 db func rnddoc fts5_rnddoc
120 do_execsql_test 5.0 {
121 CREATE VIRTUAL TABLE xx USING fts5(x, y, detail=%DETAIL%);
122 INSERT INTO xx VALUES ('def', 'abc ' || rnddoc(10));
123 INSERT INTO xx VALUES ('def', 'abc abc' || rnddoc(9));
124 INSERT INTO xx VALUES ('def', 'abc abc abc' || rnddoc(8));
126 faultsim_save_and_close
128 do_faultsim_test 5 -faults oom-* -prep {
129 faultsim_restore_and_reopen
130 execsql { SELECT * FROM xx }
132 execsql { SELECT rowid FROM xx('abc AND def') ORDER BY rank }
134 faultsim_test_result [list 0 {3 2 1}]
137 set doc [string repeat "xyz " 500]
138 do_execsql_test 6.0 {
139 CREATE VIRTUAL TABLE yy USING fts5(y, detail=%DETAIL%);
140 INSERT INTO yy(yy, rank) VALUES('pgsz', 64);
141 INSERT INTO yy VALUES ($doc);
142 INSERT INTO yy VALUES ('1 2 3');
143 INSERT INTO yy VALUES ('xyz');
144 UPDATE yy SET y = y WHERE rowid = 1;
145 UPDATE yy SET y = y WHERE rowid = 1;
146 UPDATE yy SET y = y WHERE rowid = 1;
147 UPDATE yy SET y = y WHERE rowid = 1;
150 do_faultsim_test 6 -faults oom-* -body {
151 execsql { SELECT rowid FROM yy('xyz') }
153 faultsim_test_result [list 0 {1 3}]
157 } ;# foreach_detail_mode...