summaryrefslogtreecommitdiffstats
path: root/ext/fts5/test/fts5vocab2.test
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-13 14:07:11 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-13 14:07:11 +0000
commit63847496f14c813a5d80efd5b7de0f1294ffe1e3 (patch)
tree01c7571c7c762ceee70638549a99834fdd7c411b /ext/fts5/test/fts5vocab2.test
parentInitial commit. (diff)
downloadsqlite3-63847496f14c813a5d80efd5b7de0f1294ffe1e3.tar.xz
sqlite3-63847496f14c813a5d80efd5b7de0f1294ffe1e3.zip
Adding upstream version 3.45.1.upstream/3.45.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'ext/fts5/test/fts5vocab2.test')
-rw-r--r--ext/fts5/test/fts5vocab2.test310
1 files changed, 310 insertions, 0 deletions
diff --git a/ext/fts5/test/fts5vocab2.test b/ext/fts5/test/fts5vocab2.test
new file mode 100644
index 0000000..ecacc50
--- /dev/null
+++ b/ext/fts5/test/fts5vocab2.test
@@ -0,0 +1,310 @@
+# 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 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
+
+