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.
14 # $Id: fts3aa.test,v 1.1 2007/08/20 17:38:42 shess Exp $
17 set testdir [file dirname $argv0]
18 source $testdir/tester.tcl
21 # If SQLITE_ENABLE_FTS3 is defined, omit this file.
27 # Construct a full-text search table containing five keywords:
28 # one, two, three, four, and five, in various combinations. The
29 # rowid for each will be a bitmask for the elements it contains.
32 CREATE VIRTUAL TABLE t1 USING fts3(content);
33 INSERT INTO t1(content) VALUES('one');
34 INSERT INTO t1(content) VALUES('two');
35 INSERT INTO t1(content) VALUES('one two');
36 INSERT INTO t1(content) VALUES('three');
37 INSERT INTO t1(content) VALUES('one three');
38 INSERT INTO t1(content) VALUES('two three');
39 INSERT INTO t1(content) VALUES('one two three');
40 INSERT INTO t1(content) VALUES('four');
41 INSERT INTO t1(content) VALUES('one four');
42 INSERT INTO t1(content) VALUES('two four');
43 INSERT INTO t1(content) VALUES('one two four');
44 INSERT INTO t1(content) VALUES('three four');
45 INSERT INTO t1(content) VALUES('one three four');
46 INSERT INTO t1(content) VALUES('two three four');
47 INSERT INTO t1(content) VALUES('one two three four');
48 INSERT INTO t1(content) VALUES('five');
49 INSERT INTO t1(content) VALUES('one five');
50 INSERT INTO t1(content) VALUES('two five');
51 INSERT INTO t1(content) VALUES('one two five');
52 INSERT INTO t1(content) VALUES('three five');
53 INSERT INTO t1(content) VALUES('one three five');
54 INSERT INTO t1(content) VALUES('two three five');
55 INSERT INTO t1(content) VALUES('one two three five');
56 INSERT INTO t1(content) VALUES('four five');
57 INSERT INTO t1(content) VALUES('one four five');
58 INSERT INTO t1(content) VALUES('two four five');
59 INSERT INTO t1(content) VALUES('one two four five');
60 INSERT INTO t1(content) VALUES('three four five');
61 INSERT INTO t1(content) VALUES('one three four five');
62 INSERT INTO t1(content) VALUES('two three four five');
63 INSERT INTO t1(content) VALUES('one two three four five');
67 execsql {SELECT rowid FROM t1 WHERE content MATCH 'one'}
68 } {1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31}
70 execsql {SELECT rowid FROM t1 WHERE content MATCH 'one two'}
71 } {3 7 11 15 19 23 27 31}
73 execsql {SELECT rowid FROM t1 WHERE content MATCH 'two one'}
74 } {3 7 11 15 19 23 27 31}
76 execsql {SELECT rowid FROM t1 WHERE content MATCH 'one two three'}
79 execsql {SELECT rowid FROM t1 WHERE content MATCH 'one three two'}
82 execsql {SELECT rowid FROM t1 WHERE content MATCH 'two three one'}
85 execsql {SELECT rowid FROM t1 WHERE content MATCH 'two one three'}
88 execsql {SELECT rowid FROM t1 WHERE content MATCH 'three one two'}
91 execsql {SELECT rowid FROM t1 WHERE content MATCH 'three two one'}
94 execsql {SELECT rowid FROM t1 WHERE content MATCH 'one two THREE'}
97 execsql {SELECT rowid FROM t1 WHERE content MATCH ' ONE Two three '}
101 execsql {SELECT rowid FROM t1 WHERE content MATCH '"one"'}
102 } {1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31}
104 execsql {SELECT rowid FROM t1 WHERE content MATCH '"one two"'}
105 } {3 7 11 15 19 23 27 31}
107 execsql {SELECT rowid FROM t1 WHERE content MATCH '"two one"'}
110 execsql {SELECT rowid FROM t1 WHERE content MATCH '"one two three"'}
113 execsql {SELECT rowid FROM t1 WHERE content MATCH '"one three two"'}
116 execsql {SELECT rowid FROM t1 WHERE content MATCH '"one two three four"'}
119 execsql {SELECT rowid FROM t1 WHERE content MATCH '"one three two four"'}
122 execsql {SELECT rowid FROM t1 WHERE content MATCH '"one three five"'}
125 execsql {SELECT rowid FROM t1 WHERE content MATCH '"one three" five'}
127 do_test fts3aa-2.10 {
128 execsql {SELECT rowid FROM t1 WHERE content MATCH 'five "one three"'}
130 do_test fts3aa-2.11 {
131 execsql {SELECT rowid FROM t1 WHERE content MATCH 'five "one three" four'}
133 do_test fts3aa-2.12 {
134 execsql {SELECT rowid FROM t1 WHERE content MATCH 'five four "one three"'}
136 do_test fts3aa-2.13 {
137 execsql {SELECT rowid FROM t1 WHERE content MATCH '"one three" four five'}
141 execsql {SELECT rowid FROM t1 WHERE content MATCH 'one'}
142 } {1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31}
144 execsql {SELECT rowid FROM t1 WHERE content MATCH 'one -two'}
145 } {1 5 9 13 17 21 25 29}
147 execsql {SELECT rowid FROM t1 WHERE content MATCH '-two one'}
148 } {1 5 9 13 17 21 25 29}
151 execsql {SELECT rowid FROM t1 WHERE content MATCH 'one OR two'}
152 } {1 2 3 5 6 7 9 10 11 13 14 15 17 18 19 21 22 23 25 26 27 29 30 31}
154 execsql {SELECT rowid FROM t1 WHERE content MATCH '"one two" OR three'}
155 } {3 4 5 6 7 11 12 13 14 15 19 20 21 22 23 27 28 29 30 31}
157 execsql {SELECT rowid FROM t1 WHERE content MATCH 'three OR "one two"'}
158 } {3 4 5 6 7 11 12 13 14 15 19 20 21 22 23 27 28 29 30 31}
160 execsql {SELECT rowid FROM t1 WHERE content MATCH 'one two OR three'}
161 } {3 5 7 11 13 15 19 21 23 27 29 31}
163 execsql {SELECT rowid FROM t1 WHERE content MATCH 'three OR two one'}
164 } {3 5 7 11 13 15 19 21 23 27 29 31}
166 execsql {SELECT rowid FROM t1 WHERE content MATCH 'one two OR three OR four'}
167 } {3 5 7 9 11 13 15 19 21 23 25 27 29 31}
169 execsql {SELECT rowid FROM t1 WHERE content MATCH 'two OR three OR four one'}
170 } {3 5 7 9 11 13 15 19 21 23 25 27 29 31}
172 # Test the ability to handle NULL content
175 execsql {INSERT INTO t1(content) VALUES(NULL)}
178 set rowid [db last_insert_rowid]
179 execsql {SELECT content FROM t1 WHERE rowid=$rowid}
182 execsql {SELECT rowid FROM t1 WHERE content MATCH NULL}
185 # Test the ability to handle non-positive rowids
188 execsql {INSERT INTO t1(rowid, content) VALUES(0, 'four five')}
191 execsql {SELECT content FROM t1 WHERE rowid = 0}
194 execsql {INSERT INTO t1(rowid, content) VALUES(-1, 'three four')}
197 execsql {SELECT content FROM t1 WHERE rowid = -1}
200 execsql {SELECT rowid FROM t1 WHERE t1 MATCH 'four'}
201 } {-1 0 8 9 10 11 12 13 14 15 24 25 26 27 28 29 30 31}
203 # Test creation of FTS3 and FTS4 tables with columns that contain
206 do_execsql_test fts3aa-7.1 {
207 CREATE VIRTUAL TABLE t2 USING fts3(xyz=abc);
210 do_catchsql_test fts3aa-7.2 {
211 CREATE VIRTUAL TABLE t3 USING fts4(xyz=abc);
212 } {1 {unrecognized parameter: xyz=abc}}
213 do_catchsql_test fts3aa-7.3 {
214 CREATE VIRTUAL TABLE t3 USING fts4(xyz = abc);
215 } {1 {unrecognized parameter: xyz = abc}}
217 do_execsql_test fts3aa-7.4 {
218 CREATE VIRTUAL TABLE t3 USING fts3(tokenize=simple, tokenize=simple);
219 SELECT tokenize FROM t3;
221 do_catchsql_test fts3aa-7.5 {
222 CREATE VIRTUAL TABLE t4 USING fts4(tokenize=simple, tokenize=simple);
223 } {1 {unrecognized parameter: tokenize=simple}}
225 do_execsql_test 8.0 {
226 CREATE VIRTUAL TABLE t0 USING fts4(order=desc);
228 INSERT INTO t0(rowid, content) VALUES(1, 'abc');
229 UPDATE t0 SET docid=5 WHERE docid=1;
230 INSERT INTO t0(rowid, content) VALUES(6, 'abc');
232 do_execsql_test 8.1 {
233 SELECT docid FROM t0 WHERE t0 MATCH 'abc';
235 do_execsql_test 8.2 {
236 SELECT docid FROM t0 WHERE t0 MATCH '"abc abc"';
238 do_execsql_test 8.3 { COMMIT }
239 do_execsql_test 8.4 {
240 SELECT docid FROM t0 WHERE t0 MATCH 'abc';
242 do_execsql_test 8.5 {
243 SELECT docid FROM t0 WHERE t0 MATCH '"abc abc"';
246 do_execsql_test 9.1 {
247 CREATE VIRTUAL TABLE t9 USING fts4(a, "", '---');
249 do_execsql_test 9.2 {
250 CREATE VIRTUAL TABLE t10 USING fts3(<, b, c);
253 do_execsql_test 10.0 {
254 CREATE VIRTUAL TABLE z1 USING fts3;
255 INSERT INTO z1 VALUES('one two three'),('four one five'),('six two five');
256 CREATE TRIGGER z1r1 AFTER DELETE ON z1_content BEGIN
260 do_catchsql_test 10.1 {
262 } {1 {SQL logic error}}