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
|
#!/usr/bin/env tarantool
test = require("sqltester")
test:plan(184)
--!./tcltestrunner.lua
-- 2009 January 29
--
-- 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.
--
-------------------------------------------------------------------------
--
-- Verify that certain keywords can be used as identifiers.
--
-- $Id: keyword1.test,v 1.1 2009/01/29 19:27:47 drh Exp $
-- ["set","testdir",[["file","dirname",["argv0"]]]]
-- ["source",[["testdir"],"\/tester.tcl"]]
test:execsql [[
CREATE TABLE t1(a INT PRIMARY KEY, b TEXT);
INSERT INTO t1 VALUES(1, 'one');
INSERT INTO t1 VALUES(2, 'two');
INSERT INTO t1 VALUES(3, 'three');
]]
local kwlist = {
"abort",
"action",
"after",
"cascade",
"before",
"conflict",
"deferred",
"engine",
"fail",
"ignore",
"initially",
"instead",
"key",
"offset",
"plan",
"query",
"restrict",
"raise",
"enable",
"disable"
}
local bannedkws = {
"all",
"alter",
"analyze",
"and",
"as",
"asc",
"begin",
"between",
"blob",
"by",
"case",
"check",
"collate",
"column",
"commit",
"constraint",
"create",
"cross",
"current_date",
"current_time",
"current_timestamp",
"default",
"delete",
"desc",
"distinct",
"drop",
"each",
"end",
"else",
"escape",
"except",
"exists",
"explain",
"for",
"foreign",
"from",
"group",
"having",
"immediate",
"in",
"index",
"inner",
"insert",
"intersect",
"into",
"is",
"join",
"left",
"like",
"match",
"natural",
"not",
"null",
"of",
"on",
"or",
"order",
"outer",
"pragma",
"primary",
"recursive",
"references",
"release",
"rename",
"replace",
"right",
"rollback",
"row",
"savepoint",
"select",
"set",
"table",
"then",
"to",
"transaction",
"trigger",
"union",
"unique",
"update",
"using",
"values",
"view",
"with",
"when",
"where",
"any",
"asensitive",
"binary",
"call",
"char",
"character",
"condition",
"connect",
"current",
"current_user",
"cursor",
"date",
"decimal",
"declare",
"dense_rank",
"describe",
"deterministic",
"double",
"elseif",
"fetch",
"float",
"function",
"get",
"grant",
"integer",
"inout",
"insensitive",
"iterate",
"leave",
"localtime",
"localtimestamp",
"loop",
"number",
"out",
"over",
"partition",
"precision",
"procedure",
"range",
"rank",
"reads",
"repeat",
"resignal",
"return",
"revoke",
"rows",
"row_number",
"sensitive",
"signal",
"smallint",
"specific",
"start",
"system",
"sql",
"user",
"varchar",
"varbinary",
"whenever",
"while"
}
local exprkw = [[
"cast",
"current_date",
"current_time",
"current_timestamp",
"raise",
]]
for _, kw in ipairs(kwlist) do
test:do_test(
"keyword1-"..kw..".1",
function()
if (kw == "if") then
test:execsql( string.format([[CREATE TABLE "%s"(%s %s PRIMARY KEY)]], kw:upper(), kw, 'INT'))
else
test:execsql(string.format("CREATE TABLE %s(%s %s PRIMARY KEY)", kw, kw, 'INT'))
end
test:execsql("INSERT INTO "..kw.." VALUES(99)")
test:execsql("INSERT INTO "..kw.." SELECT a FROM t1")
if test:lsearch(exprkw, kw) <0 then
return test:execsql(string.format("SELECT * FROM %s ORDER BY %s ASC", kw, kw))
else
return test:execsql(string.format([[SELECT * FROM %s ORDER BY "%s" ASC]], kw, kw:upper()))
end
end, {
1, 2, 3, 99
})
test:do_test(
"keyword1-"..kw..".2",
function()
if (kw == "if") then
test:execsql(string.format([[DROP TABLE "%s"]], kw:upper()))
test:execsql(string.format([[CREATE INDEX "%s" ON t1(a)]], kw))
else
test:execsql("DROP TABLE "..kw.."")
test:execsql("CREATE INDEX "..kw.." ON t1(a)")
end
return test:execsql("SELECT b FROM t1 WHERE a=2")
end, {
"two"
})
end
for _, kw in ipairs(bannedkws) do
query = 'CREATE TABLE '..kw..'(a INT PRIMARY KEY);'
if kw == 'end' or kw == 'match' or kw == 'release' or kw == 'rename' or
kw == 'replace' or kw == 'binary' or kw == 'character' or
kw == 'smallint' then
test:do_catchsql_test(
"bannedkw1-"..kw..".1",
query, {
1, "At line 1 at or near position "..14 + string.len(kw)..
": keyword '"..kw.."' is reserved. Please use double quotes if '"
..kw.."' is an identifier."
})
else
test:do_catchsql_test(
"bannedkw1-"..kw..".1",
query, {
1, "At line 1 at or near position 14: keyword '"..kw..
"' is reserved. Please use double quotes if '"..kw..
"' is an identifier."
})
end
end
test:finish_test()
|