File: selectC.test.lua

package info (click to toggle)
tarantool 2.6.0-1.2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 85,396 kB
  • sloc: ansic: 513,775; cpp: 69,493; sh: 25,650; python: 19,190; perl: 14,973; makefile: 4,176; yacc: 1,329; sql: 1,074; pascal: 620; ruby: 190; awk: 18; lisp: 7
file content (369 lines) | stat: -rwxr-xr-x 9,169 bytes parent folder | download | duplicates (3)
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
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
#!/usr/bin/env tarantool
test = require("sqltester")
test:plan(18)

--!./tcltestrunner.lua
-- 2008 September 16
--
-- 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.
--
-- $Id: selectC.test,v 1.5 2009/05/17 15:26:21 drh Exp $
-- ["set","testdir",[["file","dirname",["argv0"]]]]
-- ["source",[["testdir"],"\/tester.tcl"]]
-- Ticket #
test:do_execsql_test(
    "selectC-1.1",
    [[
        DROP TABLE IF EXISTS t1;
        CREATE TABLE t1(id  INT PRIMARY KEY, a INT, b TEXT, c TEXT);
        INSERT INTO t1 VALUES(1, 1,'aaa','bbb');
        INSERT INTO t1 VALUES(2, 1, 'aaa', 'bbb');
        INSERT INTO t1 VALUES(3, 2,'ccc','ddd');

        SELECT DISTINCT a AS x, b||c AS y
          FROM t1
         WHERE y IN ('aaabbb','xxx');
    ]], {
        -- <selectC-1.1>
        1, "aaabbb"
        -- </selectC-1.1>
    })

test:do_execsql_test(
    "selectC-1.2",
    [[
        SELECT DISTINCT a AS x, b||c AS y
          FROM t1
         WHERE b||c IN ('aaabbb','xxx');
    ]], {
        -- <selectC-1.2>
        1, "aaabbb"
        -- </selectC-1.2>
    })

test:do_execsql_test(
    "selectC-1.3",
    [[
        SELECT DISTINCT a AS x, b||c AS y
          FROM t1
         WHERE y='aaabbb'
    ]], {
        -- <selectC-1.3>
        1, "aaabbb"
        -- </selectC-1.3>
    })

test:do_execsql_test(
    "selectC-1.4",
    [[
        SELECT DISTINCT a AS x, b||c AS y
          FROM t1
         WHERE b||c='aaabbb'
    ]], {
        -- <selectC-1.4>
        1, "aaabbb"
        -- </selectC-1.4>
    })

test:do_execsql_test(
    "selectC-1.5",
    [[
        SELECT DISTINCT a AS x, b||c AS y
          FROM t1
         WHERE x=2
    ]], {
        -- <selectC-1.5>
        2, "cccddd"
        -- </selectC-1.5>
    })

test:do_execsql_test(
    "selectC-1.6",
    [[
        SELECT DISTINCT a AS x, b||c AS y
          FROM t1
         WHERE a=2
    ]], {
        -- <selectC-1.6>
        2, "cccddd"
        -- </selectC-1.6>
    })

test:do_execsql_test(
    "selectC-1.7",
    [[
        SELECT DISTINCT a AS x, b||c AS y
          FROM t1
         WHERE +y='aaabbb'
    ]], {
        -- <selectC-1.7>
        1, "aaabbb"
        -- </selectC-1.7>
    })

test:do_execsql_test(
    "selectC-1.8",
    [[
        SELECT a AS x, b||c AS y
          FROM t1
         GROUP BY x, y
        HAVING y='aaabbb'
    ]], {
        -- <selectC-1.8>
        1, "aaabbb"
        -- </selectC-1.8>
    })

test:do_execsql_test(
    "selectC-1.9",
    [[
        SELECT a AS x, b||c AS y
          FROM t1
         GROUP BY x, y
        HAVING b||c='aaabbb'
    ]], {
        -- <selectC-1.9>
        1, "aaabbb"
        -- </selectC-1.9>
    })

test:do_execsql_test(
    "selectC-1.10",
    [[
        SELECT a AS x, b||c AS y
          FROM t1
         WHERE y='aaabbb'
         GROUP BY x, y
    ]], {
        -- <selectC-1.10>
        1, "aaabbb"
        -- </selectC-1.10>
    })

test:do_execsql_test(
    "selectC-1.11",
    [[
        SELECT a AS x, b||c AS y
          FROM t1
         WHERE b||c='aaabbb'
         GROUP BY x, y
    ]], {
        -- <selectC-1.11>
        1, "aaabbb"
        -- </selectC-1.11>
    })


-- TODO stored procedures are not supported by now
-- longname_toupper could not be referenced from sql

--local function longname_toupper(x)
--    return string.toupper(x)
--end

-- db("function", "uppercaseconversionfunctionwithaverylongname", "longname_toupper")
test:do_execsql_test(
    "selectC-1.12.1",
    [[
        SELECT DISTINCT upper(b) AS x
          FROM t1
         ORDER BY x
    ]], {
        -- <selectC-1.12.1>
        "AAA", "CCC"
        -- </selectC-1.12.1>
    })

-- TODO stored procedures are not supported by now
--test:do_execsql_test(
--    "selectC-1.12.2",
--    [[
--        SELECT DISTINCT uppercaseconversionfunctionwithaverylongname(b) AS x
--          FROM t1
--         ORDER BY x
--    ]], {
--        -- <selectC-1.12.2>
--        "AAA", "CCC"
--        -- </selectC-1.12.2>
--    })

test:do_execsql_test(
    "selectC-1.13.1",
    [[
        SELECT upper(b) AS x
          FROM t1
         GROUP BY x
         ORDER BY x
    ]], {
        -- <selectC-1.13.1>
        "AAA", "CCC"
        -- </selectC-1.13.1>
    })

-- TODO stored procedures are not supported by now
--test:do_execsql_test(
--    "selectC-1.13.2",
--    [[
--        SELECT uppercaseconversionfunctionwithaverylongname(b) AS x
--          FROM t1
--         GROUP BY x
--         ORDER BY x
--    ]], {
--        -- <selectC-1.13.2>
--        "AAA", "CCC"
--        -- </selectC-1.13.2>
--    })

test:do_execsql_test(
    "selectC-1.14.1",
    [[
        SELECT upper(b) AS x
          FROM t1
         ORDER BY x DESC
    ]], {
        -- <selectC-1.14.1>
        "CCC", "AAA", "AAA"
        -- </selectC-1.14.1>
    })


-- TODO stored procedures are not supported by now
--test:do_execsql_test(
--    "selectC-1.14.2",
--    [[
--        SELECT uppercaseconversionfunctionwithaverylongname(b) AS x
--          FROM t1
--         ORDER BY x DESC
--    ]], {
--        -- <selectC-1.14.2>
--        "CCC", "AAA", "AAA"
--        -- </selectC-1.14.2>
--    })

-- MUST_WORK_TEST
-- # The following query used to leak memory.  Verify that has been fixed.
-- #
-- ifcapable trigger&&compound {
--   do_test selectC-2.1 {
--     catchsql {
--       CREATE TABLE t21a(a INT ,b INT );
--       INSERT INTO t21a VALUES(1,2);
--       CREATE TABLE t21b(n INT );
--       CREATE TRIGGER r21 AFTER INSERT ON t21b BEGIN
--         SELECT a FROM t21a WHERE a>new.x UNION ALL
--         SELECT b FROM t21a WHERE b>new.x ORDER BY 1 LIMIT 2;
--       END;
--       INSERT INTO t21b VALUES(6);
--     }
--   } {1 {no such column: new.x}}
-- }
-- MUST_WORK_TEST
-- # Check that ticket [883034dcb5] is fixed.
-- #
-- do_test selectC-3.1 {
--   execsql {
--     DROP TABLE IF EXISTS person;
--     CREATE TABLE person (
--         org_id          TEXT NOT NULL,
--         nickname        TEXT NOT NULL,
--         license         TEXT,
--         CONSTRAINT person_pk PRIMARY KEY (org_id, nickname INT ),
--         CONSTRAINT person_license_uk UNIQUE (license)
--     );
--     INSERT INTO person VALUES('meyers', 'jack', '2GAT123');
--     INSERT INTO person VALUES('meyers', 'hill', 'V345FMP');
--     INSERT INTO person VALUES('meyers', 'jim', '2GAT138');
--     INSERT INTO person VALUES('smith', 'maggy', '');
--     INSERT INTO person VALUES('smith', 'jose', 'JJZ109');
--     INSERT INTO person VALUES('smith', 'jack', 'THX138');
--     INSERT INTO person VALUES('lakeside', 'dave', '953OKG');
--     INSERT INTO person VALUES('lakeside', 'amy', NULL);
--     INSERT INTO person VALUES('lake-apts', 'tom', NULL);
--     INSERT INTO person VALUES('acorn', 'hideo', 'CQB421');
--     SELECT 
--       org_id, 
--       count((NOT (org_id IS NULL)) AND (NOT (nickname IS NULL)))
--     FROM person 
--     WHERE (CASE WHEN license != '' THEN 1 ELSE 0 END)
--     GROUP BY 1;
--   }
-- } {acorn 1 lakeside 1 meyers 3 smith 2}
test:do_execsql_test(
    "selectC-3.2",
    [[
        DROP TABLE IF EXISTS t2;
        CREATE TABLE t2(a  TEXT PRIMARY KEY, b TEXT);
        INSERT INTO t2 VALUES('abc', 'xxx');
        INSERT INTO t2 VALUES('def', 'yyy');
        SELECT a, max(b || a) FROM t2 WHERE (b||b||b)!='value' GROUP BY a;
    ]], {
        -- <selectC-3.2>
        "abc", "xxxabc", "def", "yyydef"
        -- </selectC-3.2>
    })

test:do_execsql_test(
    "selectC-3.3",
    [[
        SELECT b, max(a || b) FROM t2 WHERE (b||b||b)!='value' GROUP BY a;
    ]], {
        -- <selectC-3.3>
        "xxx", "abcxxx", "yyy", "defyyy"
        -- </selectC-3.3>
    })

-- TODO stored procedures are not supported by now
--local function udf()
--    udf = udf + 1
--end
--
--udf = 0
--db("function", "udf", "udf")

test:do_execsql_test(
    "selectC-4.1",
    [[
        create table t_distinct_bug (id int primary key, a TEXT, b TEXT, c TEXT);
        insert into t_distinct_bug values (0, '1', '1', 'a');
        insert into t_distinct_bug values (1, '1', '2', 'b');
        insert into t_distinct_bug values (2, '1', '3', 'c');
        insert into t_distinct_bug values (3, '1', '1', 'd');
        insert into t_distinct_bug values (4, '1', '2', 'e');
        insert into t_distinct_bug values (5, '1', '3', 'f');
    ]], {
        -- <selectC-4.1>

        -- </selectC-4.1>
    })

test:do_execsql_test(
    "selectC-4.2",
    [[
        select a from (select distinct a, b from t_distinct_bug)
    ]], {
        -- <selectC-4.2>
        "1", "1", "1"
        -- </selectC-4.2>
    })

-- TODO stored procedures are not supported by now
--test:do_execsql_test(
--    "selectC-4.3",
--    [[
--        select a, udf() from (select distinct a, b from t_distinct_bug)
--    ]], {
--        -- <selectC-4.3>
--        1, 1, 1, 2, 1, 3
--        -- </selectC-4.3>
--    })

test:finish_test()