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
20 # If SQLITE_ENABLE_FTS3 is defined, omit this file.
26 # Construct a full-text search table containing five keywords:
27 # one, two, three, four, and five, in various combinations. The
28 # rowid for each will be a bitmask for the elements it contains.
31 CREATE VIRTUAL TABLE t1 USING fts3(content);
32 INSERT INTO t1(content) VALUES('one');
33 INSERT INTO t1(content) VALUES('two');
34 INSERT INTO t1(content) VALUES('one two');
35 INSERT INTO t1(content) VALUES('three');
36 INSERT INTO t1(content) VALUES('one three');
37 INSERT INTO t1(content) VALUES('two three');
38 INSERT INTO t1(content) VALUES('one two three');
39 INSERT INTO t1(content) VALUES('four');
40 INSERT INTO t1(content) VALUES('one four');
41 INSERT INTO t1(content) VALUES('two four');
42 INSERT INTO t1(content) VALUES('one two four');
43 INSERT INTO t1(content) VALUES('three four');
44 INSERT INTO t1(content) VALUES('one three four');
45 INSERT INTO t1(content) VALUES('two three four');
46 INSERT INTO t1(content) VALUES('one two three four');
47 INSERT INTO t1(content) VALUES('five');
48 INSERT INTO t1(content) VALUES('one five');
49 INSERT INTO t1(content) VALUES('two five');
50 INSERT INTO t1(content) VALUES('one two five');
51 INSERT INTO t1(content) VALUES('three five');
52 INSERT INTO t1(content) VALUES('one three five');
53 INSERT INTO t1(content) VALUES('two three five');
54 INSERT INTO t1(content) VALUES('one two three five');
55 INSERT INTO t1(content) VALUES('four five');
56 INSERT INTO t1(content) VALUES('one four five');
57 INSERT INTO t1(content) VALUES('two four five');
58 INSERT INTO t1(content) VALUES('one two four five');
59 INSERT INTO t1(content) VALUES('three four five');
60 INSERT INTO t1(content) VALUES('one three four five');
61 INSERT INTO t1(content) VALUES('two three four five');
62 INSERT INTO t1(content) VALUES('one two three four five');
66 execsql {SELECT rowid FROM t1 WHERE content MATCH 'one'}
67 } {1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31}
69 execsql {SELECT rowid FROM t1 WHERE content MATCH 'one two'}
70 } {3 7 11 15 19 23 27 31}
72 execsql {SELECT rowid FROM t1 WHERE content MATCH 'two one'}
73 } {3 7 11 15 19 23 27 31}
75 execsql {SELECT rowid FROM t1 WHERE content MATCH 'one two three'}
78 execsql {SELECT rowid FROM t1 WHERE content MATCH 'one three two'}
81 execsql {SELECT rowid FROM t1 WHERE content MATCH 'two three one'}
84 execsql {SELECT rowid FROM t1 WHERE content MATCH 'two one three'}
87 execsql {SELECT rowid FROM t1 WHERE content MATCH 'three one two'}
90 execsql {SELECT rowid FROM t1 WHERE content MATCH 'three two one'}
93 execsql {SELECT rowid FROM t1 WHERE content MATCH 'one two THREE'}
96 execsql {SELECT rowid FROM t1 WHERE content MATCH ' ONE Two three '}
100 execsql {SELECT rowid FROM t1 WHERE content MATCH '"one"'}
101 } {1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31}
103 execsql {SELECT rowid FROM t1 WHERE content MATCH '"one two"'}
104 } {3 7 11 15 19 23 27 31}
106 execsql {SELECT rowid FROM t1 WHERE content MATCH '"two one"'}
109 execsql {SELECT rowid FROM t1 WHERE content MATCH '"one two three"'}
112 execsql {SELECT rowid FROM t1 WHERE content MATCH '"one three two"'}
115 execsql {SELECT rowid FROM t1 WHERE content MATCH '"one two three four"'}
118 execsql {SELECT rowid FROM t1 WHERE content MATCH '"one three two four"'}
121 execsql {SELECT rowid FROM t1 WHERE content MATCH '"one three five"'}
124 execsql {SELECT rowid FROM t1 WHERE content MATCH '"one three" five'}
126 do_test fts3aa-2.10 {
127 execsql {SELECT rowid FROM t1 WHERE content MATCH 'five "one three"'}
129 do_test fts3aa-2.11 {
130 execsql {SELECT rowid FROM t1 WHERE content MATCH 'five "one three" four'}
132 do_test fts3aa-2.12 {
133 execsql {SELECT rowid FROM t1 WHERE content MATCH 'five four "one three"'}
135 do_test fts3aa-2.13 {
136 execsql {SELECT rowid FROM t1 WHERE content MATCH '"one three" four five'}
140 execsql {SELECT rowid FROM t1 WHERE content MATCH 'one'}
141 } {1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31}
143 execsql {SELECT rowid FROM t1 WHERE content MATCH 'one -two'}
144 } {1 5 9 13 17 21 25 29}
146 execsql {SELECT rowid FROM t1 WHERE content MATCH '-two one'}
147 } {1 5 9 13 17 21 25 29}
150 execsql {SELECT rowid FROM t1 WHERE content MATCH 'one OR two'}
151 } {1 2 3 5 6 7 9 10 11 13 14 15 17 18 19 21 22 23 25 26 27 29 30 31}
153 execsql {SELECT rowid FROM t1 WHERE content MATCH '"one two" OR three'}
154 } {3 4 5 6 7 11 12 13 14 15 19 20 21 22 23 27 28 29 30 31}
156 execsql {SELECT rowid FROM t1 WHERE content MATCH 'three OR "one two"'}
157 } {3 4 5 6 7 11 12 13 14 15 19 20 21 22 23 27 28 29 30 31}
159 execsql {SELECT rowid FROM t1 WHERE content MATCH 'one two OR three'}
160 } {3 5 7 11 13 15 19 21 23 27 29 31}
162 execsql {SELECT rowid FROM t1 WHERE content MATCH 'three OR two one'}
163 } {3 5 7 11 13 15 19 21 23 27 29 31}
165 execsql {SELECT rowid FROM t1 WHERE content MATCH 'one two OR three OR four'}
166 } {3 5 7 9 11 13 15 19 21 23 25 27 29 31}
168 execsql {SELECT rowid FROM t1 WHERE content MATCH 'two OR three OR four one'}
169 } {3 5 7 9 11 13 15 19 21 23 25 27 29 31}
171 # Test the ability to handle NULL content
174 execsql {INSERT INTO t1(content) VALUES(NULL)}
177 set rowid [db last_insert_rowid]
178 execsql {SELECT content FROM t1 WHERE rowid=$rowid}
181 execsql {SELECT rowid FROM t1 WHERE content MATCH NULL}
184 # Test the ability to handle non-positive rowids
187 execsql {INSERT INTO t1(rowid, content) VALUES(0, 'four five')}
190 execsql {SELECT content FROM t1 WHERE rowid = 0}
193 execsql {INSERT INTO t1(rowid, content) VALUES(-1, 'three four')}
196 execsql {SELECT content FROM t1 WHERE rowid = -1}
199 execsql {SELECT rowid FROM t1 WHERE t1 MATCH 'four'}
200 } {-1 0 8 9 10 11 12 13 14 15 24 25 26 27 28 29 30 31}
202 # Test creation of FTS3 and FTS4 tables with columns that contain
205 do_execsql_test fts3aa-7.1 {
206 CREATE VIRTUAL TABLE t2 USING fts3(xyz=abc);
209 do_catchsql_test fts3aa-7.2 {
210 CREATE VIRTUAL TABLE t3 USING fts4(xyz=abc);
211 } {1 {unrecognized parameter: xyz=abc}}
212 do_catchsql_test fts3aa-7.3 {
213 CREATE VIRTUAL TABLE t3 USING fts4(xyz = abc);
214 } {1 {unrecognized parameter: xyz = abc}}
216 do_execsql_test fts3aa-7.4 {
217 CREATE VIRTUAL TABLE t3 USING fts3(tokenize=simple, tokenize=simple);
218 SELECT tokenize FROM t3;
220 do_catchsql_test fts3aa-7.5 {
221 CREATE VIRTUAL TABLE t4 USING fts4(tokenize=simple, tokenize=simple);
222 } {1 {unrecognized parameter: tokenize=simple}}