| 1 |
# 2017 November 25 |
| 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 |
|
| 12 |
source [file join [file dirname [info script]] fts5_common.tcl] |
| 13 |
set testprefix fts5first |
| 14 |
|
| 15 |
ifcapable !fts5 { |
| 16 |
finish_test |
| 17 |
return |
| 18 |
} |
| 19 |
|
| 20 |
|
| 21 |
do_execsql_test 1.0 { |
| 22 |
CREATE VIRTUAL TABLE x1 USING fts5(a, b); |
| 23 |
} |
| 24 |
|
| 25 |
unset -nocomplain res |
| 26 |
foreach {tn expr ok} { |
| 27 |
1 {^abc} 1 |
| 28 |
2 {^abc + def} 1 |
| 29 |
3 {^ "abc def"} 1 |
| 30 |
4 {^"abc def"} 1 |
| 31 |
5 {abc ^def} 1 |
| 32 |
6 {abc + ^def} 0 |
| 33 |
7 {abc ^+ def} 0 |
| 34 |
8 {"^abc"} 1 |
| 35 |
9 {NEAR(^abc def)} 0 |
| 36 |
} { |
| 37 |
set res(0) {/1 {fts5: syntax error near .*}/} |
| 38 |
set res(1) {0 {}} |
| 39 |
|
| 40 |
do_catchsql_test 1.$tn { SELECT * FROM x1($expr) } $res($ok) |
| 41 |
} |
| 42 |
|
| 43 |
#------------------------------------------------------------------------- |
| 44 |
# |
| 45 |
do_execsql_test 2.0 { |
| 46 |
INSERT INTO x1 VALUES('a b c', 'b c a'); |
| 47 |
} |
| 48 |
|
| 49 |
foreach {tn expr match} { |
| 50 |
1 {^a} 1 |
| 51 |
2 {^b} 1 |
| 52 |
3 {^c} 0 |
| 53 |
4 {^a + b} 1 |
| 54 |
5 {^b + c} 1 |
| 55 |
6 {^c + a} 0 |
| 56 |
7 {^"c a"} 0 |
| 57 |
8 {a:^a} 1 |
| 58 |
9 {a:^b} 0 |
| 59 |
10 {a:^"a b"} 1 |
| 60 |
} { |
| 61 |
do_execsql_test 2.$tn { SELECT EXISTS (SELECT rowid FROM x1($expr)) } $match |
| 62 |
} |
| 63 |
|
| 64 |
#------------------------------------------------------------------------- |
| 65 |
# |
| 66 |
do_execsql_test 3.0 { |
| 67 |
DELETE FROM x1; |
| 68 |
INSERT INTO x1 VALUES('b a', 'c a'); |
| 69 |
INSERT INTO x1 VALUES('a a', 'c c'); |
| 70 |
INSERT INTO x1 VALUES('a b', 'a a'); |
| 71 |
} |
| 72 |
fts5_aux_test_functions db |
| 73 |
|
| 74 |
foreach {tn expr expect} { |
| 75 |
1 {^a} {{2 1}} |
| 76 |
2 {^c AND ^b} {{0 2} {1 0}} |
| 77 |
} { |
| 78 |
do_execsql_test 3.$tn { |
| 79 |
SELECT fts5_test_queryphrase(x1) FROM x1($expr) LIMIT 1 |
| 80 |
} [list $expect] |
| 81 |
} |
| 82 |
|
| 83 |
#------------------------------------------------------------------------- |
| 84 |
# |
| 85 |
do_execsql_test 3.1 { |
| 86 |
CREATE VIRTUAL TABLE x2 USING fts5(a, b, c, detail=column); |
| 87 |
} |
| 88 |
|
| 89 |
do_catchsql_test 3.2 { |
| 90 |
SELECT * FROM x2('a + b'); |
| 91 |
} {1 {fts5: phrase queries are not supported (detail!=full)}} |
| 92 |
|
| 93 |
do_catchsql_test 3.3 { |
| 94 |
SELECT * FROM x2('^a'); |
| 95 |
} {1 {fts5: phrase queries are not supported (detail!=full)}} |
| 96 |
finish_test |