Debian Codegraph @

ext/fts5/test/fts5vocab2.test

raw
1 # 2017 August 10
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 # The tests in this file focus on testing the fts5vocab module.
13 #
14
15 source [file join [file dirname [info script]] fts5_common.tcl]
16 set testprefix fts5vocab2
17
18 # If SQLITE_ENABLE_FTS5 is not defined, omit this file.
19 ifcapable !fts5 {
20 finish_test
21 return
22 }
23
24 do_execsql_test 1.0 {
25 CREATE VIRTUAL TABLE t1 USING fts5(a, b);
26 CREATE VIRTUAL TABLE v1 USING fts5vocab(t1, instance);
27
28 INSERT INTO t1 VALUES('one two', 'two three');
29 INSERT INTO t1 VALUES('three four', 'four five five five');
30 }
31
32 do_execsql_test 1.1 {
33 SELECT * FROM v1;
34 } {
35 five 2 b 1
36 five 2 b 2
37 five 2 b 3
38 four 2 a 1
39 four 2 b 0
40 one 1 a 0
41 three 1 b 1
42 three 2 a 0
43 two 1 a 1
44 two 1 b 0
45 }
46
47 do_execsql_test 1.2 {
48 SELECT * FROM v1 WHERE term='three';
49 } {
50 three 1 b 1
51 three 2 a 0
52 }
53
54 do_execsql_test 1.3 {
55 BEGIN;
56 DELETE FROM t1 WHERE rowid=2;
57 SELECT * FROM v1;
58 ROLLBACK;
59 } {
60 one 1 a 0
61 three 1 b 1
62 two 1 a 1
63 two 1 b 0
64 }
65
66 do_execsql_test 1.4 {
67 BEGIN;
68 DELETE FROM t1 WHERE rowid=1;
69 SELECT * FROM v1;
70 ROLLBACK;
71 } {
72 five 2 b 1
73 five 2 b 2
74 five 2 b 3
75 four 2 a 1
76 four 2 b 0
77 three 2 a 0
78 }
79
80 do_execsql_test 1.5 {
81 DELETE FROM t1;
82 SELECT * FROM v1;
83 } {}
84
85 #-------------------------------------------------------------------------
86 #
87 do_execsql_test 2.0 {
88 DROP TABLE IF EXISTS t1;
89 DROP TABLE IF EXISTS v1;
90
91 CREATE VIRTUAL TABLE t1 USING fts5(a, b, detail=column);
92 CREATE VIRTUAL TABLE v1 USING fts5vocab(t1, instance);
93
94 INSERT INTO t1 VALUES('one two', 'two three');
95 INSERT INTO t1 VALUES('three four', 'four five five five');
96 }
97
98 do_execsql_test 2.1 {
99 SELECT * FROM v1;
100 } {
101 five 2 b {}
102 four 2 a {}
103 four 2 b {}
104 one 1 a {}
105 three 1 b {}
106 three 2 a {}
107 two 1 a {}
108 two 1 b {}
109 }
110
111 do_execsql_test 2.2 {
112 SELECT * FROM v1 WHERE term='three';
113 } {
114 three 1 b {}
115 three 2 a {}
116 }
117
118 do_execsql_test 2.3 {
119 BEGIN;
120 DELETE FROM t1 WHERE rowid=2;
121 SELECT * FROM v1;
122 ROLLBACK;
123 } {
124 one 1 a {}
125 three 1 b {}
126 two 1 a {}
127 two 1 b {}
128 }
129
130 do_execsql_test 2.4 {
131 BEGIN;
132 DELETE FROM t1 WHERE rowid=1;
133 SELECT * FROM v1;
134 ROLLBACK;
135 } {
136 five 2 b {}
137 four 2 a {}
138 four 2 b {}
139 three 2 a {}
140 }
141
142 do_execsql_test 2.5 {
143 DELETE FROM t1;
144 SELECT * FROM v1;
145 } {}
146
147 #-------------------------------------------------------------------------
148 #
149 do_execsql_test 3.0 {
150 DROP TABLE IF EXISTS t1;
151 DROP TABLE IF EXISTS v1;
152
153 CREATE VIRTUAL TABLE t1 USING fts5(a, b, detail=none);
154 CREATE VIRTUAL TABLE v1 USING fts5vocab(t1, instance);
155
156 INSERT INTO t1 VALUES('one two', 'two three');
157 INSERT INTO t1 VALUES('three four', 'four five five five');
158 }
159
160 do_execsql_test 3.1 {
161 SELECT * FROM v1;
162 } {
163 five 2 {} {}
164 four 2 {} {}
165 one 1 {} {}
166 three 1 {} {}
167 three 2 {} {}
168 two 1 {} {}
169 }
170
171 do_execsql_test 3.2 {
172 SELECT * FROM v1 WHERE term='three';
173 } {
174 three 1 {} {}
175 three 2 {} {}
176 }
177
178 do_execsql_test 3.3 {
179 BEGIN;
180 DELETE FROM t1 WHERE rowid=2;
181 SELECT * FROM v1;
182 ROLLBACK;
183 } {
184 one 1 {} {}
185 three 1 {} {}
186 two 1 {} {}
187 }
188
189 do_execsql_test 3.4 {
190 BEGIN;
191 DELETE FROM t1 WHERE rowid=1;
192 SELECT * FROM v1;
193 ROLLBACK;
194 } {
195 five 2 {} {}
196 four 2 {} {}
197 three 2 {} {}
198 }
199
200 do_execsql_test 3.5 {
201 DELETE FROM t1;
202 SELECT * FROM v1;
203 } {}
204
205 #-------------------------------------------------------------------------
206 #
207 reset_db
208 do_execsql_test 4.0 {
209 CREATE VIRTUAL TABLE v1 USING fts5vocab(nosuchtable, col);
210 }
211
212 do_catchsql_test 4.1 {
213 SELECT * FROM v1 WHERE term=='nosuchterm';
214 } {1 {no such fts5 table: main.nosuchtable}}
215
216 do_execsql_test 4.2.1 {
217 CREATE TABLE nosuchtable(nosuchtable, y, z);
218 }
219 do_catchsql_test 4.2.2 {
220 SELECT * FROM v1 WHERE term=='nosuchterm';
221 } {1 {no such fts5 table: main.nosuchtable}}
222
223 ifcapable fts3 {
224 do_execsql_test 4.3.1 {
225 DROP TABLE nosuchtable;
226 CREATE VIRTUAL TABLE nosuchtable USING fts3(a, b);
227 } {}
228 do_catchsql_test 4.3.2 {
229 SELECT * FROM v1 WHERE term=='nosuchterm';
230 } {1 {no such fts5 table: main.nosuchtable}}
231 do_catchsql_test 4.3.3 {
232 INSERT INTO nosuchtable VALUES('id', '*id');
233 SELECT * FROM v1 WHERE term=='nosuchterm';
234 } {1 {no such fts5 table: main.nosuchtable}}
235 }
236
237 #-------------------------------------------------------------------------
238 # Check that the fts5 table cannot be written while there are vocab
239 # cursors open.
240 reset_db
241 do_execsql_test 5.0 {
242 CREATE VIRTUAL TABLE t1 USING fts5(a);
243 CREATE VIRTUAL TABLE v1 USING fts5vocab(t1, instance);
244 INSERT INTO t1 VALUES('one'), ('two'), ('three'), ('four');
245 }
246
247 do_test 5.1 {
248 list [catch {
249 db eval { SELECT * FROM v1 } {
250 db eval {INSERT INTO t1 VALUES('five')}
251 }
252 } msg] $msg
253 } {1 {query aborted}}
254
255 do_execsql_test 5.2 {
256 SELECT * FROM t1
257 } {one two three four five}
258
259 #-------------------------------------------------------------------------
260 # Check that the fts5 table cannot be written while there are vocab
261 # cursors open.
262 reset_db
263 do_execsql_test 5.0 {
264 CREATE VIRTUAL TABLE t1 USING fts5(a);
265 CREATE VIRTUAL TABLE v1 USING fts5vocab(t1, instance);
266 WITH s(i) AS (
267 VALUES(1) UNION ALL SELECT i+1 FROM s WHERE i<10000
268 )
269 INSERT INTO t1 SELECT
270 'State Emergency Service (SES), Rural Fire Service (RFS) and Volunteers'
271 FROM s;
272 }
273
274 do_catchsql_test 5.1 {
275 INSERT INTO t1 SELECT rowid FROM v1
276 } {1 {query aborted}}
277
278 do_catchsql_test 5.2 {
279 DELETE FROM t1 WHERE rowid>100;
280 INSERT INTO t1 SELECT randomblob(3000) FROM v1
281 } {1 {query aborted}}
282
283 #-------------------------------------------------------------------------
284 reset_db
285 sqlite3_fts5_may_be_corrupt 1
286
287 do_execsql_test 6.0 {
288 BEGIN TRANSACTION;
289 CREATE VIRTUAL TABLE t1 USING fts5(a,b unindexed,c,tokenize="porter ascii",tokendata=1);
290 REPLACE INTO t1_data VALUES(1,X'03090009');
291 REPLACE INTO t1_data VALUES(10,X'000000000103030003010101020101030101');
292 REPLACE INTO t1_data VALUES(137438953473,X'0000002e023061010202010162010203010163010204010167010601020201016801060102030101690106010204040606060808');
293 REPLACE INTO t1_data VALUES(274877906945,X'0000001f013067020802010202010168020803010203010169020804010204040909');
294 REPLACE INTO t1_data VALUES(412316860417,X'0000002e023061030202010162030203010163030204010167030601020201016803060102030101690306010204040606060808');
295 COMMIT;
296 }
297
298 do_execsql_test 6.1 {
299 CREATE VIRTUAL TABLE t3 USING fts5vocab('t1', 'row');
300 }
301
302 do_catchsql_test 6.2 {
303 SELECT * FROM t3;
304 } {1 {database disk image is malformed}}
305
306 sqlite3_fts5_may_be_corrupt 0
307
308 #-------------------------------------------------------------------------
309 reset_db
310 do_execsql_test 7.0 {
311 CREATE VIRTUAL TABLE t1 USING fts5(a, b);
312 CREATE VIRTUAL TABLE v1 USING fts5vocab(t1, col);
313
314 INSERT INTO t1 VALUES('xx', 'xx');
315
316 CREATE TABLE x1(t);
317 INSERT INTO x1 VALUES('xx');
318 INSERT INTO x1 VALUES('xx');
319
320 SELECT term, col FROM v1;
321 } {
322 xx a xx b
323 }
324
325 do_execsql_test 7.1 {
326 SELECT * FROM x1 WHERE 'a'=(SELECT col FROM v1 WHERE term=t)
327 } {xx xx}
328
329
330 finish_test
331
332