3 # The author disclaims copyright to this source code. In place of
4 # a legal notice, here is a blessing:
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.
10 #*************************************************************************
11 # This file implements regression tests for SQLite library. The
12 # focus of this script is testing the FTS5 module.
14 # Specifically, the auxiliary function "highlight".
17 source [file join [file dirname [info script]] fts5_common.tcl]
20 # If SQLITE_ENABLE_FTS5 is defined, omit this file.
26 foreach_detail_mode $testprefix {
29 CREATE VIRTUAL TABLE ft1 USING fts5(x, detail=%DETAIL%);
30 INSERT INTO ft1 VALUES('i d d a g i b g d d');
31 INSERT INTO ft1 VALUES('h d b j c c g a c a');
32 INSERT INTO ft1 VALUES('e j a e f h b f h h');
33 INSERT INTO ft1 VALUES('j f h d g h i b d f');
34 INSERT INTO ft1 VALUES('d c j d c j b c g e');
35 INSERT INTO ft1 VALUES('i a d e g j g d a a');
36 INSERT INTO ft1 VALUES('j f c e d a h j d b');
37 INSERT INTO ft1 VALUES('i c c f a d g h j e');
38 INSERT INTO ft1 VALUES('i d i g c d c h b f');
39 INSERT INTO ft1 VALUES('g d a e h a b c f j');
41 CREATE VIRTUAL TABLE ft2 USING fts5(x, detail=%DETAIL%);
42 INSERT INTO ft2 VALUES('a b c d e f g h i j');
46 SELECT highlight(ft1, 0, '[', ']') FROM ft1 WHERE ft1 MATCH 'e';
48 {[e] j a [e] f h b f h h}
49 {d c j d c j b c g [e]}
50 {i a d [e] g j g d a a}
51 {j f c [e] d a h j d b}
52 {i c c f a d g h j [e]}
53 {g d a [e] h a b c f j}
57 SELECT highlight(ft1, 0, '[', ']') FROM ft1 WHERE ft1 MATCH 'e e e'
59 {[e] j a [e] f h b f h h}
60 {d c j d c j b c g [e]}
61 {i a d [e] g j g d a a}
62 {j f c [e] d a h j d b}
63 {i c c f a d g h j [e]}
64 {g d a [e] h a b c f j}
68 SELECT highlight(ft2, 0, '[', ']') FROM ft2 WHERE ft2 MATCH 'f d'
70 {a b c [d] e [f] g h i j}
74 SELECT highlight(ft2, 0, '[', ']') FROM ft2 WHERE ft2 MATCH 'd f'
76 {a b c [d] e [f] g h i j}
79 #-------------------------------------------------------------------------
80 # Tests below this point require detail=full.
81 #-------------------------------------------------------------------------
82 if {[detail_is_full]==0} continue
86 SELECT highlight(ft1, 0, '[', ']') FROM ft1 WHERE ft1 MATCH 'h + d';
88 {[h d] b j c c g a c a}
89 {j f [h d] g h i b d f}
93 SELECT highlight(ft1, 0, '[', ']') FROM ft1 WHERE ft1 MATCH 'd + d';
95 {i [d d] a g i b g [d d]}
99 SELECT highlight(ft1, 0, '[', ']') FROM ft1 WHERE ft1 MATCH 'd + d d + d';
101 {i [d d] a g i b g [d d]}
104 do_execsql_test 2.4 {
105 SELECT highlight(ft2, 0, '[', ']') FROM ft2 WHERE ft2 MATCH 'b+c+d c+d+e'
106 } {{a [b c d e] f g h i j}}
108 do_execsql_test 2.5 {
109 SELECT highlight(ft2, 0, '[', ']') FROM ft2 WHERE ft2 MATCH 'b+c+d e+f+g'
111 {a [b c d] [e f g] h i j}
114 do_execsql_test 2.6 {
115 SELECT highlight(ft2, 0, '[', ']') FROM ft2 WHERE ft2 MATCH 'b+c+d c'
117 {a [b c d] e f g h i j}
120 do_execsql_test 2.7 {
121 SELECT highlight(ft2, 0, '[', ']') FROM ft2 WHERE ft2 MATCH 'b+c c+d+e'
123 {a [b c d e] f g h i j}
126 #-------------------------------------------------------------------------
127 # The example from the docs.
129 do_execsql_test 3.1 {
131 CREATE VIRTUAL TABLE ft USING fts5(a, detail=%DETAIL%);
132 INSERT INTO ft VALUES('a b c x c d e');
133 INSERT INTO ft VALUES('a b c c d e');
134 INSERT INTO ft VALUES('a b c d e');
136 -- The following SELECT statement returns these three rows:
137 -- '[a b c] x [c d e]'
140 SELECT highlight(ft, 0, '[', ']') FROM ft WHERE ft MATCH 'a+b+c AND c+d+e';
147 do_execsql_test 3.2 {
148 SELECT highlight(ft, 0, NULL, NULL) FROM ft WHERE ft MATCH 'a+b+c AND c+d+e';
157 # 2023-04-06 https://sqlite.org/forum/forumpost/cae4367d9b
159 # This is not a test of FTS5, but rather a test of the of what happens to
160 # prepared statements that encounter SQLITE_SCHEMA while other prepared
161 # statements are running. The original problem POC used FTS5, and so
162 # is seems reasonable to put the test here.
164 # The vdbeaux24.test module in TH3 also tests this same behavior but
165 # without requiring FTS5 or an other extension.
169 do_execsql_test 4.0 {
170 CREATE TABLE t5(a PRIMARY KEY);
171 INSERT INTO t5 VALUES(0);
172 CREATE VIRTUAL TABLE t6 USING fts5(0);
177 WHERE ((0,0) IN (SELECT 0, LAG(0) OVER (PARTITION BY 0) FROM t6), 0)
180 SELECT max(a) FROM cte;