Add a test for the fixes on this branch.
[sqlite.git] / test / fts3aa.test
blobcb1bde74a46650c0381292ae8af41d20ef661d44
1 # 2006 September 9
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
19 set testprefix fts3aa
21 # If SQLITE_ENABLE_FTS3 is defined, omit this file.
22 ifcapable !fts3 {
23   finish_test
24   return
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.
31 db eval {
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');
66 do_test fts3aa-1.1 {
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}
69 do_test fts3aa-1.2 {
70   execsql {SELECT rowid FROM t1 WHERE content MATCH 'one two'}
71 } {3 7 11 15 19 23 27 31}
72 do_test fts3aa-1.3 {
73   execsql {SELECT rowid FROM t1 WHERE content MATCH 'two one'}
74 } {3 7 11 15 19 23 27 31}
75 do_test fts3aa-1.4 {
76   execsql {SELECT rowid FROM t1 WHERE content MATCH 'one two three'}
77 } {7 15 23 31}
78 do_test fts3aa-1.5 {
79   execsql {SELECT rowid FROM t1 WHERE content MATCH 'one three two'}
80 } {7 15 23 31}
81 do_test fts3aa-1.6 {
82   execsql {SELECT rowid FROM t1 WHERE content MATCH 'two three one'}
83 } {7 15 23 31}
84 do_test fts3aa-1.7 {
85   execsql {SELECT rowid FROM t1 WHERE content MATCH 'two one three'}
86 } {7 15 23 31}
87 do_test fts3aa-1.8 {
88   execsql {SELECT rowid FROM t1 WHERE content MATCH 'three one two'}
89 } {7 15 23 31}
90 do_test fts3aa-1.9 {
91   execsql {SELECT rowid FROM t1 WHERE content MATCH 'three two one'}
92 } {7 15 23 31}
93 do_test fts3aa-1.10 {
94   execsql {SELECT rowid FROM t1 WHERE content MATCH 'one two THREE'}
95 } {7 15 23 31}
96 do_test fts3aa-1.11 {
97   execsql {SELECT rowid FROM t1 WHERE content MATCH '  ONE    Two   three  '}
98 } {7 15 23 31}
100 do_test fts3aa-2.1 {
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}
103 do_test fts3aa-2.2 {
104   execsql {SELECT rowid FROM t1 WHERE content MATCH '"one two"'}
105 } {3 7 11 15 19 23 27 31}
106 do_test fts3aa-2.3 {
107   execsql {SELECT rowid FROM t1 WHERE content MATCH '"two one"'}
108 } {}
109 do_test fts3aa-2.4 {
110   execsql {SELECT rowid FROM t1 WHERE content MATCH '"one two three"'}
111 } {7 15 23 31}
112 do_test fts3aa-2.5 {
113   execsql {SELECT rowid FROM t1 WHERE content MATCH '"one three two"'}
114 } {}
115 do_test fts3aa-2.6 {
116   execsql {SELECT rowid FROM t1 WHERE content MATCH '"one two three four"'}
117 } {15 31}
118 do_test fts3aa-2.7 {
119   execsql {SELECT rowid FROM t1 WHERE content MATCH '"one three two four"'}
120 } {}
121 do_test fts3aa-2.8 {
122   execsql {SELECT rowid FROM t1 WHERE content MATCH '"one three five"'}
123 } {21}
124 do_test fts3aa-2.9 {
125   execsql {SELECT rowid FROM t1 WHERE content MATCH '"one three" five'}
126 } {21 29}
127 do_test fts3aa-2.10 {
128   execsql {SELECT rowid FROM t1 WHERE content MATCH 'five "one three"'}
129 } {21 29}
130 do_test fts3aa-2.11 {
131   execsql {SELECT rowid FROM t1 WHERE content MATCH 'five "one three" four'}
132 } {29}
133 do_test fts3aa-2.12 {
134   execsql {SELECT rowid FROM t1 WHERE content MATCH 'five four "one three"'}
135 } {29}
136 do_test fts3aa-2.13 {
137   execsql {SELECT rowid FROM t1 WHERE content MATCH '"one three" four five'}
138 } {29}
140 do_test fts3aa-3.1 {
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}
143 do_test fts3aa-3.2 {
144   execsql {SELECT rowid FROM t1 WHERE content MATCH 'one -two'}
145 } {1 5 9 13 17 21 25 29}
146 do_test fts3aa-3.3 {
147   execsql {SELECT rowid FROM t1 WHERE content MATCH '-two one'}
148 } {1 5 9 13 17 21 25 29}
150 do_test fts3aa-4.1 {
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}
153 do_test fts3aa-4.2 {
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}
156 do_test fts3aa-4.3 {
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}
159 do_test fts3aa-4.4 {
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}
162 do_test fts3aa-4.5 {
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}
165 do_test fts3aa-4.6 {
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}
168 do_test fts3aa-4.7 {
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
174 do_test fts3aa-5.1 {
175   execsql {INSERT INTO t1(content) VALUES(NULL)}
176 } {}
177 do_test fts3aa-5.2 {
178   set rowid [db last_insert_rowid]
179   execsql {SELECT content FROM t1 WHERE rowid=$rowid}
180 } {{}}
181 do_test fts3aa-5.3 {
182   execsql {SELECT rowid FROM t1 WHERE content MATCH NULL}
183 } {}
185 # Test the ability to handle non-positive rowids
187 do_test fts3aa-6.0 {
188   execsql {INSERT INTO t1(rowid, content) VALUES(0, 'four five')}
189 } {}
190 do_test fts3aa-6.1 {
191   execsql {SELECT content FROM t1 WHERE rowid = 0}
192 } {{four five}}
193 do_test fts3aa-6.2 {
194   execsql {INSERT INTO t1(rowid, content) VALUES(-1, 'three four')}
195 } {}
196 do_test fts3aa-6.3 {
197   execsql {SELECT content FROM t1 WHERE rowid = -1}
198 } {{three four}}
199 do_test fts3aa-6.4 {
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
204 # an "=" character.
206 do_execsql_test fts3aa-7.1 {
207   CREATE VIRTUAL TABLE t2 USING fts3(xyz=abc);
208   SELECT xyz FROM t2;
209 } {}
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;
220 } {}
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);
227   BEGIN;
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';
234 } {6 5}
235 do_execsql_test 8.2 {
236   SELECT docid FROM t0 WHERE t0 MATCH '"abc abc"';
237 } {}
238 do_execsql_test 8.3 { COMMIT }
239 do_execsql_test 8.4 {
240   SELECT docid FROM t0 WHERE t0 MATCH 'abc';
241 } {6 5}
242 do_execsql_test 8.5 {
243   SELECT docid FROM t0 WHERE t0 MATCH '"abc abc"';
244 } {}
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
257     DELETE FROM z1;
258   END;
260 do_catchsql_test 10.1 {
261   DELETE FROM z1;
262 } {1 {SQL logic error}}
264 expand_all_sql db
265 finish_test