sl@0: # 2006 September 9 sl@0: # sl@0: # The author disclaims copyright to this source code. In place of sl@0: # a legal notice, here is a blessing: sl@0: # sl@0: # May you do good and not evil. sl@0: # May you find forgiveness for yourself and forgive others. sl@0: # May you share freely, never taking more than you give. sl@0: # sl@0: #************************************************************************* sl@0: # This file implements regression tests for SQLite library. The sl@0: # focus of this script is testing the FTS3 module. sl@0: # sl@0: # $Id: fts3aa.test,v 1.1 2007/08/20 17:38:42 shess Exp $ sl@0: # sl@0: sl@0: set testdir [file dirname $argv0] sl@0: source $testdir/tester.tcl sl@0: sl@0: # If SQLITE_ENABLE_FTS3 is defined, omit this file. sl@0: ifcapable !fts3 { sl@0: finish_test sl@0: return sl@0: } sl@0: sl@0: # Construct a full-text search table containing five keywords: sl@0: # one, two, three, four, and five, in various combinations. The sl@0: # rowid for each will be a bitmask for the elements it contains. sl@0: # sl@0: db eval { sl@0: CREATE VIRTUAL TABLE t1 USING fts3(content); sl@0: INSERT INTO t1(content) VALUES('one'); sl@0: INSERT INTO t1(content) VALUES('two'); sl@0: INSERT INTO t1(content) VALUES('one two'); sl@0: INSERT INTO t1(content) VALUES('three'); sl@0: INSERT INTO t1(content) VALUES('one three'); sl@0: INSERT INTO t1(content) VALUES('two three'); sl@0: INSERT INTO t1(content) VALUES('one two three'); sl@0: INSERT INTO t1(content) VALUES('four'); sl@0: INSERT INTO t1(content) VALUES('one four'); sl@0: INSERT INTO t1(content) VALUES('two four'); sl@0: INSERT INTO t1(content) VALUES('one two four'); sl@0: INSERT INTO t1(content) VALUES('three four'); sl@0: INSERT INTO t1(content) VALUES('one three four'); sl@0: INSERT INTO t1(content) VALUES('two three four'); sl@0: INSERT INTO t1(content) VALUES('one two three four'); sl@0: INSERT INTO t1(content) VALUES('five'); sl@0: INSERT INTO t1(content) VALUES('one five'); sl@0: INSERT INTO t1(content) VALUES('two five'); sl@0: INSERT INTO t1(content) VALUES('one two five'); sl@0: INSERT INTO t1(content) VALUES('three five'); sl@0: INSERT INTO t1(content) VALUES('one three five'); sl@0: INSERT INTO t1(content) VALUES('two three five'); sl@0: INSERT INTO t1(content) VALUES('one two three five'); sl@0: INSERT INTO t1(content) VALUES('four five'); sl@0: INSERT INTO t1(content) VALUES('one four five'); sl@0: INSERT INTO t1(content) VALUES('two four five'); sl@0: INSERT INTO t1(content) VALUES('one two four five'); sl@0: INSERT INTO t1(content) VALUES('three four five'); sl@0: INSERT INTO t1(content) VALUES('one three four five'); sl@0: INSERT INTO t1(content) VALUES('two three four five'); sl@0: INSERT INTO t1(content) VALUES('one two three four five'); sl@0: } sl@0: sl@0: do_test fts3aa-1.1 { sl@0: execsql {SELECT rowid FROM t1 WHERE content MATCH 'one'} sl@0: } {1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31} sl@0: do_test fts3aa-1.2 { sl@0: execsql {SELECT rowid FROM t1 WHERE content MATCH 'one two'} sl@0: } {3 7 11 15 19 23 27 31} sl@0: do_test fts3aa-1.3 { sl@0: execsql {SELECT rowid FROM t1 WHERE content MATCH 'two one'} sl@0: } {3 7 11 15 19 23 27 31} sl@0: do_test fts3aa-1.4 { sl@0: execsql {SELECT rowid FROM t1 WHERE content MATCH 'one two three'} sl@0: } {7 15 23 31} sl@0: do_test fts3aa-1.5 { sl@0: execsql {SELECT rowid FROM t1 WHERE content MATCH 'one three two'} sl@0: } {7 15 23 31} sl@0: do_test fts3aa-1.6 { sl@0: execsql {SELECT rowid FROM t1 WHERE content MATCH 'two three one'} sl@0: } {7 15 23 31} sl@0: do_test fts3aa-1.7 { sl@0: execsql {SELECT rowid FROM t1 WHERE content MATCH 'two one three'} sl@0: } {7 15 23 31} sl@0: do_test fts3aa-1.8 { sl@0: execsql {SELECT rowid FROM t1 WHERE content MATCH 'three one two'} sl@0: } {7 15 23 31} sl@0: do_test fts3aa-1.9 { sl@0: execsql {SELECT rowid FROM t1 WHERE content MATCH 'three two one'} sl@0: } {7 15 23 31} sl@0: do_test fts3aa-1.10 { sl@0: execsql {SELECT rowid FROM t1 WHERE content MATCH 'one two THREE'} sl@0: } {7 15 23 31} sl@0: do_test fts3aa-1.11 { sl@0: execsql {SELECT rowid FROM t1 WHERE content MATCH ' ONE Two three '} sl@0: } {7 15 23 31} sl@0: sl@0: do_test fts3aa-2.1 { sl@0: execsql {SELECT rowid FROM t1 WHERE content MATCH '"one"'} sl@0: } {1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31} sl@0: do_test fts3aa-2.2 { sl@0: execsql {SELECT rowid FROM t1 WHERE content MATCH '"one two"'} sl@0: } {3 7 11 15 19 23 27 31} sl@0: do_test fts3aa-2.3 { sl@0: execsql {SELECT rowid FROM t1 WHERE content MATCH '"two one"'} sl@0: } {} sl@0: do_test fts3aa-2.4 { sl@0: execsql {SELECT rowid FROM t1 WHERE content MATCH '"one two three"'} sl@0: } {7 15 23 31} sl@0: do_test fts3aa-2.5 { sl@0: execsql {SELECT rowid FROM t1 WHERE content MATCH '"one three two"'} sl@0: } {} sl@0: do_test fts3aa-2.6 { sl@0: execsql {SELECT rowid FROM t1 WHERE content MATCH '"one two three four"'} sl@0: } {15 31} sl@0: do_test fts3aa-2.7 { sl@0: execsql {SELECT rowid FROM t1 WHERE content MATCH '"one three two four"'} sl@0: } {} sl@0: do_test fts3aa-2.8 { sl@0: execsql {SELECT rowid FROM t1 WHERE content MATCH '"one three five"'} sl@0: } {21} sl@0: do_test fts3aa-2.9 { sl@0: execsql {SELECT rowid FROM t1 WHERE content MATCH '"one three" five'} sl@0: } {21 29} sl@0: do_test fts3aa-2.10 { sl@0: execsql {SELECT rowid FROM t1 WHERE content MATCH 'five "one three"'} sl@0: } {21 29} sl@0: do_test fts3aa-2.11 { sl@0: execsql {SELECT rowid FROM t1 WHERE content MATCH 'five "one three" four'} sl@0: } {29} sl@0: do_test fts3aa-2.12 { sl@0: execsql {SELECT rowid FROM t1 WHERE content MATCH 'five four "one three"'} sl@0: } {29} sl@0: do_test fts3aa-2.13 { sl@0: execsql {SELECT rowid FROM t1 WHERE content MATCH '"one three" four five'} sl@0: } {29} sl@0: sl@0: do_test fts3aa-3.1 { sl@0: execsql {SELECT rowid FROM t1 WHERE content MATCH 'one'} sl@0: } {1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31} sl@0: do_test fts3aa-3.2 { sl@0: execsql {SELECT rowid FROM t1 WHERE content MATCH 'one -two'} sl@0: } {1 5 9 13 17 21 25 29} sl@0: do_test fts3aa-3.3 { sl@0: execsql {SELECT rowid FROM t1 WHERE content MATCH '-two one'} sl@0: } {1 5 9 13 17 21 25 29} sl@0: sl@0: do_test fts3aa-4.1 { sl@0: execsql {SELECT rowid FROM t1 WHERE content MATCH 'one OR two'} sl@0: } {1 2 3 5 6 7 9 10 11 13 14 15 17 18 19 21 22 23 25 26 27 29 30 31} sl@0: do_test fts3aa-4.2 { sl@0: execsql {SELECT rowid FROM t1 WHERE content MATCH '"one two" OR three'} sl@0: } {3 4 5 6 7 11 12 13 14 15 19 20 21 22 23 27 28 29 30 31} sl@0: do_test fts3aa-4.3 { sl@0: execsql {SELECT rowid FROM t1 WHERE content MATCH 'three OR "one two"'} sl@0: } {3 4 5 6 7 11 12 13 14 15 19 20 21 22 23 27 28 29 30 31} sl@0: do_test fts3aa-4.4 { sl@0: execsql {SELECT rowid FROM t1 WHERE content MATCH 'one two OR three'} sl@0: } {3 5 7 11 13 15 19 21 23 27 29 31} sl@0: do_test fts3aa-4.5 { sl@0: execsql {SELECT rowid FROM t1 WHERE content MATCH 'three OR two one'} sl@0: } {3 5 7 11 13 15 19 21 23 27 29 31} sl@0: do_test fts3aa-4.6 { sl@0: execsql {SELECT rowid FROM t1 WHERE content MATCH 'one two OR three OR four'} sl@0: } {3 5 7 9 11 13 15 19 21 23 25 27 29 31} sl@0: do_test fts3aa-4.7 { sl@0: execsql {SELECT rowid FROM t1 WHERE content MATCH 'two OR three OR four one'} sl@0: } {3 5 7 9 11 13 15 19 21 23 25 27 29 31} sl@0: sl@0: # Test the ability to handle NULL content sl@0: # sl@0: do_test fts3aa-5.1 { sl@0: execsql {INSERT INTO t1(content) VALUES(NULL)} sl@0: } {} sl@0: do_test fts3aa-5.2 { sl@0: set rowid [db last_insert_rowid] sl@0: execsql {SELECT content FROM t1 WHERE rowid=$rowid} sl@0: } {{}} sl@0: do_test fts3aa-5.3 { sl@0: execsql {SELECT rowid FROM t1 WHERE content MATCH NULL} sl@0: } {} sl@0: sl@0: # Test the ability to handle non-positive rowids sl@0: # sl@0: do_test fts3aa-6.0 { sl@0: execsql {INSERT INTO t1(rowid, content) VALUES(0, 'four five')} sl@0: } {} sl@0: do_test fts3aa-6.1 { sl@0: execsql {SELECT content FROM t1 WHERE rowid = 0} sl@0: } {{four five}} sl@0: do_test fts3aa-6.2 { sl@0: execsql {INSERT INTO t1(rowid, content) VALUES(-1, 'three four')} sl@0: } {} sl@0: do_test fts3aa-6.3 { sl@0: execsql {SELECT content FROM t1 WHERE rowid = -1} sl@0: } {{three four}} sl@0: do_test fts3aa-6.4 { sl@0: execsql {SELECT rowid FROM t1 WHERE t1 MATCH 'four'} sl@0: } {-1 0 8 9 10 11 12 13 14 15 24 25 26 27 28 29 30 31} sl@0: sl@0: finish_test