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 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241
|
#!/usr/bin/env tarantool
test = require("sqltester")
test:plan(7)
--!./tcltestrunner.lua
-- 2015-03-06
--
-- The author disclaims copyright to this source code. In place of
-- a legal notice, here is a blessing:
--
-- May you do good and not evil.
-- May you find forgiveness for yourself and forgive others.
-- May you share freely, never taking more than you give.
--
-----------------------------------------------------------------
--
-- This file implements regression tests for sql library. The
-- focus of this file is testing the LIKE operator and
-- in particular the optimizations that occur to help this
-- operator run faster and that those optimizations work
-- correctly when there are both strings and blobs being tested.
--
-- Ticket 05f43be8fdda9fbd948d374319b99b054140bc36 shows that the following
-- SQL was not working correctly:
--
-- CREATE TABLE t1(x TEXT UNIQUE COLLATE nocase);
-- INSERT INTO t1(x) VALUES(x'616263');
-- SELECT 'query-1', x FROM t1 WHERE x LIKE 'a%';
-- SELECT 'query-2', x FROM t1 WHERE +x LIKE 'a%';
--
-- This script verifies that it works right now.
--
-- ["set","testdir",[["file","dirname",["argv0"]]]]
-- ["source",[["testdir"],"\/tester.tcl"]]
test:execsql([[
--PRAGMA encoding='UTF8';
CREATE TABLE t1(a INT PRIMARY KEY,b TEXT COLLATE "unicode_ci");
INSERT INTO t1(a,b)
VALUES(1,'abc'),
(2,'ABX'),
(3,'BCD'),
(4, char(0x61, 0x62, 0x63)),
(5, char(0x41, 0x42, 0x58)),
(6, char(0x42, 0x43, 0x44));
CREATE INDEX t1ba ON t1(b,a);
]])
-- MUST_WORK #1476 collate nocase
--test:do_execsql_test(
-- "like3-1.1",
-- [[
-- SELECT a, b FROM t1 WHERE b LIKE 'aB%' ORDER BY +a;
-- ]], {
-- -- <like3-1.1>
-- 1, "abc", 2, "ABX", 4, "abc", 5, "ABX"
-- -- </like3-1.1>
-- })
test:do_execsql_test(
"like3-1.2",
[[
SELECT a, b FROM t1 WHERE +b LIKE 'aB%' ORDER BY +a;
]], {
-- <like3-1.2>
1, "abc", 2, "ABX", 4, "abc", 5, "ABX"
-- </like3-1.2>
})
test:do_execsql_test(
"like3-2.0",
[[
CREATE TABLE t2(a INT PRIMARY KEY, b TEXT);
INSERT INTO t2 SELECT a, b FROM t1;
CREATE INDEX t2ba ON t2(b,a);
SELECT a, b FROM t2 WHERE b LIKE 'ab%' COLLATE "unicode_ci" ORDER BY +a;
]], {
-- <like3-2.0>
1, "abc", 2, "ABX", 4, "abc", 5, "ABX"
-- </like3-2.0>
})
test:do_execsql_test(
"like3-2.1",
[[
SELECT a, b FROM t2 WHERE +b LIKE 'ab%' COLLATE "unicode_ci" ORDER BY +a;
]], {
-- <like3-2.1>
1, "abc", 2, "ABX", 4, "abc", 5, "ABX"
-- </like3-2.1>
})
test:do_execsql_test(
"like3-2.2",
[[
SELECT a, b FROM t2 WHERE b>='ab' AND b LIKE 'ab%'
]], {
-- <like3-2.2>
1, "abc", 4, "abc"
-- </like3-2.2>
})
test:do_execsql_test(
"like3-2.3",
[[
SELECT a, b FROM t2 WHERE +b>='ab' AND +b LIKE 'ab%'
]], {
-- <like3-2.3>
1, "abc", 4, "abc"
-- </like3-2.3>
})
test:do_execsql_test(
"like3-2.4",
[[
SELECT a, b FROM t2 WHERE b LIKE 'ab%' AND b>='ab'
]], {
-- <like3-2.4>
1, "abc", 4, "abc"
-- </like3-2.4>
})
test:do_execsql_test(
"like3-2.5",
[[
SELECT a, b FROM t2 WHERE +b LIKE 'ab%' AND +b>='ab'
]], {
-- <like3-2.5>
1, "abc", 4, "abc"
-- </like3-2.5>
})
test:execsql([[
CREATE TABLE t3(x TEXT PRIMARY KEY COLLATE "unicode_ci");
INSERT INTO t3(x) VALUES('aaa'),('abc'),('abd'),('abe'),('acz');
]])
-- MUST_WORK #1476 collate nocase
if 0>0 then
test:do_execsql_test(
"like3-3.0",
[[
SELECT quote(x) FROM t3 WHERE x LIKE 'ab%' ORDER BY x;
]], {
-- <like3-3.0>
"'abc'", "'abd'", "'abe'", "X'616263'", "X'616264'", "X'616265'"
-- </like3-3.0>
})
test:do_execsql_test(
"like3-3.1",
[[
SELECT quote(x) FROM t3 WHERE x LIKE 'ab%' ORDER BY x DESC;
]], {
-- <like3-3.1>
"X'616265'", "X'616264'", "X'616263'", "'abe'", "'abd'", "'abc'"
-- </like3-3.1>
})
test:do_execsql_test(
"like3-3.1ck",
[[
SELECT quote(x) FROM t3 WHERE x LIKE 'ab%' ORDER BY +x DESC;
]], {
-- <like3-3.1ck>
"X'616265'", "X'616264'", "X'616263'", "'abe'", "'abd'", "'abc'"
-- </like3-3.1ck>
})
test:do_execsql_test(
"like3-3.2",
[[
SELECT quote(x) FROM t3 WHERE x LIKE 'ab%' ORDER BY x ASC;
]], {
-- <like3-3.2>
"'abc'", "'abd'", "'abe'", "X'616263'", "X'616264'", "X'616265'"
-- </like3-3.2>
})
test:do_execsql_test(
"like3-3.2ck",
[[
SELECT quote(x) FROM t3 WHERE x LIKE 'ab%' ORDER BY +x ASC;
]], {
-- <like3-3.2ck>
"'abc'", "'abd'", "'abe'", "X'616263'", "X'616264'", "X'616265'"
-- </like3-3.2ck>
})
test:do_execsql_test(
"like3-4.0",
[[
CREATE TABLE t4(x TEXT COLLATE "unicode_ci" PRIMARY KEY);
CREATE INDEX t4x ON t4(x DESC);
INSERT INTO t4(x) SELECT x FROM t3;
SELECT quote(x) FROM t4 WHERE x LIKE 'ab%' ORDER BY x;
]], {
-- <like3-4.0>
"'abc'", "'abd'", "'abe'", "X'616263'", "X'616264'", "X'616265'"
-- </like3-4.0>
})
test:do_execsql_test(
"like3-4.1",
[[
SELECT quote(x) FROM t4 WHERE x LIKE 'ab%' ORDER BY x DESC;
]], {
-- <like3-4.1>
"X'616265'", "X'616264'", "X'616263'", "'abe'", "'abd'", "'abc'"
-- </like3-4.1>
})
test:do_execsql_test(
"like3-4.1ck",
[[
SELECT quote(x) FROM t4 WHERE x LIKE 'ab%' ORDER BY +x DESC;
]], {
-- <like3-4.1ck>
"X'616265'", "X'616264'", "X'616263'", "'abe'", "'abd'", "'abc'"
-- </like3-4.1ck>
})
test:do_execsql_test(
"like3-4.2",
[[
SELECT quote(x) FROM t4 WHERE x LIKE 'ab%' ORDER BY x ASC;
]], {
-- <like3-4.2>
"'abc'", "'abd'", "'abe'", "X'616263'", "X'616264'", "X'616265'"
-- </like3-4.2>
})
test:do_execsql_test(
"like3-4.2ck",
[[
SELECT quote(x) FROM t4 WHERE x LIKE 'ab%' ORDER BY +x ASC;
]], {
-- <like3-4.2ck>
"'abc'", "'abd'", "'abe'", "X'616263'", "X'616264'", "X'616265'"
-- </like3-4.2ck>
})
end
test:finish_test()
|