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 FTS5 module.
15 source [file join [file dirname [info script]] fts5_common.tcl]
16 set testprefix fts5colset
18 # If SQLITE_ENABLE_FTS5 is not defined, omit this file.
24 foreach_detail_mode $::testprefix {
25 if {[detail_is_none]} continue
28 CREATE VIRTUAL TABLE t1 USING fts5(a, b, c, d, detail=%DETAIL%);
29 INSERT INTO t1 VALUES('a', 'b', 'c', 'd'); -- 1
30 INSERT INTO t1 VALUES('d', 'a', 'b', 'c'); -- 2
31 INSERT INTO t1 VALUES('c', 'd', 'a', 'b'); -- 3
32 INSERT INTO t1 VALUES('b', 'c', 'd', 'a'); -- 4
40 5 " - {d d c} : a" {1 2}
41 6 "- {d c b a} : a" {}
42 7 "-{\"a\"} : b" {1 2 3}
45 10 "-\"c\" : a" {1 2 4}
47 do_execsql_test 1.$tn {
48 SELECT rowid FROM t1($q)
53 0 {{a} : (a AND ":")} {}
54 1 "{a b c} : (a AND d)" {2 3}
55 2 "{a b c} : (a AND b:d)" {3}
56 3 "{a b c} : (a AND d:d)" {}
57 4 "{b} : ( {b a} : ( {c b a} : ( {d b c a} : ( d OR c ) ) ) )" {3 4}
58 5 "{a} : ( {b a} : ( {c b a} : ( {d b c a} : ( d OR c ) ) ) )" {2 3}
59 6 "{a} : ( {b a} : ( {c b} : ( {d b c a} : ( d OR c ) ) ) )" {}
60 7 "{a b c} : (b:a AND c:b)" {2}
62 do_execsql_test 2.$tn {
63 SELECT rowid FROM t1($q)
70 2 "b MATCH '{a b c} : a'" {2}
71 3 "b MATCH 'a OR b'" {1 2}
72 4 "b MATCH 'a OR a:b'" {2}
73 5 "b MATCH 'a OR b:b'" {1 2}
75 do_execsql_test 3.$tn "
76 SELECT rowid FROM t1 WHERE $w
80 do_catchsql_test 4.1 {
81 SELECT * FROM t1 WHERE rowid MATCH 'a'
82 } {1 {unable to use function MATCH in the requested context}}
85 #-------------------------------------------------------------------------
86 # Confirm that the expression parser creates the same expression tree
89 # {a b} : (abc AND def)
90 # -{c d} : (abc AND def)
92 # Assuming that the table columns are (a, b, c, d).
95 SELECT fts5_expr('abcd AND cdef');
96 } {{"abcd" AND "cdef"}}
98 SELECT fts5_expr('{a b} : (abcd AND cdef)', 'a', 'b', 'c', 'd');
99 } {{{a b} : "abcd" AND {a b} : "cdef"}}
100 do_execsql_test 5.3 {
101 SELECT fts5_expr('-{c d} : (abcd AND cdef)', 'a', 'b', 'c', 'd');
102 } {{{a b} : "abcd" AND {a b} : "cdef"}}