1# 2006 September 9 2# 3# The author disclaims copyright to this source code. In place of 4# a legal notice, here is a blessing: 5# 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. 9# 10#************************************************************************* 11# This file implements regression tests for SQLite library. The 12# focus of this script is testing the FTS3 module. 13# 14# $Id: fts3aa.test,v 1.1 2007/08/20 17:38:42 shess Exp $ 15# 16 17set testdir [file dirname $argv0] 18source $testdir/tester.tcl 19set testprefix fts3aa 20 21# If SQLITE_ENABLE_FTS3 is defined, omit this file. 22ifcapable !fts3 { 23 finish_test 24 return 25} 26 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. 30# 31db 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'); 64} 65 66do_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} 69do_test fts3aa-1.2 { 70 execsql {SELECT rowid FROM t1 WHERE content MATCH 'one two'} 71} {3 7 11 15 19 23 27 31} 72do_test fts3aa-1.3 { 73 execsql {SELECT rowid FROM t1 WHERE content MATCH 'two one'} 74} {3 7 11 15 19 23 27 31} 75do_test fts3aa-1.4 { 76 execsql {SELECT rowid FROM t1 WHERE content MATCH 'one two three'} 77} {7 15 23 31} 78do_test fts3aa-1.5 { 79 execsql {SELECT rowid FROM t1 WHERE content MATCH 'one three two'} 80} {7 15 23 31} 81do_test fts3aa-1.6 { 82 execsql {SELECT rowid FROM t1 WHERE content MATCH 'two three one'} 83} {7 15 23 31} 84do_test fts3aa-1.7 { 85 execsql {SELECT rowid FROM t1 WHERE content MATCH 'two one three'} 86} {7 15 23 31} 87do_test fts3aa-1.8 { 88 execsql {SELECT rowid FROM t1 WHERE content MATCH 'three one two'} 89} {7 15 23 31} 90do_test fts3aa-1.9 { 91 execsql {SELECT rowid FROM t1 WHERE content MATCH 'three two one'} 92} {7 15 23 31} 93do_test fts3aa-1.10 { 94 execsql {SELECT rowid FROM t1 WHERE content MATCH 'one two THREE'} 95} {7 15 23 31} 96do_test fts3aa-1.11 { 97 execsql {SELECT rowid FROM t1 WHERE content MATCH ' ONE Two three '} 98} {7 15 23 31} 99 100do_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} 103do_test fts3aa-2.2 { 104 execsql {SELECT rowid FROM t1 WHERE content MATCH '"one two"'} 105} {3 7 11 15 19 23 27 31} 106do_test fts3aa-2.3 { 107 execsql {SELECT rowid FROM t1 WHERE content MATCH '"two one"'} 108} {} 109do_test fts3aa-2.4 { 110 execsql {SELECT rowid FROM t1 WHERE content MATCH '"one two three"'} 111} {7 15 23 31} 112do_test fts3aa-2.5 { 113 execsql {SELECT rowid FROM t1 WHERE content MATCH '"one three two"'} 114} {} 115do_test fts3aa-2.6 { 116 execsql {SELECT rowid FROM t1 WHERE content MATCH '"one two three four"'} 117} {15 31} 118do_test fts3aa-2.7 { 119 execsql {SELECT rowid FROM t1 WHERE content MATCH '"one three two four"'} 120} {} 121do_test fts3aa-2.8 { 122 execsql {SELECT rowid FROM t1 WHERE content MATCH '"one three five"'} 123} {21} 124do_test fts3aa-2.9 { 125 execsql {SELECT rowid FROM t1 WHERE content MATCH '"one three" five'} 126} {21 29} 127do_test fts3aa-2.10 { 128 execsql {SELECT rowid FROM t1 WHERE content MATCH 'five "one three"'} 129} {21 29} 130do_test fts3aa-2.11 { 131 execsql {SELECT rowid FROM t1 WHERE content MATCH 'five "one three" four'} 132} {29} 133do_test fts3aa-2.12 { 134 execsql {SELECT rowid FROM t1 WHERE content MATCH 'five four "one three"'} 135} {29} 136do_test fts3aa-2.13 { 137 execsql {SELECT rowid FROM t1 WHERE content MATCH '"one three" four five'} 138} {29} 139 140do_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} 143do_test fts3aa-3.2 { 144 execsql {SELECT rowid FROM t1 WHERE content MATCH 'one -two'} 145} {1 5 9 13 17 21 25 29} 146do_test fts3aa-3.3 { 147 execsql {SELECT rowid FROM t1 WHERE content MATCH '-two one'} 148} {1 5 9 13 17 21 25 29} 149 150do_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} 153do_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} 156do_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} 159do_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} 162do_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} 165do_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} 168do_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} 171 172# Test the ability to handle NULL content 173# 174do_test fts3aa-5.1 { 175 execsql {INSERT INTO t1(content) VALUES(NULL)} 176} {} 177do_test fts3aa-5.2 { 178 set rowid [db last_insert_rowid] 179 execsql {SELECT content FROM t1 WHERE rowid=$rowid} 180} {{}} 181do_test fts3aa-5.3 { 182 execsql {SELECT rowid FROM t1 WHERE content MATCH NULL} 183} {} 184 185# Test the ability to handle non-positive rowids 186# 187do_test fts3aa-6.0 { 188 execsql {INSERT INTO t1(rowid, content) VALUES(0, 'four five')} 189} {} 190do_test fts3aa-6.1 { 191 execsql {SELECT content FROM t1 WHERE rowid = 0} 192} {{four five}} 193do_test fts3aa-6.2 { 194 execsql {INSERT INTO t1(rowid, content) VALUES(-1, 'three four')} 195} {} 196do_test fts3aa-6.3 { 197 execsql {SELECT content FROM t1 WHERE rowid = -1} 198} {{three four}} 199do_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} 202 203# Test creation of FTS3 and FTS4 tables with columns that contain 204# an "=" character. 205# 206do_execsql_test fts3aa-7.1 { 207 CREATE VIRTUAL TABLE t2 USING fts3(xyz=abc); 208 SELECT xyz FROM t2; 209} {} 210do_catchsql_test fts3aa-7.2 { 211 CREATE VIRTUAL TABLE t3 USING fts4(xyz=abc); 212} {1 {unrecognized parameter: xyz=abc}} 213do_catchsql_test fts3aa-7.3 { 214 CREATE VIRTUAL TABLE t3 USING fts4(xyz = abc); 215} {1 {unrecognized parameter: xyz = abc}} 216 217do_execsql_test fts3aa-7.4 { 218 CREATE VIRTUAL TABLE t3 USING fts3(tokenize=simple, tokenize=simple); 219 SELECT tokenize FROM t3; 220} {} 221do_catchsql_test fts3aa-7.5 { 222 CREATE VIRTUAL TABLE t4 USING fts4(tokenize=simple, tokenize=simple); 223} {1 {unrecognized parameter: tokenize=simple}} 224 225do_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'); 231} 232do_execsql_test 8.1 { 233 SELECT docid FROM t0 WHERE t0 MATCH 'abc'; 234} {6 5} 235do_execsql_test 8.2 { 236 SELECT docid FROM t0 WHERE t0 MATCH '"abc abc"'; 237} {} 238do_execsql_test 8.3 { COMMIT } 239do_execsql_test 8.4 { 240 SELECT docid FROM t0 WHERE t0 MATCH 'abc'; 241} {6 5} 242do_execsql_test 8.5 { 243 SELECT docid FROM t0 WHERE t0 MATCH '"abc abc"'; 244} {} 245 246do_execsql_test 9.1 { 247 CREATE VIRTUAL TABLE t9 USING fts4(a, "", '---'); 248} 249do_execsql_test 9.2 { 250 CREATE VIRTUAL TABLE t10 USING fts3(<, b, c); 251} 252 253do_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; 259} 260do_catchsql_test 10.1 { 261 DELETE FROM z1; 262} {1 {SQL logic error}} 263 264expand_all_sql db 265finish_test 266