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 / fts5locale.test

779 lines · 20717 bytes Raw Blame History
1# 2014 Dec 20
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# Tests focusing on the built-in fts5 tokenizers.
13#
14
15source [file join [file dirname [info script]] fts5_common.tcl]
16set testprefix fts5locale
17
18# If SQLITE_ENABLE_FTS5 is not defined, omit this file.
19ifcapable !fts5 {
20 finish_test
21 return
22}
23
24proc transform_token {locale token} {
25 switch -- $locale {
26 reverse {
27 set ret ""
28 foreach c [split $token ""] {
29 set ret "$c$ret"
30 }
31 set token $ret
32 }
33
34 default {
35 # no-op
36 }
37 }
38
39 set token
40}
41
42proc tcl_create {args} { return "tcl_tokenize" }
43proc tcl_tokenize {tflags text} {
44 set iToken 1
45 set bSkip 0
46 if {[sqlite3_fts5_locale]=="second"} { set bSkip 1 }
47 foreach {w iStart iEnd} [fts5_tokenize_split $text] {
48 incr iToken
49 if {(($iToken) % ($bSkip + 1))} continue
50
51 set w [transform_token [sqlite3_fts5_locale] $w]
52 sqlite3_fts5_token $w $iStart $iEnd
53 }
54}
55
56#-------------------------------------------------------------------------
57# Check that queries can have a locale attached to them.
58#
59reset_db
60sqlite3_fts5_create_tokenizer -v2 db tcl tcl_create
61
62do_execsql_test 1.0 {
63 CREATE VIRTUAL TABLE t1 USING fts5(a, tokenize=tcl);
64 INSERT INTO t1 VALUES('abc');
65 INSERT INTO t1 VALUES('cba');
66} {}
67
68do_execsql_test 1.1 {
69 SELECT rowid, a FROM t1( fts5_locale('en_US', 'abc') );
70} {1 abc}
71
72do_execsql_test 1.2 {
73 SELECT rowid, a FROM t1( fts5_locale('reverse', 'abc') );
74} {2 cba}
75
76
77#-------------------------------------------------------------------------
78# Test that the locale= option exists and seems to accept values. And
79# that fts5_locale() values may only be inserted into an internal-content
80# table if the locale=1 option was specified.
81#
82reset_db
83sqlite3_fts5_create_tokenizer -v2 db tcl tcl_create
84
85do_execsql_test 2.1 {
86 CREATE VIRTUAL TABLE b1 USING fts5(x, y, locale=1, tokenize=tcl);
87 CREATE VIRTUAL TABLE b2 USING fts5(x, y, locale=0, tokenize=tcl);
88
89 CREATE VIRTUAL TABLE ttt USING fts5vocab('b1', instance);
90}
91
92do_catchsql_test 2.2.1 {
93 CREATE VIRTUAL TABLE b3 USING fts5(x, y, locale=2);
94} {1 {malformed locale=... directive}}
95do_catchsql_test 2.2.2 {
96 CREATE VIRTUAL TABLE b3 USING fts5(x, y, locale=111);
97} {1 {malformed locale=... directive}}
98
99do_catchsql_test 2.3 {
100 INSERT INTO b1(b1, rank) VALUES('locale', 0);
101} {1 {SQL logic error}}
102
103do_execsql_test 2.4.1 {
104 INSERT INTO b1 VALUES('abc', 'one two three');
105}
106
107do_execsql_test 2.4.2 {
108 INSERT INTO b1 VALUES('def', fts5_locale('reverse', 'four five six'));
109}
110
111do_execsql_test 2.5 {
112 INSERT INTO b2 VALUES('abc', 'one two three');
113}
114
115do_catchsql_test 2.6 {
116 INSERT INTO b2 VALUES('def', fts5_locale('reverse', 'four five six'));
117} {1 {fts5_locale() requires locale=1}}
118
119do_execsql_test 2.7 { SELECT rowid FROM b1('one') } {1}
120do_execsql_test 2.8 { SELECT rowid FROM b1('four') } {}
121do_execsql_test 2.9 { SELECT rowid FROM b1('ruof') } 2
122do_execsql_test 2.10 { SELECT rowid FROM b1(fts5_locale('reverse', 'five'))} 2
123
124do_execsql_test 2.11 {
125 SELECT x, quote(y) FROM b1
126} {
127 abc {'one two three'}
128 def {'four five six'}
129}
130
131do_execsql_test 2.12 { SELECT quote(y) FROM b1('ruof') } {
132 {'four five six'}
133}
134
135do_execsql_test 2.13 {
136 INSERT INTO b1(b1) VALUES('integrity-check');
137}
138
139do_execsql_test 2.14 {
140 INSERT INTO b1(b1) VALUES('rebuild');
141}
142do_execsql_test 2.15 {
143 INSERT INTO b1(b1) VALUES('integrity-check');
144}
145
146do_execsql_test 2.16 {
147 DELETE FROM b1 WHERE rowid=2
148}
149do_execsql_test 2.17 {
150 INSERT INTO b1(b1) VALUES('integrity-check');
151}
152
153do_execsql_test 2.18 {
154 INSERT INTO b1(rowid, x, y) VALUES(
155 test_setsubtype(45, 76), 'abc def', 'def abc'
156 );
157}
158
159#-------------------------------------------------------------------------
160# Test the 'delete' command with contentless tables.
161#
162reset_db
163sqlite3_fts5_create_tokenizer -v2 db tcl tcl_create
164
165do_execsql_test 3.1 {
166 CREATE VIRTUAL TABLE c1 USING fts5(x, content=, tokenize=tcl, locale=1);
167 CREATE VIRTUAL TABLE c2 USING fts5vocab('c1', instance);
168
169 INSERT INTO c1 VALUES('hello world');
170 INSERT INTO c1 VALUES( fts5_locale('reverse', 'one two three') );
171}
172
173do_execsql_test 3.2 {
174 SELECT DISTINCT term FROM c2 ORDER BY 1
175} {
176 eerht eno hello owt world
177}
178
179do_execsql_test 3.3 {
180 INSERT INTO c1(c1, rowid, x)
181 VALUES('delete', 2, fts5_locale('reverse', 'one two three') );
182}
183
184do_execsql_test 3.4 {
185 SELECT DISTINCT term FROM c2 ORDER BY 1
186} {
187 hello world
188}
189
190#-------------------------------------------------------------------------
191# Test that an UPDATE that updates a subset of the columns does not
192# magically discard the locale from those columns not updated.
193#
194reset_db
195sqlite3_fts5_create_tokenizer -v2 db tcl tcl_create
196
197do_execsql_test 4.1 {
198 CREATE VIRTUAL TABLE d1 USING fts5(x, y, locale=1, tokenize=tcl);
199 CREATE VIRTUAL TABLE d2 USING fts5vocab('d1', instance);
200
201 INSERT INTO d1(rowid, x, y) VALUES(1, 'abc', 'def');
202 INSERT INTO d1(rowid, x, y) VALUES(2, 'ghi', fts5_locale('reverse', 'hello'));
203}
204
205do_execsql_test 4.2 {
206 SELECT DISTINCT term FROM d2 ORDER BY 1
207} {
208 abc def ghi olleh
209}
210
211do_execsql_test 4.3 {
212 UPDATE d1 SET x='jkl' WHERE rowid=2;
213}
214
215do_execsql_test 4.4 {
216 SELECT DISTINCT term FROM d2 ORDER BY 1
217} {
218 abc def jkl olleh
219}
220
221do_execsql_test 4.5 {
222 SELECT rowid, * FROM d1
223} {
224 1 abc def
225 2 jkl hello
226}
227
228do_execsql_test 4.6 {
229 UPDATE d1 SET rowid=4 WHERE rowid=2
230}
231
232do_execsql_test 4.7 {
233 SELECT rowid, * FROM d1
234} {
235 1 abc def
236 4 jkl hello
237}
238
239fts5_aux_test_functions db
240
241do_execsql_test 4.8.1 {
242 SELECT fts5_test_columntext(d1) FROM d1('jkl')
243} {{jkl hello}}
244do_execsql_test 4.8.2 {
245 SELECT fts5_test_columntext(d1) FROM d1(fts5_locale('reverse', 'hello'))
246} {{jkl hello}}
247
248do_execsql_test 4.9 {
249 SELECT fts5_test_columnlocale(d1) FROM d1(fts5_locale('reverse', 'hello'))
250} {{{} reverse}}
251
252do_execsql_test 4.10 {
253 SELECT fts5_test_columnlocale(d1) FROM d1
254} {
255 {{} {}}
256 {{} reverse}
257}
258
259#-------------------------------------------------------------------------
260# Test that if an fts5_locale() value is written to an UNINDEXED
261# column it is stored as text. This is so that blobs and other values
262# can also be stored as is.
263#
264reset_db
265sqlite3_fts5_create_tokenizer -v2 db tcl tcl_create
266
267do_execsql_test 5.1 {
268 CREATE VIRTUAL TABLE t1 USING fts5(
269 x, y UNINDEXED, locale=1, tokenize=tcl
270 );
271
272 INSERT INTO t1(rowid, x, y) VALUES(111,
273 fts5_locale('reverse', 'one two three'),
274 fts5_locale('reverse', 'four five six')
275 );
276}
277
278do_execsql_test 5.2 {
279 SELECT rowid, x, y FROM t1
280} {
281 111 {one two three} {four five six}
282}
283
284do_execsql_test 5.3 {
285 SELECT typeof(c0), typeof(c1), typeof(l0) FROM t1_content
286} {
287 text text text
288}
289
290#-------------------------------------------------------------------------
291
292foreach {tn opt} {
293 1 {}
294 2 {, columnsize=0}
295} {
296 reset_db
297 sqlite3_fts5_create_tokenizer -v2 db tcl tcl_create
298 do_execsql_test 6.$tn.1 "
299 CREATE VIRTUAL TABLE y1 USING fts5(t, locale=1, tokenize=tcl $opt);
300 "
301
302 do_execsql_test 6.$tn.2 {
303 INSERT INTO y1(rowid, t) VALUES
304 (1, fts5_locale('second', 'the city of London')),
305 (2, fts5_locale('second', 'shall have all the old')),
306 (3, fts5_locale('second', 'Liberties and Customs')),
307 (4, fts5_locale('second', 'which it hath been used to have'));
308 }
309
310 fts5_aux_test_functions db
311
312 do_execsql_test 6.$tn.3 {
313 SELECT fts5_test_columnsize(y1) FROM y1
314 } {
315 2 3 2 4
316 }
317
318 do_execsql_test 6.$tn.4 {
319 SELECT rowid, fts5_test_columnsize(y1) FROM y1('shall');
320 } {
321 2 3
322 }
323
324 do_execsql_test 6.$tn.5 {
325 SELECT rowid, fts5_test_columnsize(y1) FROM y1('shall');
326 } {
327 2 3
328 }
329
330 do_execsql_test 6.$tn.6 {
331 SELECT rowid, fts5_test_columnsize(y1) FROM y1('have');
332 } {
333 4 4
334 }
335
336 do_execsql_test 6.$tn.7 {
337 SELECT rowid, highlight(y1, 0, '[', ']') FROM y1('have');
338 } {
339 4 {which it hath been used to [have]}
340 }
341
342 do_execsql_test 6.$tn.8 {
343 SELECT rowid,
344 highlight(y1, 0, '[', ']'),
345 snippet(y1, 0, '[', ']', '...', 10)
346 FROM y1('Liberties + Customs');
347 } {
348 3 {[Liberties and Customs]}
349 {[Liberties and Customs]}
350 }
351}
352
353#-------------------------------------------------------------------------
354reset_db
355do_execsql_test 6.0 {
356 CREATE VIRTUAL TABLE x1 USING fts5(x);
357}
358do_catchsql_test 6.1 {
359 INSERT INTO x1(rowid, x) VALUES(123, fts5_locale('en_AU', 'hello world'));
360} {1 {fts5_locale() requires locale=1}}
361
362do_execsql_test 6.2 {
363 SELECT typeof( fts5_locale(NULL, 'xyz') ), typeof( fts5_locale('', 'abc') );
364} {text text}
365
366#--------------------------------------------------------------------------
367# Test that fts5_locale() works with external-content tables.
368#
369reset_db
370sqlite3_fts5_create_tokenizer -v2 db tcl tcl_create
371
372do_execsql_test 7.1 {
373 CREATE TABLE t1(ii INTEGER PRIMARY KEY, bb BLOB, tt TEXT, locale TEXT);
374 CREATE VIEW v1 AS
375 SELECT ii AS rowid, bb, fts5_locale(locale, tt) AS tt FROM t1;
376
377 CREATE VIRTUAL TABLE ft USING fts5(
378 bb, tt, locale=1, tokenize=tcl, content=v1
379 );
380
381 INSERT INTO t1 VALUES(1, NULL, 'one two three', NULL);
382 INSERT INTO t1 VALUES(2, '7800616263', 'four five six', 'reverse');
383 INSERT INTO t1 VALUES(3, '000000007800616263', 'seven eight nine', 'second');
384}
385
386do_execsql_test 7.2 {
387 INSERT INTO ft(ft) VALUES('rebuild');
388 INSERT INTO ft(ft) VALUES('integrity-check');
389}
390
391do_execsql_test 7.3 {
392 SELECT rowid, quote(bb), quote(tt) FROM ft
393} {
394 1 NULL {'one two three'}
395 2 '7800616263' {'four five six'}
396 3 '000000007800616263' {'seven eight nine'}
397}
398
399do_execsql_test 7.4 { SELECT rowid FROM ft('six'); }
400do_execsql_test 7.5 { SELECT rowid FROM ft(fts5_locale('reverse','six')); } 2
401
402fts5_aux_test_functions db
403
404do_execsql_test 7.6 {
405 SELECT fts5_test_columnlocale(ft) FROM ft;
406} {
407 {{} {}} {{} reverse} {{} second}
408}
409
410#-------------------------------------------------------------------------
411# Test that the porter tokenizer works with locales.
412#
413reset_db
414sqlite3_fts5_create_tokenizer -v2 db tcl tcl_create
415
416do_execsql_test 8.1 {
417 CREATE VIRTUAL TABLE ft USING fts5(tt, locale=1, tokenize="porter tcl");
418 CREATE VIRTUAL TABLE vocab USING fts5vocab('ft', instance);
419
420 INSERT INTO ft(rowid, tt) VALUES
421 (111, fts5_locale('second', 'the porter tokenizer is a wrapper tokenizer')),
422 (222, fts5_locale('reverse', 'This value may also be set'));
423}
424
425do_execsql_test 8.1 {
426 SELECT DISTINCT term FROM vocab ORDER BY 1
427} {
428 a eb eulav osla sihT te the token yam
429}
430
431#-------------------------------------------------------------------------
432# Test that position-lists (used by xInst, xPhraseFirst etc.) work with
433# locales and modes other than detail=full.
434#
435foreach {tn detail} {
436 1 detail=full
437 2 detail=none
438 3 detail=column
439} {
440 reset_db
441 sqlite3_fts5_create_tokenizer -v2 db tcl tcl_create
442 do_execsql_test 9.$tn.0 "
443 CREATE VIRTUAL TABLE ft USING fts5(tt, locale=1, tokenize=tcl, $detail);
444 "
445 do_execsql_test 9.$tn.1 {
446 CREATE VIRTUAL TABLE vocab USING fts5vocab('ft', instance);
447 INSERT INTO ft(rowid, tt) VALUES
448 (-1, fts5_locale('second', 'it is an ancient mariner'));
449 }
450
451 do_execsql_test 9.$tn.2 {
452 SELECT DISTINCT term FROM vocab
453 } {an it mariner}
454
455 do_execsql_test 9.$tn.3 {
456 SELECT highlight(ft, 0, '[', ']') FROM ft('mariner')
457 } {{it is an ancient [mariner]}}
458}
459
460#-------------------------------------------------------------------------
461# Check some corrupt fts5_locale() blob formats are detected.
462#
463foreach_detail_mode $::testprefix {
464
465 reset_db
466 sqlite3_fts5_create_tokenizer -v2 db tcl tcl_create
467 fts5_aux_test_functions db
468 do_execsql_test 10.1 {
469 CREATE TABLE x1(ii INTEGER PRIMARY KEY, x);
470 CREATE VIRTUAL TABLE ft USING fts5(x,
471 content=x1, content_rowid=ii, locale=1, detail=%DETAIL%, columnsize=0
472 );
473
474 CREATE VIRTUAL TABLE ft2 USING fts5(
475 x, locale=1, detail=%DETAIL%, columnsize=0
476 );
477 }
478
479 foreach {tn v} {
480 1 X'001152'
481 2 X'0011223344'
482 3 X'00E0B2EB68656c6c6f'
483 4 X'00E0B2EB0068656c6c6f'
484 } {
485 do_execsql_test 10.2.$tn.0 { INSERT INTO ft(ft) VALUES('delete-all') }
486 do_execsql_test 10.2.$tn.1 { DELETE FROM x1; }
487 do_execsql_test 10.2.$tn.2 " INSERT INTO x1 VALUES(NULL, $v) "
488
489 do_catchsql_test 10.2.$tn.3 {
490 INSERT INTO ft(ft) VALUES('rebuild');
491 } {0 {}}
492
493 do_catchsql_test 10.2.$tn.4 "
494 SELECT * FROM ft( test_setsubtype($v, 76) );
495 " {1 {fts5: syntax error near ""}}
496
497 do_execsql_test 10.2.$tn.5 {
498 INSERT INTO ft(rowid, x) VALUES(1, 'hello world');
499 }
500
501 if {"%DETAIL%"=="full"} {
502 do_execsql_test 10.2.$tn.6 {
503 SELECT fts5_test_poslist(ft) FROM ft('world');
504 } {0.0.1}
505
506 do_execsql_test 10.2.$tn.7.1 {
507 SELECT fts5_test_columnsize(ft) FROM ft('world');
508 } {1}
509
510 do_execsql_test 10.2.$tn.7.2 {
511 SELECT fts5_test_columnlocale(ft) FROM ft('world');
512 } {{{}}}
513 }
514
515 do_catchsql_test 10.2.$tn.8 {
516 SELECT count(*) FROM ft('hello')
517 } {0 1}
518
519 do_catchsql_test 10.2.$tn.9 {
520 PRAGMA integrity_check;
521 } {0 ok}
522
523 do_execsql_test 10.2.$tn.10 {
524 DELETE FROM x1;
525 INSERT INTO x1(ii, x) VALUES(1, 'hello world');
526 }
527
528 do_catchsql_test 10.2.$tn.11 "
529 INSERT INTO ft(ft, rowid, x) VALUES('delete', 1, test_setsubtype($v,76) )
530 " {0 {}}
531
532 do_catchsql_test 10.2.$tn.12 "
533 INSERT INTO ft(rowid, x) VALUES(2, test_setsubtype($v,76) )
534 " {0 {}}
535
536 do_execsql_test 10.2.$tn.13 {
537 INSERT INTO ft2(rowid, x) VALUES(1, 'hello world');
538 }
539 do_execsql_test 10.2.$tn.14 "UPDATE ft2_content SET c0=$v"
540
541 do_catchsql_test 10.2.$tn.15 {
542 PRAGMA integrity_check;
543 } {0 {{malformed inverted index for FTS5 table main.ft2}}}
544
545 do_execsql_test 10.2.$tn.16 {
546 DELETE FROM ft2_content;
547 INSERT INTO ft2(ft2) VALUES('rebuild');
548 }
549 }
550
551}
552
553#-------------------------------------------------------------------------
554#
555reset_db
556sqlite3_fts5_create_tokenizer -v2 db tcl tcl_create
557fts5_aux_test_functions db
558do_execsql_test 11.0 {
559 CREATE VIRTUAL TABLE x1 USING fts5(abc, locale=1);
560 INSERT INTO x1(rowid, abc) VALUES(123, fts5_locale('en_US', 'one two three'));
561}
562
563do_catchsql_test 11.1 {
564 SELECT fts5_columnlocale(x1, -1) FROM x1('two');
565} {1 SQLITE_RANGE}
566do_catchsql_test 11.2 {
567 SELECT fts5_columnlocale(x1, 1) FROM x1('two');
568} {1 SQLITE_RANGE}
569
570#-------------------------------------------------------------------------
571#
572reset_db
573do_test 12.0 {
574 list [catch {
575 sqlite3_fts5_create_tokenizer -v2 -version 3 db tcl tcl_create
576 } msg] $msg
577} {1 {error in fts5_api.xCreateTokenizer_v2()}}
578
579#-------------------------------------------------------------------------
580# Tests for auxiliary function fts5_get_locale().
581#
582reset_db
583
584# Check that if the table does not support locale=1, fts5_get_locale()
585# always returns NULL.
586do_execsql_test 13.1.0 {
587 CREATE VIRTUAL TABLE nolocale USING fts5(a, b);
588 INSERT INTO nolocale VALUES('one two three', 'four five six');
589 INSERT INTO nolocale VALUES('three two one', 'seven eight nine');
590}
591do_execsql_test 13.1.1 {
592 SELECT fts5_get_locale(nolocale, 0) IS NULL FROM nolocale;
593} {1 1}
594do_execsql_test 13.1.2 {
595 SELECT fts5_get_locale(nolocale, 1) IS NULL FROM nolocale('one + two');
596} {1}
597do_execsql_test 13.1.3 {
598 SELECT fts5_get_locale(nolocale, 0) IS NULL FROM nolocale('one AND two');
599} {1 1}
600do_execsql_test 13.1.4 {
601 SELECT
602 fts5_get_locale(nolocale, 1) IS NULL
603 FROM nolocale('three AND two') ORDER BY rank
604} {1 1}
605do_catchsql_test 13.1.5 {
606 SELECT fts5_get_locale(nolocale, 2) IS NULL FROM nolocale('three AND two');
607} {1 {column index out of range}}
608do_catchsql_test 13.1.6 {
609 SELECT fts5_get_locale(nolocale, -1) IS NULL FROM nolocale('three AND two');
610} {1 {column index out of range}}
611do_catchsql_test 13.1.7 {
612 SELECT fts5_get_locale(nolocale) IS NULL FROM nolocale('three AND two');
613} {1 {wrong number of arguments to function fts5_get_locale()}}
614do_catchsql_test 13.1.8 {
615 SELECT fts5_get_locale(nolocale, 0, 0) IS NULL FROM nolocale('three AND two');
616} {1 {wrong number of arguments to function fts5_get_locale()}}
617do_catchsql_test 13.1.9 {
618 SELECT fts5_get_locale(nolocale, 'text') FROM nolocale('three AND two');
619} {1 {non-integer argument passed to function fts5_get_locale()}}
620
621# Column numbers too large or too small to fit in a 32-bit signed integer
622# are out of range.
623foreach {tn iCol} {
624 1 2147483648
625 2 -2147483649
626 3 4294967295
627 4 4294967296
628 5 4294967297
629 6 -4294967295
630 7 -4294967296
631 8 9223372036854775807
632 9 -9223372036854775808
633} {
634 do_catchsql_test 13.1.10.$tn {
635 SELECT fts5_get_locale(nolocale, $iCol) FROM nolocale('three AND two');
636 } {1 {column index out of range}}
637}
638
639
640# Check that if the table does support locale=1, fts5_get_locale()
641# returns the locale of the identified row/column.
642do_execsql_test 13.2.0 {
643 CREATE VIRTUAL TABLE ft USING fts5(a, b, locale=1);
644 INSERT INTO ft VALUES(
645 fts5_locale('th_TH', 'one two three'), 'four five six seven'
646 );
647 INSERT INTO ft VALUES(
648 'three two one', fts5_locale('en_AU', 'seven eight nine')
649 );
650}
651
652do_execsql_test 13.2.1 {
653 SELECT quote(fts5_get_locale(ft, 0)), quote(fts5_get_locale(ft, 1)) FROM ft
654} { 'th_TH' NULL NULL 'en_AU' }
655do_execsql_test 13.2.2 {
656 SELECT
657 quote(fts5_get_locale(ft, 0)), quote(fts5_get_locale(ft, 1))
658 FROM ft('one AND three')
659} { 'th_TH' NULL NULL 'en_AU' }
660do_execsql_test 13.2.3 {
661 SELECT
662 quote(fts5_get_locale(ft, 0)), quote(fts5_get_locale(ft, 1))
663 FROM ft('one AND three') ORDER BY rank
664} { NULL 'en_AU' 'th_TH' NULL }
665do_execsql_test 13.2.4 {
666 SELECT
667 quote(fts5_get_locale(ft, 0)), quote(fts5_get_locale(ft, 1))
668 FROM ft('one AND three') ORDER BY rowid
669} { 'th_TH' NULL NULL 'en_AU' }
670
671do_execsql_test 13.2.5 {
672 SELECT
673 quote(fts5_get_locale(ft, '0')), quote(fts5_get_locale(ft, 1))
674 FROM ft('one AND three') ORDER BY rowid
675} { 'th_TH' NULL NULL 'en_AU' }
676
677do_catchsql_test 13.2.6 {
678 SELECT
679 quote(fts5_get_locale(ft, '0.0')), quote(fts5_get_locale(ft, 1))
680 FROM ft('one AND three') ORDER BY rowid
681} {1 {non-integer argument passed to function fts5_get_locale()}}
682do_catchsql_test 13.2.7 {
683 SELECT
684 quote(fts5_get_locale(ft, 0.0)), quote(fts5_get_locale(ft, 1))
685 FROM ft('one AND three') ORDER BY rowid
686} {1 {non-integer argument passed to function fts5_get_locale()}}
687
688#-------------------------------------------------------------------------
689# Check that UPDATE statements that may affect more than one row work.
690#
691reset_db
692do_execsql_test 14.1 {
693 CREATE VIRTUAL TABLE ft USING fts5(a, b, locale=1);
694}
695
696do_execsql_test 14.2 {
697 INSERT INTO ft VALUES('hello', 'world');
698}
699
700do_execsql_test 14.3 {
701 UPDATE ft SET b = fts5_locale('en_AU', 'world');
702}
703
704do_execsql_test 14.4 {
705 INSERT INTO ft VALUES(X'abcd', X'1234');
706} {}
707
708do_execsql_test 14.5 {
709 SELECT quote(a), quote(b) FROM ft
710} {'hello' 'world' X'ABCD' X'1234'}
711
712do_execsql_test 14.6 {
713 DELETE FROM ft;
714 INSERT INTO ft VALUES(NULL, 'null');
715 INSERT INTO ft VALUES(123, 'int');
716 INSERT INTO ft VALUES(345.0, 'real');
717 INSERT INTO ft VALUES('abc', 'text');
718 INSERT INTO ft VALUES(fts5_locale('abc', 'def'), 'text');
719
720 SELECT a, typeof(a), b FROM ft
721} {
722 {} null null
723 123 integer int
724 345.0 real real
725 abc text text
726 def text text
727}
728
729do_execsql_test 14.7 {
730 SELECT quote(c0), typeof(c0) FROM ft_content
731} {
732 NULL null
733 123 integer
734 345.0 real
735 'abc' text
736 'def' text
737}
738
739#-------------------------------------------------------------------------
740# Check that inserting UNINDEXED columns between indexed columns of a
741# locale=1 table does not cause a problem.
742#
743reset_db
744sqlite3_fts5_create_tokenizer -v2 db tcl tcl_create
745fts5_aux_test_functions db
746
747do_execsql_test 15.1 {
748 CREATE VIRTUAL TABLE ft USING fts5(a, b UNINDEXED, c, locale=1, tokenize=tcl);
749}
750
751do_execsql_test 15.2 {
752 INSERT INTO ft VALUES('one', 'two', 'three');
753 INSERT INTO ft VALUES('one', 'two', fts5_locale('loc', 'three'));
754}
755
756do_execsql_test 15.3 {
757 SELECT c2, l2 FROM ft_content
758} {three {} three loc}
759
760do_execsql_test 15.4 {
761 SELECT c, fts5_columnlocale(ft, 2) FROM ft
762} {three {} three loc}
763
764#-------------------------------------------------------------------------
765#
766set nMaxCol 500
767set nStep 20
768
769for {set ii $nStep} {$ii <= $nMaxCol} {incr ii $nStep} {
770 set C [list]
771 for {set iCol 0} {$iCol<$ii} {incr iCol} {
772 lappend C col$iCol
773 }
774 set ct "CREATE VIRTUAL TABLE t$ii USING fts5([join $C ,], locale=1)"
775 do_execsql_test 16.$ii $ct
776}
777
778finish_test
779