sqlite
[Ported from github.com/sqlite/sqlite] Fix bugs in and improve the interface to the ".check" command of the CLI.
Brought by drakestapleton
sqlite / ext / fts5 / test / fts5colset.test
| 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 | do_execsql_test 6.0 { |
| 106 | CREATE VIRTUAL TABLE t3 USING fts5(c0); |
| 107 | INSERT INTO t3(rowid, c0) VALUES(1, 'x'); |
| 108 | INSERT INTO t3(rowid, c0) VALUES(2, 'x b z'); |
| 109 | } |
| 110 | |
| 111 | do_execsql_test 6.1 { |
| 112 | SELECT rowid FROM t3 WHERE t3 MATCH 'z' |
| 113 | } {2} |
| 114 | do_execsql_test 6.2 { |
| 115 | SELECT rowid FROM t3 WHERE t3 MATCH 'b OR -{c0} : x' |
| 116 | } {2} |
| 117 | |
| 118 | do_execsql_test 6.3 { |
| 119 | SELECT rowid FROM t3 WHERE t3 MATCH 'z NOT (b OR c0 : x)'; |
| 120 | } {} |
| 121 | do_execsql_test 6.4 { |
| 122 | SELECT rowid FROM t3 WHERE t3 MATCH 'z NOT b'; |
| 123 | } {} |
| 124 | do_execsql_test 6.5 { |
| 125 | SELECT rowid FROM t3 WHERE t3 MATCH 'z NOT (b OR -{c0} : q)'; |
| 126 | } {} |
| 127 | |
| 128 | do_execsql_test 6.6 { |
| 129 | SELECT rowid FROM t3 WHERE t3 MATCH 'z NOT (b OR -{c0} : x)'; |
| 130 | } {} |
| 131 | |
| 132 | do_execsql_test 6.7 { |
| 133 | CREATE VIRTUAL TABLE t4 USING fts5(c0); |
| 134 | INSERT INTO t4(rowid, c0) VALUES(1, 'a'); |
| 135 | INSERT INTO t4(rowid, c0) VALUES(2, 'a'); |
| 136 | SELECT rowid FROM t4 WHERE t4 MATCH 'a AND (-{c0} : a)'; |
| 137 | } {} |
| 138 | |
| 139 | |
| 140 | finish_test |