File: identifier_case.test.lua

package info (click to toggle)
tarantool 2.6.0-1.4
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 85,412 kB
  • sloc: ansic: 513,775; cpp: 69,493; sh: 25,650; python: 19,190; perl: 14,973; makefile: 4,178; yacc: 1,329; sql: 1,074; pascal: 620; ruby: 190; awk: 18; lisp: 7
file content (262 lines) | stat: -rwxr-xr-x 7,230 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
#!/usr/bin/env tarantool
test = require("sqltester")
test:plan(73)

local test_prefix = "identifier_case-"

local data = {
    { 1,  [[ table1 ]], {0} },
    { 2,  [[ Table1 ]], {"/already exists/"} },
    { 3,  [[ TABLE1 ]], {"/already exists/"} },
    { 4,  [[ "TABLE1" ]], {"/already exists/"} },
    { 5,  [[ "table1" ]], {0} },
    { 6,  [[ "Table1" ]], {0} },
    -- non ASCII characters case is not supported
    { 7,  [[ русский ]], {0} },
    { 8,  [[ "русский" ]], {0} },
    { 9,  [[ Großschreibweise ]], {0} },
    { 10,  [[ Русский ]], {"/already exists/"} },
    { 11,  [[ Grossschreibweise ]], {"/already exists/"} },
}

for _, row in ipairs(data) do
    test:do_catchsql_test(
        test_prefix.."1.1."..row[1],
        string.format( [[
                CREATE TABLE %s (a int PRIMARY KEY);
                INSERT INTO %s values (%s);
                ]], row[2], row[2], row[1]),
        row[3])
end

data = {
    { 1, [[ table1 ]], {1}},
    { 2, [[ Table1 ]], {1}},
    { 3, [[ TABLE1 ]], {1}},
    { 4, [[ "TABLE1" ]], {1}},
    { 5, [[ "table1" ]], {5}},
    { 6, [[ "Table1" ]], {6}},
    { 7, [[ русский ]], {7}},
    { 8, [[ "русский" ]], {8}},
}

for _, row in ipairs(data) do
    test:do_execsql_test(
        test_prefix.."1.2."..row[1],
        string.format([[
            SELECT * FROM %s;
            ]], row[2]),
        row[3])
end

test:do_test(
    test_prefix.."1.3.1",
    function ()
        test:execsql([[ DROP TABLE table1; ]])
    end,
    nil)

test:do_test(
    test_prefix.."1.3.2",
    function ()
        test:execsql([[ DROP TABLE "table1"; ]])
    end,
    nil)

test:do_test(
    test_prefix.."1.3.3",
    function ()
        return test:drop_all_tables()
    end,
    4)

data = {
    { 1,  [[ columnn ]], {0} },
    { 2,  [[ Columnn ]], {0} },
    { 3,  [[ COLUMNN ]], {0} },
    { 4,  [[ "COLUMNN" ]], {0} },
    { 5,  [[ "columnn" ]], {0} },
    { 6,  [[ "Columnn" ]], {0} },
    { 7,  [[ "columNN" ]], {1, "Space field 'columNN' is duplicate"} }
}

for _, row in ipairs(data) do
    test:do_catchsql_test(
        test_prefix.."2.1."..row[1],
        string.format( [[
                CREATE TABLE table%s ("columNN" INT, %s INT, primary key("columNN", %s));
                INSERT INTO table%s(%s, "columNN") values (%s, %s);
                ]],
                row[1], row[2], row[2],
                row[1], row[2], row[1], row[1]+1),
        row[3])
end


data = {
    { 1,  [[ columnn ]], },
    { 2,  [[ Columnn ]], },
    { 3,  [[ COLUMNN ]], },
    { 4,  [[ "COLUMNN" ]], },
    { 5,  [[ "columnn" ]], },
    { 6,  [[ "Columnn" ]], }
}

for _, row in ipairs(data) do
    test:do_execsql_test(
        test_prefix.."2.2."..row[1],
        string.format([[
            SELECT %s FROM table%s;
            ]], row[2], row[1]),
        {row[1]})
end

test:do_test(
    test_prefix.."2.3.1",
    function ()
        return test:drop_all_tables()
    end,
    6)

test:execsql([[create table table1(pk INT PRIMARY KEY AUTOINCREMENT, columnn INT , "columnn" INT UNIQUE)]])
test:execsql([[insert into table1("columnn", "COLUMNN") values(2,1)]])


data = {
    --tn  lookup_cln    lookup_val  set_cln       set_val result
    { 1,  [[ columnn ]], 1,          [[ columnn ]], 3 ,     {3,2} },
    { 2,  [[ Columnn ]], 3,          [[ columnn ]], 4 ,     {4,2} },
    { 3,  [[ columnn ]], 4,          [[ Columnn ]], 5 ,     {5,2} },
    { 4,  [["COLUMNN"]], 5,          [[ columnn ]], 6 ,     {6,2} },
    { 5,  [[ columnn ]], 6,          [["COLUMNN"]], 7 ,     {7,2} },
    { 6,  [["columnn"]], 2,          [["columnn"]], 3 ,     {7,3} },
    { 7,  [["columnn"]], 3,          [[ columnn ]], 8 ,     {8,3} },
    { 8,  [["columnn"]], 8,          [[ columnn ]], 1000 ,  {8,3} },
}

for _, row in ipairs(data) do
    local tn = row[1]
    local lookup_cln = row[2]
    local lookup_val = row[3]
    local set_cln = row[4]
    local set_val = row[5]
    local result = row[6]
    test:do_execsql_test(
        test_prefix.."3.1."..tn,
        string.format( [[
                UPDATE table1 set %s = %s where %s = %s;
                SELECT table1.columnn, "TABLE1"."columnn" FROM table1;
                ]],
            set_cln, set_val, lookup_cln, lookup_val),
        result)
end

test:do_test(
    test_prefix.."3.2.1",
    function ()
        return test:drop_all_tables()
    end,
    1)

test:do_execsql_test(
    test_prefix.."4.0",
    string.format([[create table table1(a INT , b  INT primary key)]]),
    nil
)

test:do_execsql_test(
    test_prefix.."4.1",
    string.format([[select * from table1 order by a]]),
    {}
)

data = {
    { 1,  [[ trigger1 ]], {0}},
    { 2,  [[ Trigger1 ]], {1, "Trigger 'TRIGGER1' already exists"}},
    { 3,  [["TRIGGER1"]], {1, "Trigger 'TRIGGER1' already exists"}},
    { 4,  [["trigger1" ]], {0}}
}

for _, row in ipairs(data) do
    test:do_catchsql_test(
        test_prefix.."5.1."..row[1],
        string.format( [[
                CREATE TRIGGER %s DELETE ON table1 FOR EACH ROW BEGIN SELECT 1; END
                ]], row[2]),
        row[3])
end

data = {
    { 1,  [[ trigger1 ]], {0}},
    { 2,  [["trigger1" ]], {0}}
}

for _, row in ipairs(data) do
    test:do_catchsql_test(
        test_prefix.."5.2."..row[1],
        string.format( [[
                DROP TRIGGER %s
                ]], row[2]),
        row[3])
end


-- Check that collaiton names work as identifiers
data = {
    { 1,  [[ binary ]], {1, "Collation 'BINARY' does not exist"}},
    { 2,  [[ BINARY ]], {1, "Collation 'BINARY' does not exist"}},
    { 3,  [["binary"]], {0}},
    { 4,  [["bInaRy"]], {1, "Collation 'bInaRy' does not exist"}},
    { 5,  [["unicode"]], {0}},
    { 6,  [[ unicode ]], {1,"Collation 'UNICODE' does not exist"}},
    { 7,  [["UNICODE"]], {1,"Collation 'UNICODE' does not exist"}},
    { 8,  [[NONE]], {1,"Collation 'NONE' does not exist"}},
    { 9,  [["none"]], {0}},
}

test:do_catchsql_test(
    test_prefix.."6.0.",
    [[
        CREATE TABLE T1 (a TEXT primary key, b TEXT);
    ]],
    {0})

for _, row in ipairs(data) do
    test:do_catchsql_test(
        test_prefix.."6.1."..row[1],
        string.format( [[
                CREATE INDEX I%s ON T1 (b COLLATE %s);
                ]], row[1], row[2]),
        row[3])
end

test:do_catchsql_test(
    test_prefix.."6.2",
    [[
        DROP TABLE T1;
    ]],
    {0})

data = {
    { 1,  [[ 'a' < 'b' collate binary ]], {1, "Collation 'BINARY' does not exist"}},
    { 2,  [[ 'a' < 'b' collate "binary" ]], {0, {true}}},
    { 3,  [[ 'a' < 'b' collate 'binary' ]], {1, [[Syntax error at line 1 near ''binary'']]}},
    { 4,  [[ 'a' < 'b' collate "unicode" ]], {0, {true}}},
    { 5,  [[ 5 < 'b' collate "unicode" ]], {0, {true}}},
    { 6,  [[ 5 < 'b' collate unicode ]], {1,"Collation 'UNICODE' does not exist"}},
    { 7,  [[ 5 < 'b' collate "unicode_ci" ]], {0, {true}}},
    { 8,  [[ 5 < 'b' collate NONE ]], {1, "Collation 'NONE' does not exist"}},
    { 9,  [[ 5 < 'b' collate "none" ]], {0, {true}}},
}

for _, row in ipairs(data) do
    test:do_catchsql_test(
        test_prefix.."6.3."..row[1],
        string.format( [[
                SELECT %s;
                ]], row[2]),
        row[3])
end


test:finish_test()