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 #***********************************************************************
12 # This file focuses on the code in fts5_config.c, which is largely concerned
13 # with parsing the various configuration and CREATE TABLE options.
16 source [file join [file dirname [info script]] fts5_common.tcl]
17 set testprefix fts5config
19 # If SQLITE_ENABLE_FTS5 is defined, omit this file.
25 #-------------------------------------------------------------------------
26 # Try different types of quote characters.
29 CREATE VIRTUAL TABLE t1 USING fts5('a', "b", [c], `d`);
30 PRAGMA table_info = t1;
38 #-------------------------------------------------------------------------
39 # Syntax errors in the prefix= option.
50 set res [list 1 {malformed prefix=... directive}]
51 do_catchsql_test 2.$tn "CREATE VIRTUAL TABLE f1 USING fts5(x, $opt)" $res
54 #-------------------------------------------------------------------------
55 # Syntax errors in the 'rank' option.
67 do_catchsql_test 3.$tn {
68 INSERT INTO t1(t1, rank) VALUES('rank', $val);
69 } {1 {SQL logic error or missing database}}
72 #-------------------------------------------------------------------------
73 # The parsing of SQL literals specified as part of 'rank' options.
76 CREATE VIRTUAL TABLE zzz USING fts5(one);
77 INSERT INTO zzz VALUES('a b c');
79 proc first {cmd A} { return $A }
80 sqlite3_fts5_create_function db first first
84 2 "'01234567890ABCDEF'"
87 5 "x'0123456789ABCDEF'"
88 6 "x'0123456789abcdef'"
95 set func [string map {' ''} "first($arg)"]
96 do_execsql_test 4.1.$tn "
97 INSERT INTO zzz(zzz, rank) VALUES('rank', '$func');
98 SELECT rank IS $arg FROM zzz WHERE zzz MATCH 'a + b + c'
102 do_execsql_test 4.2 {
103 INSERT INTO zzz(zzz, rank) VALUES('rank', 'f1()');
106 #-------------------------------------------------------------------------
107 # Misquoting in tokenize= and other options.
109 do_catchsql_test 5.1 {
110 CREATE VIRTUAL TABLE xx USING fts5(x, tokenize="porter 'ascii");
111 } {1 {parse error in tokenize directive}}
114 do_catchsql_test 5.2 {
115 CREATE VIRTUAL TABLE xx USING fts5(x, [y[]);
118 do_catchsql_test 5.3 {
119 CREATE VIRTUAL TABLE yy USING fts5(x, [y]]);
120 } {1 {unrecognized token: "]"}}
122 #-------------------------------------------------------------------------
123 # Errors in prefix= directives.
125 do_catchsql_test 6.2 {
126 CREATE VIRTUAL TABLE abc USING fts5(a, prefix='1, 2, 1001');
127 } {1 {prefix length out of range (max 999)}}
128 do_catchsql_test 6.3 {
129 CREATE VIRTUAL TAbLE abc USING fts5(a, prefix='1, 2, 0000');
130 } {1 {prefix length out of range (max 999)}}
131 do_catchsql_test 6.4 {
132 CREATE VIRTUAL TABLE abc USING fts5(a, prefix='1 , 1000000');
133 } {1 {prefix length out of range (max 999)}}
135 #-------------------------------------------------------------------------
136 # Duplicate tokenize= and other options.
138 do_catchsql_test 7.1 {
139 CREATE VIRTUAL TABLE abc USING fts5(a, tokenize=porter, tokenize=ascii);
140 } {1 {multiple tokenize=... directives}}
141 do_catchsql_test 7.2 {
142 CREATE VIRTUAL TABLE abc USING fts5(a, content=porter, content=ascii);
143 } {1 {multiple content=... directives}}
144 do_catchsql_test 7.3 {
145 CREATE VIRTUAL TABLE abc USING fts5(a, content_rowid=porter, content_rowid=a);
146 } {1 {multiple content_rowid=... directives}}
148 #-------------------------------------------------------------------------
149 # Unrecognized option.
151 do_catchsql_test 8.0 {
152 CREATE VIRTUAL TABLE abc USING fts5(a, nosuchoption=123);
153 } {1 {unrecognized option: "nosuchoption"}}
154 do_catchsql_test 8.1 {
155 CREATE VIRTUAL TABLE abc USING fts5(a, "nosuchoption"=123);
156 } {1 {parse error in ""nosuchoption"=123"}}
158 #-------------------------------------------------------------------------
161 # 9.1.* 'pgsz' options.
162 # 9.2.* 'automerge' options.
163 # 9.3.* 'crisismerge' options.
164 # 9.4.* a non-existant option.
165 # 9.5.* 'hashsize' options.
167 do_execsql_test 9.0 {
168 CREATE VIRTUAL TABLE abc USING fts5(a, b);
170 do_catchsql_test 9.1.1 {
171 INSERT INTO abc(abc, rank) VALUES('pgsz', -5);
172 } {1 {SQL logic error or missing database}}
173 do_catchsql_test 9.1.2 {
174 INSERT INTO abc(abc, rank) VALUES('pgsz', 50000000);
175 } {1 {SQL logic error or missing database}}
176 do_catchsql_test 9.1.3 {
177 INSERT INTO abc(abc, rank) VALUES('pgsz', 66.67);
178 } {1 {SQL logic error or missing database}}
180 do_catchsql_test 9.2.1 {
181 INSERT INTO abc(abc, rank) VALUES('automerge', -5);
182 } {1 {SQL logic error or missing database}}
183 do_catchsql_test 9.2.2 {
184 INSERT INTO abc(abc, rank) VALUES('automerge', 50000000);
185 } {1 {SQL logic error or missing database}}
186 do_catchsql_test 9.2.3 {
187 INSERT INTO abc(abc, rank) VALUES('automerge', 66.67);
188 } {1 {SQL logic error or missing database}}
189 do_execsql_test 9.2.4 {
190 INSERT INTO abc(abc, rank) VALUES('automerge', 1);
193 do_catchsql_test 9.3.1 {
194 INSERT INTO abc(abc, rank) VALUES('crisismerge', -5);
195 } {1 {SQL logic error or missing database}}
196 do_catchsql_test 9.3.2 {
197 INSERT INTO abc(abc, rank) VALUES('crisismerge', 66.67);
198 } {1 {SQL logic error or missing database}}
199 do_execsql_test 9.3.3 {
200 INSERT INTO abc(abc, rank) VALUES('crisismerge', 1);
202 do_execsql_test 9.3.4 {
203 INSERT INTO abc(abc, rank) VALUES('crisismerge', 50000000);
206 do_catchsql_test 9.4.1 {
207 INSERT INTO abc(abc, rank) VALUES('nosuchoption', 1);
208 } {1 {SQL logic error or missing database}}
210 do_catchsql_test 9.5.1 {
211 INSERT INTO abc(abc, rank) VALUES('hashsize', 'not an integer');
212 } {1 {SQL logic error or missing database}}
213 do_catchsql_test 9.5.2 {
214 INSERT INTO abc(abc, rank) VALUES('hashsize', -500000);
215 } {1 {SQL logic error or missing database}}
216 do_catchsql_test 9.5.3 {
217 INSERT INTO abc(abc, rank) VALUES('hashsize', 500000);
220 #-------------------------------------------------------------------------
221 # Too many prefix indexes. Maximum allowed is 31.
224 1 {prefix="1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32"}
225 2 {prefix="1 2 3 4", prefix="5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32"}
227 set sql "CREATE VIRTUAL TABLE xyz USING fts5(x, $spec)"
228 do_catchsql_test 10.$tn $sql {1 {too many prefix indexes (max 31)}}
231 #-------------------------------------------------------------------------
232 # errors in the detail= option.
242 set res [list 1 {malformed detail=... directive}]
243 do_catchsql_test 11.$tn "CREATE VIRTUAL TABLE f1 USING fts5(x, $opt)" $res
246 do_catchsql_test 12.1 {
247 INSERT INTO t1(t1, rank) VALUES('rank', NULL);;
248 } {1 {SQL logic error or missing database}}