123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311 |
- # 2017 August 10
- #
- # The author disclaims copyright to this source code. In place of
- # a legal notice, here is a blessing:
- #
- # May you do good and not evil.
- # May you find forgiveness for yourself and forgive others.
- # May you share freely, never taking more than you give.
- #
- #***********************************************************************
- #
- # The tests in this file focus on testing the fts5vocab module.
- #
- source [file join [file dirname [info script]] fts5_common.tcl]
- set testprefix fts5vocab2
- # If SQLITE_ENABLE_FTS5 is not defined, omit this file.
- ifcapable !fts5 {
- finish_test
- return
- }
- do_execsql_test 1.0 {
- CREATE VIRTUAL TABLE t1 USING fts5(a, b);
- CREATE VIRTUAL TABLE v1 USING fts5vocab(t1, instance);
- INSERT INTO t1 VALUES('one two', 'two three');
- INSERT INTO t1 VALUES('three four', 'four five five five');
- }
- do_execsql_test 1.1 {
- SELECT * FROM v1;
- } {
- five 2 b 1
- five 2 b 2
- five 2 b 3
- four 2 a 1
- four 2 b 0
- one 1 a 0
- three 1 b 1
- three 2 a 0
- two 1 a 1
- two 1 b 0
- }
- do_execsql_test 1.2 {
- SELECT * FROM v1 WHERE term='three';
- } {
- three 1 b 1
- three 2 a 0
- }
- do_execsql_test 1.3 {
- BEGIN;
- DELETE FROM t1 WHERE rowid=2;
- SELECT * FROM v1;
- ROLLBACK;
- } {
- one 1 a 0
- three 1 b 1
- two 1 a 1
- two 1 b 0
- }
- do_execsql_test 1.4 {
- BEGIN;
- DELETE FROM t1 WHERE rowid=1;
- SELECT * FROM v1;
- ROLLBACK;
- } {
- five 2 b 1
- five 2 b 2
- five 2 b 3
- four 2 a 1
- four 2 b 0
- three 2 a 0
- }
- do_execsql_test 1.5 {
- DELETE FROM t1;
- SELECT * FROM v1;
- } {}
- #-------------------------------------------------------------------------
- #
- do_execsql_test 2.0 {
- DROP TABLE IF EXISTS t1;
- DROP TABLE IF EXISTS v1;
- CREATE VIRTUAL TABLE t1 USING fts5(a, b, detail=column);
- CREATE VIRTUAL TABLE v1 USING fts5vocab(t1, instance);
- INSERT INTO t1 VALUES('one two', 'two three');
- INSERT INTO t1 VALUES('three four', 'four five five five');
- }
- do_execsql_test 2.1 {
- SELECT * FROM v1;
- } {
- five 2 b {}
- four 2 a {}
- four 2 b {}
- one 1 a {}
- three 1 b {}
- three 2 a {}
- two 1 a {}
- two 1 b {}
- }
- do_execsql_test 2.2 {
- SELECT * FROM v1 WHERE term='three';
- } {
- three 1 b {}
- three 2 a {}
- }
- do_execsql_test 2.3 {
- BEGIN;
- DELETE FROM t1 WHERE rowid=2;
- SELECT * FROM v1;
- ROLLBACK;
- } {
- one 1 a {}
- three 1 b {}
- two 1 a {}
- two 1 b {}
- }
- do_execsql_test 2.4 {
- BEGIN;
- DELETE FROM t1 WHERE rowid=1;
- SELECT * FROM v1;
- ROLLBACK;
- } {
- five 2 b {}
- four 2 a {}
- four 2 b {}
- three 2 a {}
- }
- do_execsql_test 2.5 {
- DELETE FROM t1;
- SELECT * FROM v1;
- } {}
- #-------------------------------------------------------------------------
- #
- do_execsql_test 3.0 {
- DROP TABLE IF EXISTS t1;
- DROP TABLE IF EXISTS v1;
- CREATE VIRTUAL TABLE t1 USING fts5(a, b, detail=none);
- CREATE VIRTUAL TABLE v1 USING fts5vocab(t1, instance);
- INSERT INTO t1 VALUES('one two', 'two three');
- INSERT INTO t1 VALUES('three four', 'four five five five');
- }
- do_execsql_test 3.1 {
- SELECT * FROM v1;
- } {
- five 2 {} {}
- four 2 {} {}
- one 1 {} {}
- three 1 {} {}
- three 2 {} {}
- two 1 {} {}
- }
- do_execsql_test 3.2 {
- SELECT * FROM v1 WHERE term='three';
- } {
- three 1 {} {}
- three 2 {} {}
- }
- do_execsql_test 3.3 {
- BEGIN;
- DELETE FROM t1 WHERE rowid=2;
- SELECT * FROM v1;
- ROLLBACK;
- } {
- one 1 {} {}
- three 1 {} {}
- two 1 {} {}
- }
- do_execsql_test 3.4 {
- BEGIN;
- DELETE FROM t1 WHERE rowid=1;
- SELECT * FROM v1;
- ROLLBACK;
- } {
- five 2 {} {}
- four 2 {} {}
- three 2 {} {}
- }
- do_execsql_test 3.5 {
- DELETE FROM t1;
- SELECT * FROM v1;
- } {}
- #-------------------------------------------------------------------------
- #
- reset_db
- do_execsql_test 4.0 {
- CREATE VIRTUAL TABLE v1 USING fts5vocab(nosuchtable, col);
- }
- do_catchsql_test 4.1 {
- SELECT * FROM v1 WHERE term=='nosuchterm';
- } {1 {no such fts5 table: main.nosuchtable}}
- do_execsql_test 4.2.1 {
- CREATE TABLE nosuchtable(nosuchtable, y, z);
- }
- do_catchsql_test 4.2.2 {
- SELECT * FROM v1 WHERE term=='nosuchterm';
- } {1 {no such fts5 table: main.nosuchtable}}
- ifcapable fts3 {
- do_execsql_test 4.3.1 {
- DROP TABLE nosuchtable;
- CREATE VIRTUAL TABLE nosuchtable USING fts3(a, b);
- } {}
- do_catchsql_test 4.3.2 {
- SELECT * FROM v1 WHERE term=='nosuchterm';
- } {1 {no such fts5 table: main.nosuchtable}}
- do_catchsql_test 4.3.3 {
- INSERT INTO nosuchtable VALUES('id', '*id');
- SELECT * FROM v1 WHERE term=='nosuchterm';
- } {1 {no such fts5 table: main.nosuchtable}}
- }
- #-------------------------------------------------------------------------
- # Check that the fts5 table cannot be written while there are vocab
- # cursors open.
- reset_db
- do_execsql_test 5.0 {
- CREATE VIRTUAL TABLE t1 USING fts5(a);
- CREATE VIRTUAL TABLE v1 USING fts5vocab(t1, instance);
- INSERT INTO t1 VALUES('one'), ('two'), ('three'), ('four');
- }
- do_test 5.1 {
- list [catch {
- db eval { SELECT * FROM v1 } {
- db eval {INSERT INTO t1 VALUES('five')}
- }
- } msg] $msg
- } {1 {query aborted}}
- do_execsql_test 5.2 {
- SELECT * FROM t1
- } {one two three four five}
- #-------------------------------------------------------------------------
- # Check that the fts5 table cannot be written while there are vocab
- # cursors open.
- reset_db
- do_execsql_test 5.0 {
- CREATE VIRTUAL TABLE t1 USING fts5(a);
- CREATE VIRTUAL TABLE v1 USING fts5vocab(t1, instance);
- WITH s(i) AS (
- VALUES(1) UNION ALL SELECT i+1 FROM s WHERE i<10000
- )
- INSERT INTO t1 SELECT
- 'State Emergency Service (SES), Rural Fire Service (RFS) and Volunteers'
- FROM s;
- }
- do_catchsql_test 5.1 {
- INSERT INTO t1 SELECT rowid FROM v1
- } {1 {query aborted}}
- do_catchsql_test 5.2 {
- DELETE FROM t1 WHERE rowid>100;
- INSERT INTO t1 SELECT randomblob(3000) FROM v1
- } {1 {query aborted}}
- #-------------------------------------------------------------------------
- reset_db
- sqlite3_fts5_may_be_corrupt 1
- do_execsql_test 6.0 {
- BEGIN TRANSACTION;
- CREATE VIRTUAL TABLE t1 USING fts5(a,b unindexed,c,tokenize="porter ascii",tokendata=1);
- REPLACE INTO t1_data VALUES(1,X'03090009');
- REPLACE INTO t1_data VALUES(10,X'000000000103030003010101020101030101');
- REPLACE INTO t1_data VALUES(137438953473,X'0000002e023061010202010162010203010163010204010167010601020201016801060102030101690106010204040606060808');
- REPLACE INTO t1_data VALUES(274877906945,X'0000001f013067020802010202010168020803010203010169020804010204040909');
- REPLACE INTO t1_data VALUES(412316860417,X'0000002e023061030202010162030203010163030204010167030601020201016803060102030101690306010204040606060808');
- COMMIT;
- }
- do_execsql_test 6.1 {
- CREATE VIRTUAL TABLE t3 USING fts5vocab('t1', 'row');
- }
- do_catchsql_test 6.2 {
- SELECT * FROM t3;
- } {1 {database disk image is malformed}}
- sqlite3_fts5_may_be_corrupt 0
- finish_test
|