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 19db00b6aeSshess 20db00b6aeSshess# If SQLITE_ENABLE_FTS3 is defined, omit this file. 21db00b6aeSshessifcapable !fts3 { 22db00b6aeSshess finish_test 23db00b6aeSshess return 24db00b6aeSshess} 25db00b6aeSshess 26db00b6aeSshess# Construct a full-text search table containing five keywords: 27db00b6aeSshess# one, two, three, four, and five, in various combinations. The 28db00b6aeSshess# rowid for each will be a bitmask for the elements it contains. 29db00b6aeSshess# 30db00b6aeSshessdb eval { 31db00b6aeSshess CREATE VIRTUAL TABLE t1 USING fts3(content); 32db00b6aeSshess INSERT INTO t1(content) VALUES('one'); 33db00b6aeSshess INSERT INTO t1(content) VALUES('two'); 34db00b6aeSshess INSERT INTO t1(content) VALUES('one two'); 35db00b6aeSshess INSERT INTO t1(content) VALUES('three'); 36db00b6aeSshess INSERT INTO t1(content) VALUES('one three'); 37db00b6aeSshess INSERT INTO t1(content) VALUES('two three'); 38db00b6aeSshess INSERT INTO t1(content) VALUES('one two three'); 39db00b6aeSshess INSERT INTO t1(content) VALUES('four'); 40db00b6aeSshess INSERT INTO t1(content) VALUES('one four'); 41db00b6aeSshess INSERT INTO t1(content) VALUES('two four'); 42db00b6aeSshess INSERT INTO t1(content) VALUES('one two four'); 43db00b6aeSshess INSERT INTO t1(content) VALUES('three four'); 44db00b6aeSshess INSERT INTO t1(content) VALUES('one three four'); 45db00b6aeSshess INSERT INTO t1(content) VALUES('two three four'); 46db00b6aeSshess INSERT INTO t1(content) VALUES('one two three four'); 47db00b6aeSshess INSERT INTO t1(content) VALUES('five'); 48db00b6aeSshess INSERT INTO t1(content) VALUES('one five'); 49db00b6aeSshess INSERT INTO t1(content) VALUES('two five'); 50db00b6aeSshess INSERT INTO t1(content) VALUES('one two five'); 51db00b6aeSshess INSERT INTO t1(content) VALUES('three five'); 52db00b6aeSshess INSERT INTO t1(content) VALUES('one three five'); 53db00b6aeSshess INSERT INTO t1(content) VALUES('two three five'); 54db00b6aeSshess INSERT INTO t1(content) VALUES('one two three five'); 55db00b6aeSshess INSERT INTO t1(content) VALUES('four five'); 56db00b6aeSshess INSERT INTO t1(content) VALUES('one four five'); 57db00b6aeSshess INSERT INTO t1(content) VALUES('two four five'); 58db00b6aeSshess INSERT INTO t1(content) VALUES('one two four five'); 59db00b6aeSshess INSERT INTO t1(content) VALUES('three four five'); 60db00b6aeSshess INSERT INTO t1(content) VALUES('one three four five'); 61db00b6aeSshess INSERT INTO t1(content) VALUES('two three four five'); 62db00b6aeSshess INSERT INTO t1(content) VALUES('one two three four five'); 63db00b6aeSshess} 64db00b6aeSshess 65db00b6aeSshessdo_test fts3aa-1.1 { 66db00b6aeSshess execsql {SELECT rowid FROM t1 WHERE content MATCH 'one'} 67db00b6aeSshess} {1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31} 68db00b6aeSshessdo_test fts3aa-1.2 { 69db00b6aeSshess execsql {SELECT rowid FROM t1 WHERE content MATCH 'one two'} 70db00b6aeSshess} {3 7 11 15 19 23 27 31} 71db00b6aeSshessdo_test fts3aa-1.3 { 72db00b6aeSshess execsql {SELECT rowid FROM t1 WHERE content MATCH 'two one'} 73db00b6aeSshess} {3 7 11 15 19 23 27 31} 74db00b6aeSshessdo_test fts3aa-1.4 { 75db00b6aeSshess execsql {SELECT rowid FROM t1 WHERE content MATCH 'one two three'} 76db00b6aeSshess} {7 15 23 31} 77db00b6aeSshessdo_test fts3aa-1.5 { 78db00b6aeSshess execsql {SELECT rowid FROM t1 WHERE content MATCH 'one three two'} 79db00b6aeSshess} {7 15 23 31} 80db00b6aeSshessdo_test fts3aa-1.6 { 81db00b6aeSshess execsql {SELECT rowid FROM t1 WHERE content MATCH 'two three one'} 82db00b6aeSshess} {7 15 23 31} 83db00b6aeSshessdo_test fts3aa-1.7 { 84db00b6aeSshess execsql {SELECT rowid FROM t1 WHERE content MATCH 'two one three'} 85db00b6aeSshess} {7 15 23 31} 86db00b6aeSshessdo_test fts3aa-1.8 { 87db00b6aeSshess execsql {SELECT rowid FROM t1 WHERE content MATCH 'three one two'} 88db00b6aeSshess} {7 15 23 31} 89db00b6aeSshessdo_test fts3aa-1.9 { 90db00b6aeSshess execsql {SELECT rowid FROM t1 WHERE content MATCH 'three two one'} 91db00b6aeSshess} {7 15 23 31} 92db00b6aeSshessdo_test fts3aa-1.10 { 93db00b6aeSshess execsql {SELECT rowid FROM t1 WHERE content MATCH 'one two THREE'} 94db00b6aeSshess} {7 15 23 31} 95db00b6aeSshessdo_test fts3aa-1.11 { 96db00b6aeSshess execsql {SELECT rowid FROM t1 WHERE content MATCH ' ONE Two three '} 97db00b6aeSshess} {7 15 23 31} 98db00b6aeSshess 99db00b6aeSshessdo_test fts3aa-2.1 { 100db00b6aeSshess execsql {SELECT rowid FROM t1 WHERE content MATCH '"one"'} 101db00b6aeSshess} {1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31} 102db00b6aeSshessdo_test fts3aa-2.2 { 103db00b6aeSshess execsql {SELECT rowid FROM t1 WHERE content MATCH '"one two"'} 104db00b6aeSshess} {3 7 11 15 19 23 27 31} 105db00b6aeSshessdo_test fts3aa-2.3 { 106db00b6aeSshess execsql {SELECT rowid FROM t1 WHERE content MATCH '"two one"'} 107db00b6aeSshess} {} 108db00b6aeSshessdo_test fts3aa-2.4 { 109db00b6aeSshess execsql {SELECT rowid FROM t1 WHERE content MATCH '"one two three"'} 110db00b6aeSshess} {7 15 23 31} 111db00b6aeSshessdo_test fts3aa-2.5 { 112db00b6aeSshess execsql {SELECT rowid FROM t1 WHERE content MATCH '"one three two"'} 113db00b6aeSshess} {} 114db00b6aeSshessdo_test fts3aa-2.6 { 115db00b6aeSshess execsql {SELECT rowid FROM t1 WHERE content MATCH '"one two three four"'} 116db00b6aeSshess} {15 31} 117db00b6aeSshessdo_test fts3aa-2.7 { 118db00b6aeSshess execsql {SELECT rowid FROM t1 WHERE content MATCH '"one three two four"'} 119db00b6aeSshess} {} 120db00b6aeSshessdo_test fts3aa-2.8 { 121db00b6aeSshess execsql {SELECT rowid FROM t1 WHERE content MATCH '"one three five"'} 122db00b6aeSshess} {21} 123db00b6aeSshessdo_test fts3aa-2.9 { 124db00b6aeSshess execsql {SELECT rowid FROM t1 WHERE content MATCH '"one three" five'} 125db00b6aeSshess} {21 29} 126db00b6aeSshessdo_test fts3aa-2.10 { 127db00b6aeSshess execsql {SELECT rowid FROM t1 WHERE content MATCH 'five "one three"'} 128db00b6aeSshess} {21 29} 129db00b6aeSshessdo_test fts3aa-2.11 { 130db00b6aeSshess execsql {SELECT rowid FROM t1 WHERE content MATCH 'five "one three" four'} 131db00b6aeSshess} {29} 132db00b6aeSshessdo_test fts3aa-2.12 { 133db00b6aeSshess execsql {SELECT rowid FROM t1 WHERE content MATCH 'five four "one three"'} 134db00b6aeSshess} {29} 135db00b6aeSshessdo_test fts3aa-2.13 { 136db00b6aeSshess execsql {SELECT rowid FROM t1 WHERE content MATCH '"one three" four five'} 137db00b6aeSshess} {29} 138db00b6aeSshess 139db00b6aeSshessdo_test fts3aa-3.1 { 140db00b6aeSshess execsql {SELECT rowid FROM t1 WHERE content MATCH 'one'} 141db00b6aeSshess} {1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31} 142db00b6aeSshessdo_test fts3aa-3.2 { 143db00b6aeSshess execsql {SELECT rowid FROM t1 WHERE content MATCH 'one -two'} 144db00b6aeSshess} {1 5 9 13 17 21 25 29} 145db00b6aeSshessdo_test fts3aa-3.3 { 146db00b6aeSshess execsql {SELECT rowid FROM t1 WHERE content MATCH '-two one'} 147db00b6aeSshess} {1 5 9 13 17 21 25 29} 148db00b6aeSshess 149*09977bb9Sdanbreakpoint 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}} 199*09977bb9Sdanbreakpoint 200db00b6aeSshessdo_test fts3aa-6.4 { 201db00b6aeSshess execsql {SELECT rowid FROM t1 WHERE t1 MATCH 'four'} 202db00b6aeSshess} {-1 0 8 9 10 11 12 13 14 15 24 25 26 27 28 29 30 31} 203db00b6aeSshess 204db00b6aeSshessfinish_test 205