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