Unverified 提交 b3581c5d authored 作者: Evgenij Ryazanov's avatar Evgenij Ryazanov 提交者: GitHub

Merge pull request #1314 from katzyn/ddl

Add ALTER VIEW RENAME command
......@@ -468,7 +468,7 @@ This command commits an open transaction in this connection.
ALTER USER SA SET PASSWORD 'rioyxlgt'
"
"Commands (DDL)","ALTER VIEW","
"Commands (DDL)","ALTER VIEW RECOMPILE","
ALTER VIEW [ IF EXISTS ] viewName RECOMPILE
","
Recompiles a view after the underlying tables have been changed or created.
......@@ -478,6 +478,15 @@ This command commits an open transaction in this connection.
ALTER VIEW ADDRESS_VIEW RECOMPILE
"
"Commands (DDL)","ALTER VIEW RENAME","
ALTER VIEW [ IF EXISTS ] viewName RENAME TO newName
","
Renames a view.
This command commits an open transaction in this connection.
","
ALTER VIEW TEST RENAME TO MY_VIEW
"
"Commands (DDL)","ANALYZE","
ANALYZE [ TABLE tableName ] [ SAMPLE_SIZE rowCountInt ]
","
......
......@@ -5767,20 +5767,32 @@ public class Parser {
return command;
}
private AlterView parseAlterView() {
AlterView command = new AlterView(session);
private DefineCommand parseAlterView() {
boolean ifExists = readIfExists(false);
command.setIfExists(ifExists);
String viewName = readIdentifierWithSchema();
Table tableView = getSchema().findTableOrView(session, viewName);
Schema schema = getSchema();
Table tableView = schema.findTableOrView(session, viewName);
if (!(tableView instanceof TableView) && !ifExists) {
throw DbException.get(ErrorCode.VIEW_NOT_FOUND_1, viewName);
}
if (readIf("RENAME")) {
read("TO");
String newName = readIdentifierWithSchema(schema.getName());
checkSchema(schema);
AlterTableRename command = new AlterTableRename(session, getSchema());
command.setOldTableName(viewName);
command.setNewTableName(newName);
command.setIfTableExists(ifExists);
return command;
} else {
read("RECOMPILE");
TableView view = (TableView) tableView;
AlterView command = new AlterView(session);
command.setIfExists(ifExists);
command.setView(view);
read("RECOMPILE");
return command;
}
}
private Prepared parseAlterSchema() {
boolean ifExists = readIfExists(false);
......
......@@ -123,8 +123,8 @@ public class TestScript extends TestDb {
"uuid", "varchar", "varchar-ignorecase" }) {
testScript("datatypes/" + s + ".sql");
}
for (String s : new String[] { "alterTableAdd", "alterTableDropColumn",
"createAlias", "createSynonym", "createView", "createTable", "createTrigger",
for (String s : new String[] { "alterTableAdd", "alterTableDropColumn", "alterTableRename",
"createAlias", "createSynonym", "createTable", "createTrigger", "createView",
"dropDomain", "dropIndex", "dropSchema", "truncateTable" }) {
testScript("ddl/" + s + ".sql");
}
......
-- Copyright 2004-2018 H2 Group. Multiple-Licensed under the MPL 2.0,
-- and the EPL 1.0 (http://h2database.com/html/license.html).
-- Initial Developer: H2 Group
--
-- Test for ALTER TABLE RENAME and ALTER VIEW RENAME
CREATE TABLE TABLE1A(ID INT);
> ok
INSERT INTO TABLE1A VALUES (1);
> update count: 1
-- ALTER TABLE RENAME
ALTER TABLE TABLE1A RENAME TO TABLE1B;
> ok
SELECT * FROM TABLE1B;
>> 1
ALTER TABLE IF EXISTS TABLE1B RENAME TO TABLE1C;
> ok
SELECT * FROM TABLE1C;
>> 1
ALTER TABLE BAD RENAME TO SMTH;
> exception TABLE_OR_VIEW_NOT_FOUND_1
ALTER TABLE IF EXISTS BAD RENAME TO SMTH;
> ok
-- ALTER VIEW RENAME
CREATE VIEW VIEW1A AS SELECT * FROM TABLE1C;
> ok
ALTER VIEW VIEW1A RENAME TO VIEW1B;
> ok
SELECT * FROM VIEW1B;
>> 1
ALTER TABLE IF EXISTS VIEW1B RENAME TO VIEW1C;
> ok
SELECT * FROM VIEW1C;
>> 1
ALTER VIEW BAD RENAME TO SMTH;
> exception VIEW_NOT_FOUND_1
ALTER VIEW IF EXISTS BAD RENAME TO SMTH;
> ok
SELECT * FROM VIEW1C;
>> 1
DROP TABLE TABLE1C CASCADE;
> ok
......@@ -16,11 +16,11 @@ HELP ABCDE EF_GH;
HELP HELP;
> ID SECTION TOPIC SYNTAX TEXT
> -- ---------------- ----- ----------------------- ----------------------------------------------------
> 64 Commands (Other) HELP HELP [ anything [...] ] Displays the help pages of SQL commands or keywords.
> 65 Commands (Other) HELP HELP [ anything [...] ] Displays the help pages of SQL commands or keywords.
> rows: 1
HELP he lp;
> ID SECTION TOPIC SYNTAX TEXT
> -- ---------------- ----- ----------------------- ----------------------------------------------------
> 64 Commands (Other) HELP HELP [ anything [...] ] Displays the help pages of SQL commands or keywords.
> 65 Commands (Other) HELP HELP [ anything [...] ] Displays the help pages of SQL commands or keywords.
> rows: 1
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论