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
|
#!/usr/bin/env tarantool
test = require("sqltester")
identifier = require("identifier")
test:plan(9)
local test_prefix = "identifier_char-"
local testcases = {
-- table creation testcase
{"table",
-- create
function (id)
-- sql autogenerated index name rules add "sql_autoindex_") prefix
if string.len(id) == box.schema.NAME_MAX then
id = string.sub(id, string.len(id))
end
test:execsql(string.format("create table \"%s\" (a INT primary key);", id))
end,
-- cleanup
function (id)
if string.len(id) == box.schema.NAME_MAX then
id = string.sub(id, string.len(id))
end
test:execsql(string.format("drop table \"%s\";", id))
end},
{"column name",
function (id)
test:execsql(string.format("create table table1(a INT primary key, \"%s\" INT);", id))
end,
function (id)
test:execsql(string.format("drop table table1;", id))
end},
{"view as select",
function (id)
test:execsql(string.format("create view \"%s\" as select * from test;", id))
end,
function (id)
test:execsql(string.format("drop view \"%s\";", id))
end},
{"view column name",
function (id)
test:execsql(string.format("create view v1 (\"%s\") as select b from test;", id))
end,
function (id)
test:execsql(string.format("drop view v1;", id))
end},
{"as column name",
function (id)
test:execsql(string.format("create view v1 as select b as \"%s\" from test;", id))
end,
function (id)
test:execsql(string.format("drop view v1;", id))
end},
{"index name",
function (id)
test:execsql(string.format("create index \"%s\" on test(b,c);", id))
end,
function (id)
test:execsql(string.format("drop index \"%s\" on test", id))
end},
{"savepoint name",
function (id)
test:execsql("START TRANSACTION")
local ok, res = pcall(test.execsql, test, string.format("savepoint \"%s\"", id))
test:execsql("commit")
if ok == false then error(res) end
end,
function (id) end},
{"trigger name",
function (id)
test:execsql(string.format([[
CREATE TRIGGER "%s" UPDATE ON test
FOR EACH ROW
BEGIN
SELECT RAISE(ABORT, 'newer');
END;]], id));
end,
function (id)
test:execsql(string.format("drop trigger \"%s\"", id))
end}
}
test:do_execsql_test(
test_prefix.."preparition",
"create table test(a INT primary key, b INT, c INT)")
for _, testcase in ipairs(testcases) do
test:do_test(
test_prefix..testcase[1],
function ()
return identifier.run_test(
testcase[2],
testcase[3])
end,
"All tests passed")
end
test:finish_test()
|