interplane.Get Omega
Read in your language

sqlite

[Ported from github.com/sqlite/sqlite] Fix bugs in and improve the interface to the ".check" command of the CLI.

Brought by drakestapleton

branch master Branches Tags History

sqlite / ext / fts5 / test / fts5prefix2.test

104 lines · 2604 bytes Raw Blame History
1# 2020 Dec 3
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# This file contains tests focused on prefix indexes.
13#
14
15source [file join [file dirname [info script]] fts5_common.tcl]
16set testprefix fts5prefix2
17
18# If SQLITE_ENABLE_FTS5 is not defined, omit this file.
19ifcapable !fts5 {
20 finish_test
21 return
22}
23
24foreach p {3 2 1} {
25 reset_db
26 do_execsql_test 1.$p.0 "
27 CREATE VIRTUAL TABLE t1 USING fts5(xyz, prefix=$p);
28 "
29 do_execsql_test 1.$p.1 {
30 INSERT INTO t1 VALUES
31 ('May you do good and not evil.'),
32 ('May you find forgiveness for yourself and forgive others.'),
33 ('May you share freely, never taking more than you give f.');
34 }
35
36 do_execsql_test 1.$p.2 {
37 SELECT highlight(t1, 0, '[', ']') FROM t1('f*');
38 } {
39 {May you [find] [forgiveness] [for] yourself and [forgive] others.}
40 {May you share [freely], never taking more than you give [f].}
41 }
42}
43
44do_execsql_test 2.0 {
45 CREATE VIRTUAL TABLE t2 USING fts5(one, prefix=3);
46 INSERT INTO t2 VALUES('top');
47 INSERT INTO t2 VALUES('to');
48 INSERT INTO t2 VALUES('tommy');
49}
50
51do_execsql_test 2.1 {
52 SELECT * FROM t2('to*');
53} {top to tommy}
54
55#-------------------------------------------------------------------------
56
57foreach {tn newrowid} {
58 1 122
59 2 123
60 3 124
61} {
62 reset_db
63 do_execsql_test 3.$tn.0 {
64 CREATE VIRTUAL TABLE t12 USING fts5(x);
65 INSERT INTO t12(rowid, x) VALUES(123, 'wwww');
66 }
67 do_execsql_test 3.$tn.1 {
68 BEGIN;
69 DELETE FROM t12 WHERE rowid=123;
70 SELECT * FROM t12('wwww*');
71 INSERT INTO t12(rowid, x) VALUES($newrowid, 'wwww');
72 SELECT * FROM t12('wwww*');
73 END;
74 } {wwww}
75 do_execsql_test 3.$tn.2 {
76 INSERT INTO t12(t12) VALUES('integrity-check');
77 }
78 do_execsql_test 3.$tn.3 {
79 SELECT rowid FROM t12('wwww*');
80 } $newrowid
81}
82
83#-------------------------------------------------------------------------
84foreach_detail_mode $::testprefix-4 {
85 reset_db
86 do_execsql_test 1 {
87 CREATE VIRTUAL TABLE t1 USING fts5(x, detail=%DETAIL%);
88 WITH RECURSIVE c(x) AS (
89 VALUES(1) UNION ALL SELECT x+1 FROM c WHERE x<55
90 )
91 INSERT INTO t1(rowid, x) SELECT x,'ab' FROM c;
92 INSERT INTO t1(rowid, x) VALUES(-9223372036854775808,'abc');
93 }
94
95 do_execsql_test 2 {
96 SELECT count(*) FROM t1('a*')
97 } {56}
98}
99
100finish_test
101
102
103
104finish_test