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 # The tests in this file focus on testing the fts5vocab module.
15 source [file join [file dirname [info script]] fts5_common.tcl]
16 set testprefix fts5vocab2
18 # If SQLITE_ENABLE_FTS5 is defined, omit this file.
25 CREATE VIRTUAL TABLE t1 USING fts5(a, b);
26 CREATE VIRTUAL TABLE v1 USING fts5vocab(t1, instance);
28 INSERT INTO t1 VALUES('one two', 'two three');
29 INSERT INTO t1 VALUES('three four', 'four five five five');
48 SELECT * FROM v1 WHERE term='three';
56 DELETE FROM t1 WHERE rowid=2;
68 DELETE FROM t1 WHERE rowid=1;
85 #-------------------------------------------------------------------------
88 DROP TABLE IF EXISTS t1;
89 DROP TABLE IF EXISTS v1;
91 CREATE VIRTUAL TABLE t1 USING fts5(a, b, detail=column);
92 CREATE VIRTUAL TABLE v1 USING fts5vocab(t1, instance);
94 INSERT INTO t1 VALUES('one two', 'two three');
95 INSERT INTO t1 VALUES('three four', 'four five five five');
111 do_execsql_test 2.2 {
112 SELECT * FROM v1 WHERE term='three';
118 do_execsql_test 2.3 {
120 DELETE FROM t1 WHERE rowid=2;
130 do_execsql_test 2.4 {
132 DELETE FROM t1 WHERE rowid=1;
142 do_execsql_test 2.5 {
147 #-------------------------------------------------------------------------
149 do_execsql_test 3.0 {
150 DROP TABLE IF EXISTS t1;
151 DROP TABLE IF EXISTS v1;
153 CREATE VIRTUAL TABLE t1 USING fts5(a, b, detail=none);
154 CREATE VIRTUAL TABLE v1 USING fts5vocab(t1, instance);
156 INSERT INTO t1 VALUES('one two', 'two three');
157 INSERT INTO t1 VALUES('three four', 'four five five five');
160 do_execsql_test 3.1 {
171 do_execsql_test 3.2 {
172 SELECT * FROM v1 WHERE term='three';
178 do_execsql_test 3.3 {
180 DELETE FROM t1 WHERE rowid=2;
189 do_execsql_test 3.4 {
191 DELETE FROM t1 WHERE rowid=1;
200 do_execsql_test 3.5 {
205 #-------------------------------------------------------------------------
208 do_execsql_test 4.0 {
209 CREATE VIRTUAL TABLE v1 USING fts5vocab(nosuchtable, col);
212 do_catchsql_test 4.1 {
213 SELECT * FROM v1 WHERE term=='nosuchterm';
214 } {1 {no such fts5 table: main.nosuchtable}}
216 do_execsql_test 4.2.1 {
217 CREATE TABLE nosuchtable(nosuchtable, y, z);
219 do_catchsql_test 4.2.2 {
220 SELECT * FROM v1 WHERE term=='nosuchterm';
221 } {1 {no such fts5 table: main.nosuchtable}}
224 do_execsql_test 4.3.1 {
225 DROP TABLE nosuchtable;
226 CREATE VIRTUAL TABLE nosuchtable USING fts3(a, b);
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}}
237 #-------------------------------------------------------------------------
238 # Check that the fts5 table cannot be written while there are vocab
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');
249 db eval { SELECT * FROM v1 } {
250 db eval {INSERT INTO t1 VALUES('five')}
253 } {1 {query aborted}}
255 do_execsql_test 5.2 {
257 } {one two three four five}
259 #-------------------------------------------------------------------------
260 # Check that the fts5 table cannot be written while there are vocab
263 do_execsql_test 5.0 {
264 CREATE VIRTUAL TABLE t1 USING fts5(a);
265 CREATE VIRTUAL TABLE v1 USING fts5vocab(t1, instance);
267 VALUES(1) UNION ALL SELECT i+1 FROM s WHERE i<10000
269 INSERT INTO t1 SELECT
270 'State Emergency Service (SES), Rural Fire Service (RFS) and Volunteers'
274 do_catchsql_test 5.1 {
275 INSERT INTO t1 SELECT rowid FROM v1
276 } {1 {query aborted}}
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}}
283 #-------------------------------------------------------------------------
285 sqlite3_fts5_may_be_corrupt 1
287 do_execsql_test 6.0 {
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');
298 do_execsql_test 6.1 {
299 CREATE VIRTUAL TABLE t3 USING fts5vocab('t1', 'row');
302 do_catchsql_test 6.2 {
304 } {1 {database disk image is malformed}}
306 sqlite3_fts5_may_be_corrupt 0