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 #*************************************************************************
11 # This file implements regression tests for SQLite library. The
12 # focus of this script is testing the FTS3 module.
15 set testdir [file dirname $argv0]
16 source $testdir/tester.tcl
17 set testprefix fts3misc
19 # If SQLITE_ENABLE_FTS3 is defined, omit this file.
25 #-------------------------------------------------------------------------
29 CREATE VIRTUAL TABLE t1 USING fts3(a, b);
30 INSERT INTO t1 VALUES('one', 'i');
31 INSERT INTO t1 VALUES('one', 'ii');
32 INSERT INTO t1 VALUES('two', 'i');
33 INSERT INTO t1 VALUES('two', 'ii');
37 SELECT a.a, b.b FROM t1 a, t1 b WHERE a.t1 MATCH 'two' AND b.t1 MATCH 'i'
38 } {two i two i two i two i}
40 #-------------------------------------------------------------------------
41 # FTS tables with 128 or more columns.
44 set vector [list a b c d e f g h]
46 for {set i 0} {$i<8} {incr i} {
47 if {$v & (1 << $i)} { lappend res [lindex $vector $i] }
52 set vector [list d e f g h i j k]
54 for {set i 0} {$i<8} {incr i} {
55 if {$v & (1 << $i)} { lappend res [lindex $vector $i] }
64 for {set i 0} {$i<200} {incr i} {
67 execsql "CREATE VIRTUAL TABLE t2 USING fts3([join $cols ,])"
70 SELECT 1 UNION ALL SELECT i+1 FROM data WHERE i<200
72 INSERT INTO t2(c198, c199) SELECT v1(i), v2(i) FROM data;
76 SELECT rowid FROM t2 WHERE t2 MATCH '"a b c"'
78 7 15 23 31 39 47 55 63 71 79 87 95 103 111
79 119 127 135 143 151 159 167 175 183 191 199
82 SELECT rowid FROM t2 WHERE t2 MATCH '"g h i"'
84 56 57 58 59 60 61 62 63 120 121 122 123 124
85 125 126 127 184 185 186 187 188 189 190 191
88 SELECT rowid FROM t2 WHERE t2 MATCH '"i h"'
92 SELECT rowid FROM t2 WHERE t2 MATCH '"f e"'
96 SELECT rowid FROM t2 WHERE t2 MATCH '"e f"'
98 6 7 14 15 22 23 30 31 38 39 46 47 48 49 50 51 52 53 54 55 56
99 57 58 59 60 61 62 63 70 71 78 79 86 87 94 95 102 103 110
100 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127
101 134 135 142 143 150 151 158 159 166 167 174 175 176 177 178 179 180
102 181 182 183 184 185 186 187 188 189 190 191 198 199
105 #-------------------------------------------------------------------------
106 # Range constraints on the docid using non-integer values.
108 do_execsql_test 2.6 {
109 SELECT rowid FROM t2 WHERE t2 MATCH 'e' AND rowid BETWEEN NULL AND 45;
111 do_execsql_test 2.7 {
112 SELECT rowid FROM t2 WHERE t2 MATCH 'e' AND rowid BETWEEN 11.5 AND 48.2;
114 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
115 29 30 31 34 35 38 39 42 43 46 47 48
117 do_execsql_test 2.8 {
118 SELECT rowid FROM t2 WHERE t2 MATCH 'e' AND rowid BETWEEN '11.5' AND '48.2';
120 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
121 29 30 31 34 35 38 39 42 43 46 47 48
124 #-------------------------------------------------------------------------
125 # Phrase query tests.
127 do_execsql_test 3.1.1 {
128 CREATE VIRTUAL TABLE t3 USING fts3;
129 INSERT INTO t3 VALUES('a b c');
130 INSERT INTO t3 VALUES('d e f');
131 INSERT INTO t3 VALUES('a b d');
132 INSERT INTO t3 VALUES('1 2 3 4 5 6 7 8 9 10 11');
134 do_execsql_test 3.1.2 {
135 SELECT * FROM t3 WHERE t3 MATCH '"a b x y"' ORDER BY docid DESC
137 do_execsql_test 3.1.3 {
138 SELECT * FROM t3 WHERE t3 MATCH '"a b c" OR "a b x y"' ORDER BY docid DESC
140 do_execsql_test 3.1.4 {
141 SELECT * FROM t3 WHERE t3 MATCH '"a* b* x* a*"'
143 do_execsql_test 3.1.5 {
144 SELECT rowid FROM t3 WHERE t3 MATCH '"2 3 4 5 6 7 8 9"'
147 #-------------------------------------------------------------------------
150 ifcapable fts4_deferred {
151 do_execsql_test 4.0 {
152 PRAGMA page_size = 512;
153 CREATE VIRTUAL TABLE t4 USING fts4;
154 WITH s(i) AS ( SELECT 1 UNION ALL SELECT i+1 FROM s WHERE i<8000 )
155 INSERT INTO t4 SELECT 'a b c a b c a b c' FROM s;
157 do_execsql_test 4.1 {
158 SELECT count(*) FROM t4 WHERE t4 MATCH '"a b c" OR "c a b"'
160 do_execsql_test 4.2 {
161 SELECT quote(value) from t4_stat where id=0
162 } {X'C03EC0B204C0A608'}
163 do_execsql_test 4.3 {
164 UPDATE t4_stat SET value = X'C03EC0B204C0A60800' WHERE id=0;
166 do_catchsql_test 4.4 {
167 SELECT count(*) FROM t4 WHERE t4 MATCH '"a b c" OR "c a b"'
168 } {1 {database disk image is malformed}}
169 do_execsql_test 4.5 {
170 UPDATE t4_stat SET value = X'00C03EC0B204C0A608' WHERE id=0;
172 do_catchsql_test 4.6 {
173 SELECT count(*) FROM t4 WHERE t4 MATCH '"a b c" OR "c a b"'
174 } {1 {database disk image is malformed}}
177 #-------------------------------------------------------------------------
180 do_execsql_test 5.0 {
181 CREATE VIRTUAL TABLE t5 USING fts4;
182 INSERT INTO t5 VALUES('a x x x x b x x x x c');
183 INSERT INTO t5 VALUES('a x x x x b x x x x c');
184 INSERT INTO t5 VALUES('a x x x x b x x x x c');
186 do_execsql_test 5.1 {
187 SELECT rowid FROM t5 WHERE t5 MATCH 'a NEAR/4 b NEAR/4 c'
189 do_execsql_test 5.2 {
190 SELECT rowid FROM t5 WHERE t5 MATCH 'a NEAR/3 b NEAR/4 c'
192 do_execsql_test 5.3 {
193 SELECT rowid FROM t5 WHERE t5 MATCH 'a NEAR/4 b NEAR/3 c'
195 do_execsql_test 5.4 {
196 SELECT rowid FROM t5 WHERE t5 MATCH 'y NEAR/4 b NEAR/4 c'
198 do_execsql_test 5.5 {
199 SELECT rowid FROM t5 WHERE t5 MATCH 'x OR a NEAR/3 b NEAR/3 c'
201 do_execsql_test 5.5 {
202 SELECT rowid FROM t5 WHERE t5 MATCH 'x OR y NEAR/3 b NEAR/3 c'
205 #-------------------------------------------------------------------------
208 do_execsql_test 6.0 {
209 CREATE VIRTUAL TABLE t6 USING fts4;
212 WITH s(i) AS (SELECT 1 UNION ALL SELECT i+1 FROM s WHERE i<50000)
213 INSERT INTO t6 SELECT 'x x x x x x x x x x x' FROM s;
215 INSERT INTO t6 VALUES('x x x x x x x x x x x A');
216 INSERT INTO t6 VALUES('x x x x x x x x x x x B');
217 INSERT INTO t6 VALUES('x x x x x x x x x x x A');
218 INSERT INTO t6 VALUES('x x x x x x x x x x x B');
220 WITH s(i) AS (SELECT 1 UNION ALL SELECT i+1 FROM s WHERE i<50000)
221 INSERT INTO t6 SELECT 'x x x x x x x x x x x' FROM s;
224 do_execsql_test 6.1 {
225 SELECT rowid FROM t6 WHERE t6 MATCH 'b OR "x a"'
226 } {50001 50002 50003 50004}