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 file is prefixes.c extension
15 set testdir [file dirname $argv0]
16 source $testdir/tester.tcl
17 set testprefix unionvtab
24 load_static_extension db prefixes
26 foreach {tn zLeft zRight expected} {
32 5 "xyz\u1234xz" "xyz\u1234xy" 5
33 6 "xyz\u1234" "xyz\u1234xy" 4
34 7 "xyz\u1234" "xyz\u1234" 4
35 8 "xyz\u1234xy" "xyz\u1234" 4
36 9 "xyz\u1234xy" "xyz\u1233" 3
37 10 "xyz\u1234xy" "xyz\u1235" 3
39 do_execsql_test 1.$tn { SELECT prefix_length($zLeft, $zRight) } $expected
44 CREATE TABLE t1(k TEXT UNIQUE, v INTEGER);
69 foreach {tn INPUT expected} {
70 1 abatementt abatement
75 do_execsql_test 2.$tn {
77 SELECT (SELECT max(k) FROM t1 WHERE k<=$INPUT)
81 WHERE k<=substr($INPUT, 1, prefix_length(finder.str, $INPUT))
82 ) FROM finder WHERE length(finder.str)>0
84 SELECT str FROM finder WHERE length(str)==prefix_length(str, $INPUT) LIMIT 1