1db00b6aeSshess# 2006 September 9 2db00b6aeSshess# 3db00b6aeSshess# The author disclaims copyright to this source code. In place of 4db00b6aeSshess# a legal notice, here is a blessing: 5db00b6aeSshess# 6db00b6aeSshess# May you do good and not evil. 7db00b6aeSshess# May you find forgiveness for yourself and forgive others. 8db00b6aeSshess# May you share freely, never taking more than you give. 9db00b6aeSshess# 10db00b6aeSshess#************************************************************************* 11db00b6aeSshess# This file implements regression tests for SQLite library. The 12db00b6aeSshess# focus of this script is testing the FTS3 module. 13db00b6aeSshess# 14db00b6aeSshess# $Id: fts3aa.test,v 1.1 2007/08/20 17:38:42 shess Exp $ 15db00b6aeSshess# 16db00b6aeSshess 17db00b6aeSshessset testdir [file dirname $argv0] 18db00b6aeSshesssource $testdir/tester.tcl 191586699cSdanset testprefix fts3aa 20db00b6aeSshess 21db00b6aeSshess# If SQLITE_ENABLE_FTS3 is defined, omit this file. 22db00b6aeSshessifcapable !fts3 { 23db00b6aeSshess finish_test 24db00b6aeSshess return 25db00b6aeSshess} 26db00b6aeSshess 27db00b6aeSshess# Construct a full-text search table containing five keywords: 28db00b6aeSshess# one, two, three, four, and five, in various combinations. The 29db00b6aeSshess# rowid for each will be a bitmask for the elements it contains. 30db00b6aeSshess# 31db00b6aeSshessdb eval { 32db00b6aeSshess CREATE VIRTUAL TABLE t1 USING fts3(content); 33db00b6aeSshess INSERT INTO t1(content) VALUES('one'); 34db00b6aeSshess INSERT INTO t1(content) VALUES('two'); 35db00b6aeSshess INSERT INTO t1(content) VALUES('one two'); 36db00b6aeSshess INSERT INTO t1(content) VALUES('three'); 37db00b6aeSshess INSERT INTO t1(content) VALUES('one three'); 38db00b6aeSshess INSERT INTO t1(content) VALUES('two three'); 39db00b6aeSshess INSERT INTO t1(content) VALUES('one two three'); 40db00b6aeSshess INSERT INTO t1(content) VALUES('four'); 41db00b6aeSshess INSERT INTO t1(content) VALUES('one four'); 42db00b6aeSshess INSERT INTO t1(content) VALUES('two four'); 43db00b6aeSshess INSERT INTO t1(content) VALUES('one two four'); 44db00b6aeSshess INSERT INTO t1(content) VALUES('three four'); 45db00b6aeSshess INSERT INTO t1(content) VALUES('one three four'); 46db00b6aeSshess INSERT INTO t1(content) VALUES('two three four'); 47db00b6aeSshess INSERT INTO t1(content) VALUES('one two three four'); 48db00b6aeSshess INSERT INTO t1(content) VALUES('five'); 49db00b6aeSshess INSERT INTO t1(content) VALUES('one five'); 50db00b6aeSshess INSERT INTO t1(content) VALUES('two five'); 51db00b6aeSshess INSERT INTO t1(content) VALUES('one two five'); 52db00b6aeSshess INSERT INTO t1(content) VALUES('three five'); 53db00b6aeSshess INSERT INTO t1(content) VALUES('one three five'); 54db00b6aeSshess INSERT INTO t1(content) VALUES('two three five'); 55db00b6aeSshess INSERT INTO t1(content) VALUES('one two three five'); 56db00b6aeSshess INSERT INTO t1(content) VALUES('four five'); 57db00b6aeSshess INSERT INTO t1(content) VALUES('one four five'); 58db00b6aeSshess INSERT INTO t1(content) VALUES('two four five'); 59db00b6aeSshess INSERT INTO t1(content) VALUES('one two four five'); 60db00b6aeSshess INSERT INTO t1(content) VALUES('three four five'); 61db00b6aeSshess INSERT INTO t1(content) VALUES('one three four five'); 62db00b6aeSshess INSERT INTO t1(content) VALUES('two three four five'); 63db00b6aeSshess INSERT INTO t1(content) VALUES('one two three four five'); 64db00b6aeSshess} 65db00b6aeSshess 66db00b6aeSshessdo_test fts3aa-1.1 { 67db00b6aeSshess execsql {SELECT rowid FROM t1 WHERE content MATCH 'one'} 68db00b6aeSshess} {1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31} 69db00b6aeSshessdo_test fts3aa-1.2 { 70db00b6aeSshess execsql {SELECT rowid FROM t1 WHERE content MATCH 'one two'} 71db00b6aeSshess} {3 7 11 15 19 23 27 31} 72db00b6aeSshessdo_test fts3aa-1.3 { 73db00b6aeSshess execsql {SELECT rowid FROM t1 WHERE content MATCH 'two one'} 74db00b6aeSshess} {3 7 11 15 19 23 27 31} 75db00b6aeSshessdo_test fts3aa-1.4 { 76db00b6aeSshess execsql {SELECT rowid FROM t1 WHERE content MATCH 'one two three'} 77db00b6aeSshess} {7 15 23 31} 78db00b6aeSshessdo_test fts3aa-1.5 { 79db00b6aeSshess execsql {SELECT rowid FROM t1 WHERE content MATCH 'one three two'} 80db00b6aeSshess} {7 15 23 31} 81db00b6aeSshessdo_test fts3aa-1.6 { 82db00b6aeSshess execsql {SELECT rowid FROM t1 WHERE content MATCH 'two three one'} 83db00b6aeSshess} {7 15 23 31} 84db00b6aeSshessdo_test fts3aa-1.7 { 85db00b6aeSshess execsql {SELECT rowid FROM t1 WHERE content MATCH 'two one three'} 86db00b6aeSshess} {7 15 23 31} 87db00b6aeSshessdo_test fts3aa-1.8 { 88db00b6aeSshess execsql {SELECT rowid FROM t1 WHERE content MATCH 'three one two'} 89db00b6aeSshess} {7 15 23 31} 90db00b6aeSshessdo_test fts3aa-1.9 { 91db00b6aeSshess execsql {SELECT rowid FROM t1 WHERE content MATCH 'three two one'} 92db00b6aeSshess} {7 15 23 31} 93db00b6aeSshessdo_test fts3aa-1.10 { 94db00b6aeSshess execsql {SELECT rowid FROM t1 WHERE content MATCH 'one two THREE'} 95db00b6aeSshess} {7 15 23 31} 96db00b6aeSshessdo_test fts3aa-1.11 { 97db00b6aeSshess execsql {SELECT rowid FROM t1 WHERE content MATCH ' ONE Two three '} 98db00b6aeSshess} {7 15 23 31} 99db00b6aeSshess 100db00b6aeSshessdo_test fts3aa-2.1 { 101db00b6aeSshess execsql {SELECT rowid FROM t1 WHERE content MATCH '"one"'} 102db00b6aeSshess} {1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31} 103db00b6aeSshessdo_test fts3aa-2.2 { 104db00b6aeSshess execsql {SELECT rowid FROM t1 WHERE content MATCH '"one two"'} 105db00b6aeSshess} {3 7 11 15 19 23 27 31} 106db00b6aeSshessdo_test fts3aa-2.3 { 107db00b6aeSshess execsql {SELECT rowid FROM t1 WHERE content MATCH '"two one"'} 108db00b6aeSshess} {} 109db00b6aeSshessdo_test fts3aa-2.4 { 110db00b6aeSshess execsql {SELECT rowid FROM t1 WHERE content MATCH '"one two three"'} 111db00b6aeSshess} {7 15 23 31} 112db00b6aeSshessdo_test fts3aa-2.5 { 113db00b6aeSshess execsql {SELECT rowid FROM t1 WHERE content MATCH '"one three two"'} 114db00b6aeSshess} {} 115db00b6aeSshessdo_test fts3aa-2.6 { 116db00b6aeSshess execsql {SELECT rowid FROM t1 WHERE content MATCH '"one two three four"'} 117db00b6aeSshess} {15 31} 118db00b6aeSshessdo_test fts3aa-2.7 { 119db00b6aeSshess execsql {SELECT rowid FROM t1 WHERE content MATCH '"one three two four"'} 120db00b6aeSshess} {} 121db00b6aeSshessdo_test fts3aa-2.8 { 122db00b6aeSshess execsql {SELECT rowid FROM t1 WHERE content MATCH '"one three five"'} 123db00b6aeSshess} {21} 124db00b6aeSshessdo_test fts3aa-2.9 { 125db00b6aeSshess execsql {SELECT rowid FROM t1 WHERE content MATCH '"one three" five'} 126db00b6aeSshess} {21 29} 127db00b6aeSshessdo_test fts3aa-2.10 { 128db00b6aeSshess execsql {SELECT rowid FROM t1 WHERE content MATCH 'five "one three"'} 129db00b6aeSshess} {21 29} 130db00b6aeSshessdo_test fts3aa-2.11 { 131db00b6aeSshess execsql {SELECT rowid FROM t1 WHERE content MATCH 'five "one three" four'} 132db00b6aeSshess} {29} 133db00b6aeSshessdo_test fts3aa-2.12 { 134db00b6aeSshess execsql {SELECT rowid FROM t1 WHERE content MATCH 'five four "one three"'} 135db00b6aeSshess} {29} 136db00b6aeSshessdo_test fts3aa-2.13 { 137db00b6aeSshess execsql {SELECT rowid FROM t1 WHERE content MATCH '"one three" four five'} 138db00b6aeSshess} {29} 139db00b6aeSshess 140db00b6aeSshessdo_test fts3aa-3.1 { 141db00b6aeSshess execsql {SELECT rowid FROM t1 WHERE content MATCH 'one'} 142db00b6aeSshess} {1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31} 143db00b6aeSshessdo_test fts3aa-3.2 { 144db00b6aeSshess execsql {SELECT rowid FROM t1 WHERE content MATCH 'one -two'} 145db00b6aeSshess} {1 5 9 13 17 21 25 29} 146db00b6aeSshessdo_test fts3aa-3.3 { 147db00b6aeSshess execsql {SELECT rowid FROM t1 WHERE content MATCH '-two one'} 148db00b6aeSshess} {1 5 9 13 17 21 25 29} 149db00b6aeSshess 150db00b6aeSshessdo_test fts3aa-4.1 { 151db00b6aeSshess execsql {SELECT rowid FROM t1 WHERE content MATCH 'one OR two'} 152db00b6aeSshess} {1 2 3 5 6 7 9 10 11 13 14 15 17 18 19 21 22 23 25 26 27 29 30 31} 153db00b6aeSshessdo_test fts3aa-4.2 { 154db00b6aeSshess execsql {SELECT rowid FROM t1 WHERE content MATCH '"one two" OR three'} 155db00b6aeSshess} {3 4 5 6 7 11 12 13 14 15 19 20 21 22 23 27 28 29 30 31} 156db00b6aeSshessdo_test fts3aa-4.3 { 157db00b6aeSshess execsql {SELECT rowid FROM t1 WHERE content MATCH 'three OR "one two"'} 158db00b6aeSshess} {3 4 5 6 7 11 12 13 14 15 19 20 21 22 23 27 28 29 30 31} 159db00b6aeSshessdo_test fts3aa-4.4 { 160db00b6aeSshess execsql {SELECT rowid FROM t1 WHERE content MATCH 'one two OR three'} 161db00b6aeSshess} {3 5 7 11 13 15 19 21 23 27 29 31} 162db00b6aeSshessdo_test fts3aa-4.5 { 163db00b6aeSshess execsql {SELECT rowid FROM t1 WHERE content MATCH 'three OR two one'} 164db00b6aeSshess} {3 5 7 11 13 15 19 21 23 27 29 31} 165db00b6aeSshessdo_test fts3aa-4.6 { 166db00b6aeSshess execsql {SELECT rowid FROM t1 WHERE content MATCH 'one two OR three OR four'} 167db00b6aeSshess} {3 5 7 9 11 13 15 19 21 23 25 27 29 31} 168db00b6aeSshessdo_test fts3aa-4.7 { 169db00b6aeSshess execsql {SELECT rowid FROM t1 WHERE content MATCH 'two OR three OR four one'} 170db00b6aeSshess} {3 5 7 9 11 13 15 19 21 23 25 27 29 31} 171db00b6aeSshess 172db00b6aeSshess# Test the ability to handle NULL content 173db00b6aeSshess# 174db00b6aeSshessdo_test fts3aa-5.1 { 175db00b6aeSshess execsql {INSERT INTO t1(content) VALUES(NULL)} 176db00b6aeSshess} {} 177db00b6aeSshessdo_test fts3aa-5.2 { 178db00b6aeSshess set rowid [db last_insert_rowid] 179db00b6aeSshess execsql {SELECT content FROM t1 WHERE rowid=$rowid} 180db00b6aeSshess} {{}} 181db00b6aeSshessdo_test fts3aa-5.3 { 182db00b6aeSshess execsql {SELECT rowid FROM t1 WHERE content MATCH NULL} 183db00b6aeSshess} {} 184db00b6aeSshess 185db00b6aeSshess# Test the ability to handle non-positive rowids 186db00b6aeSshess# 187db00b6aeSshessdo_test fts3aa-6.0 { 188db00b6aeSshess execsql {INSERT INTO t1(rowid, content) VALUES(0, 'four five')} 189db00b6aeSshess} {} 190db00b6aeSshessdo_test fts3aa-6.1 { 191db00b6aeSshess execsql {SELECT content FROM t1 WHERE rowid = 0} 192db00b6aeSshess} {{four five}} 193db00b6aeSshessdo_test fts3aa-6.2 { 194db00b6aeSshess execsql {INSERT INTO t1(rowid, content) VALUES(-1, 'three four')} 195db00b6aeSshess} {} 196db00b6aeSshessdo_test fts3aa-6.3 { 197db00b6aeSshess execsql {SELECT content FROM t1 WHERE rowid = -1} 198db00b6aeSshess} {{three four}} 199db00b6aeSshessdo_test fts3aa-6.4 { 200db00b6aeSshess execsql {SELECT rowid FROM t1 WHERE t1 MATCH 'four'} 201db00b6aeSshess} {-1 0 8 9 10 11 12 13 14 15 24 25 26 27 28 29 30 31} 202db00b6aeSshess 203ccc7ff4dSdan# Test creation of FTS3 and FTS4 tables with columns that contain 204ccc7ff4dSdan# an "=" character. 205ccc7ff4dSdan# 206ccc7ff4dSdando_execsql_test fts3aa-7.1 { 207ccc7ff4dSdan CREATE VIRTUAL TABLE t2 USING fts3(xyz=abc); 208ccc7ff4dSdan SELECT xyz FROM t2; 209ccc7ff4dSdan} {} 210ccc7ff4dSdando_catchsql_test fts3aa-7.2 { 211ccc7ff4dSdan CREATE VIRTUAL TABLE t3 USING fts4(xyz=abc); 212ccc7ff4dSdan} {1 {unrecognized parameter: xyz=abc}} 213ccc7ff4dSdando_catchsql_test fts3aa-7.3 { 214ccc7ff4dSdan CREATE VIRTUAL TABLE t3 USING fts4(xyz = abc); 215ccc7ff4dSdan} {1 {unrecognized parameter: xyz = abc}} 216ccc7ff4dSdan 217ccc7ff4dSdando_execsql_test fts3aa-7.4 { 218ccc7ff4dSdan CREATE VIRTUAL TABLE t3 USING fts3(tokenize=simple, tokenize=simple); 219ccc7ff4dSdan SELECT tokenize FROM t3; 220ccc7ff4dSdan} {} 221ccc7ff4dSdando_catchsql_test fts3aa-7.5 { 222ccc7ff4dSdan CREATE VIRTUAL TABLE t4 USING fts4(tokenize=simple, tokenize=simple); 223ccc7ff4dSdan} {1 {unrecognized parameter: tokenize=simple}} 224ccc7ff4dSdan 2251586699cSdando_execsql_test 8.0 { 2261586699cSdan CREATE VIRTUAL TABLE t0 USING fts4(order=desc); 2271586699cSdan BEGIN; 2281586699cSdan INSERT INTO t0(rowid, content) VALUES(1, 'abc'); 2291586699cSdan UPDATE t0 SET docid=5 WHERE docid=1; 2301586699cSdan INSERT INTO t0(rowid, content) VALUES(6, 'abc'); 2311586699cSdan} 2321586699cSdando_execsql_test 8.1 { 2331586699cSdan SELECT docid FROM t0 WHERE t0 MATCH 'abc'; 2341586699cSdan} {6 5} 2351586699cSdando_execsql_test 8.2 { 2361586699cSdan SELECT docid FROM t0 WHERE t0 MATCH '"abc abc"'; 2371586699cSdan} {} 2381586699cSdando_execsql_test 8.3 { COMMIT } 2391586699cSdando_execsql_test 8.4 { 2401586699cSdan SELECT docid FROM t0 WHERE t0 MATCH 'abc'; 2411586699cSdan} {6 5} 2421586699cSdando_execsql_test 8.5 { 2431586699cSdan SELECT docid FROM t0 WHERE t0 MATCH '"abc abc"'; 2441586699cSdan} {} 2451586699cSdan 246ddf47470Sdando_execsql_test 9.1 { 247ddf47470Sdan CREATE VIRTUAL TABLE t9 USING fts4(a, "", '---'); 248ddf47470Sdan} 249ddf47470Sdando_execsql_test 9.2 { 250ddf47470Sdan CREATE VIRTUAL TABLE t10 USING fts3(<, b, c); 251ddf47470Sdan} 252ddf47470Sdan 253*1ea0443cSdando_execsql_test 10.0 { 254*1ea0443cSdan CREATE VIRTUAL TABLE z1 USING fts3; 255*1ea0443cSdan INSERT INTO z1 VALUES('one two three'),('four one five'),('six two five'); 256*1ea0443cSdan CREATE TRIGGER z1r1 AFTER DELETE ON z1_content BEGIN 257*1ea0443cSdan DELETE FROM z1; 258*1ea0443cSdan END; 259*1ea0443cSdan} 260*1ea0443cSdando_catchsql_test 10.1 { 261*1ea0443cSdan DELETE FROM z1; 262*1ea0443cSdan} {1 {SQL logic error}} 263*1ea0443cSdan 264eab0e103Sdanexpand_all_sql db 265db00b6aeSshessfinish_test 266