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 # Tests focusing on fts5 tables with the columnsize=0 option.
15 source [file join [file dirname [info script]] fts5_common.tcl]
16 set testprefix fts5columnsize
18 # If SQLITE_ENABLE_FTS5 is defined, omit this file.
24 #-------------------------------------------------------------------------
25 # Check that the option can be parsed and that the %_docsize table is
26 # only created if it is set to true.
28 foreach {tn outcome stmt} {
29 1 0 { CREATE VIRTUAL TABLE t1 USING fts5(x, columnsize=0) }
30 2 1 { CREATE VIRTUAL TABLE t1 USING fts5(x, columnsize=1) }
31 3 0 { CREATE VIRTUAL TABLE t1 USING fts5(x, columnsize='0') }
32 4 1 { CREATE VIRTUAL TABLE t1 USING fts5(x, columnsize='1') }
33 5 2 { CREATE VIRTUAL TABLE t1 USING fts5(x, columnsize='') }
34 6 2 { CREATE VIRTUAL TABLE t1 USING fts5(x, columnsize=2) }
35 7 1 { CREATE VIRTUAL TABLE t1 USING fts5(x, columnsize=0, columnsize=1) }
36 8 1 { CREATE VIRTUAL TABLE t1 USING fts5(x) }
37 9 2 { CREATE VIRTUAL TABLE t1 USING fts5(x, columnsize=11) }
40 DROP TABLE IF EXISTS t1;
43 do_catchsql_test 1.$tn.1 $stmt {1 {malformed columnsize=... directive}}
45 do_execsql_test 1.$tn.2 $stmt
46 do_execsql_test 1.$tn.3 {
47 SELECT count(*) FROM sqlite_master WHERE name = 't1_docsize'
52 #-------------------------------------------------------------------------
53 # Run tests on a table with no %_content or %_docsize backing store.
56 CREATE VIRTUAL TABLE t2 USING fts5(x, columnsize=0, content='');
58 do_catchsql_test 2.1 {
59 INSERT INTO t2 VALUES('a b c d e f');
60 } {1 {datatype mismatch}}
62 INSERT INTO t2(rowid, x) VALUES(1, 'c d e f');
63 INSERT INTO t2(rowid, x) VALUES(2, 'c d e f g h');
64 INSERT INTO t2(rowid, x) VALUES(3, 'a b c d e f g h');
67 SELECT rowid FROM t2 WHERE t2 MATCH 'b'; SELECT '::';
68 SELECT rowid FROM t2 WHERE t2 MATCH 'e'; SELECT '::';
69 SELECT rowid FROM t2 WHERE t2 MATCH 'h';
72 INSERT INTO t2(t2, rowid, x) VALUES('delete', 2, 'c d e f g h');
73 SELECT rowid FROM t2 WHERE t2 MATCH 'b'; SELECT '::';
74 SELECT rowid FROM t2 WHERE t2 MATCH 'e'; SELECT '::';
75 SELECT rowid FROM t2 WHERE t2 MATCH 'h';
78 INSERT INTO t2(t2) VALUES('delete-all');
79 SELECT rowid FROM t2 WHERE t2 MATCH 'b'; SELECT '::';
80 SELECT rowid FROM t2 WHERE t2 MATCH 'e'; SELECT '::';
81 SELECT rowid FROM t2 WHERE t2 MATCH 'h';
84 INSERT INTO t2(rowid, x) VALUES(1, 'o t t f');
85 INSERT INTO t2(rowid, x) VALUES(2, 'f s s e');
86 INSERT INTO t2(rowid, x) VALUES(3, 'n t e t');
89 do_catchsql_test 2.7.1 {
91 } {1 {t2: table does not support scanning}}
92 do_catchsql_test 2.7.2 {
93 SELECT rowid FROM t2 WHERE rowid=2
94 } {1 {t2: table does not support scanning}}
95 do_catchsql_test 2.7.3 {
96 SELECT rowid FROM t2 WHERE rowid BETWEEN 1 AND 3
97 } {1 {t2: table does not support scanning}}
103 #-------------------------------------------------------------------------
104 # Test the xColumnSize() API
106 fts5_aux_test_functions db
108 do_execsql_test 3.1.0 {
109 CREATE VIRTUAL TABLE t3 USING fts5(x, y UNINDEXED, z, columnsize=0);
110 INSERT INTO t3 VALUES('a a', 'b b b', 'c');
111 INSERT INTO t3 VALUES('x a x', 'b b b y', '');
113 do_execsql_test 3.1.1 {
114 SELECT rowid, fts5_test_columnsize(t3) FROM t3 WHERE t3 MATCH 'a'
118 do_execsql_test 3.1.2 {
119 INSERT INTO t3 VALUES(NULL, NULL, 'a a a a');
120 DELETE FROM t3 WHERE rowid = 1;
121 SELECT rowid, fts5_test_columnsize(t3) FROM t3 WHERE t3 MATCH 'a'
126 do_execsql_test 3.2.0 {
127 CREATE VIRTUAL TABLE t4 USING fts5(x, y UNINDEXED, z, columnsize=0, content='');
128 INSERT INTO t4(rowid, x, y, z) VALUES(1, 'a a', 'b b b', 'c');
129 INSERT INTO t4(rowid, x, y, z) VALUES(2, 'x a x', 'b b b y', '');
131 do_execsql_test 3.2.1 {
132 SELECT rowid, fts5_test_columnsize(t4) FROM t4 WHERE t4 MATCH 'a'
134 1 {-1 0 -1} 2 {-1 0 -1}
137 #-------------------------------------------------------------------------
138 # Test the integrity-check
140 do_execsql_test 4.1.1 {
141 CREATE VIRTUAL TABLE t5 USING fts5(x, columnsize=0);
142 INSERT INTO t5 VALUES('1 2 3 4');
143 INSERT INTO t5 VALUES('2 4 6 8');
147 do_execsql_test 4.1.2 {
148 INSERT INTO t5(t5) VALUES('integrity-check');