| 1 |
# 2016 August 10 |
| 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 FTS5 module. |
| 13 |
# |
| 14 |
|
| 15 |
source [file join [file dirname [info script]] fts5_common.tcl] |
| 16 |
set testprefix fts5colset |
| 17 |
|
| 18 |
# If SQLITE_ENABLE_FTS5 is not defined, omit this file. |
| 19 |
ifcapable !fts5 { |
| 20 |
finish_test |
| 21 |
return |
| 22 |
} |
| 23 |
|
| 24 |
foreach_detail_mode $::testprefix { |
| 25 |
if {[detail_is_none]} continue |
| 26 |
|
| 27 |
do_execsql_test 1.0 { |
| 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 |
| 33 |
} |
| 34 |
|
| 35 |
foreach {tn q res} { |
| 36 |
1 "a" {1 2 3 4} |
| 37 |
2 "{a} : a" {1} |
| 38 |
3 "-{a} : a" {2 3 4} |
| 39 |
4 "- {a c} : a" {2 4} |
| 40 |
5 " - {d d c} : a" {1 2} |
| 41 |
6 "- {d c b a} : a" {} |
| 42 |
7 "-{\"a\"} : b" {1 2 3} |
| 43 |
8 "- c : a" {1 2 4} |
| 44 |
9 "-c : a" {1 2 4} |
| 45 |
10 "-\"c\" : a" {1 2 4} |
| 46 |
} { |
| 47 |
do_execsql_test 1.$tn { |
| 48 |
SELECT rowid FROM t1($q) |
| 49 |
} $res |
| 50 |
} |
| 51 |
|
| 52 |
foreach {tn q res} { |
| 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} |
| 61 |
} { |
| 62 |
do_execsql_test 2.$tn { |
| 63 |
SELECT rowid FROM t1($q) |
| 64 |
} $res |
| 65 |
} |
| 66 |
|
| 67 |
foreach {tn w res} { |
| 68 |
0 "a MATCH 'a'" {1} |
| 69 |
1 "b MATCH 'a'" {2} |
| 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} |
| 74 |
} { |
| 75 |
do_execsql_test 3.$tn " |
| 76 |
SELECT rowid FROM t1 WHERE $w |
| 77 |
" $res |
| 78 |
} |
| 79 |
|
| 80 |
do_catchsql_test 4.1 { |
| 81 |
SELECT * FROM t1 WHERE rowid MATCH 'a' |
| 82 |
} {1 {no query solution}} |
| 83 |
} |
| 84 |
|
| 85 |
#------------------------------------------------------------------------- |
| 86 |
# Confirm that the expression parser creates the same expression tree |
| 87 |
# for: |
| 88 |
# |
| 89 |
# {a b} : (abc AND def) |
| 90 |
# -{c d} : (abc AND def) |
| 91 |
# |
| 92 |
# Assuming that the table columns are (a, b, c, d). |
| 93 |
# |
| 94 |
do_execsql_test 5.1 { |
| 95 |
SELECT fts5_expr('abcd AND cdef'); |
| 96 |
} {{"abcd" AND "cdef"}} |
| 97 |
do_execsql_test 5.2 { |
| 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"}} |
| 103 |
|
| 104 |
|
| 105 |
finish_test |