提交 3b718821 authored 作者: lukaseder's avatar lukaseder

[#285] Add support for ALTER SCHEMA IF EXISTS

上级 1dd4130d
......@@ -653,7 +653,7 @@ public class Parser {
return command;
}
private Schema getSchema(String schemaName) {
private Schema findSchema(String schemaName) {
if (schemaName == null) {
return null;
}
......@@ -665,13 +665,22 @@ public class Parser {
} else if (database.getMode().sysDummy1 &&
"SYSIBM".equals(schemaName)) {
// IBM DB2 and Apache Derby compatibility: SYSIBM.SYSDUMMY1
} else {
throw DbException.get(ErrorCode.SCHEMA_NOT_FOUND_1, schemaName);
}
}
return schema;
}
private Schema getSchema(String schemaName) {
if (schemaName == null) {
return null;
}
Schema schema = findSchema(schemaName);
if (schema == null) {
throw DbException.get(ErrorCode.SCHEMA_NOT_FOUND_1, schemaName);
}
return schema;
}
private Schema getSchema() {
return getSchema(schemaName);
}
......@@ -4883,17 +4892,27 @@ public class Parser {
return command;
}
private AlterSchemaRename parseAlterSchema() {
private Prepared parseAlterSchema() {
boolean ifExists = readIfExists(false);
String schemaName = readIdentifierWithSchema();
Schema old = getSchema();
AlterSchemaRename command = new AlterSchemaRename(session);
command.setOldSchema(getSchema(schemaName));
read("RENAME");
read("TO");
String newName = readIdentifierWithSchema(old.getName());
checkSchema(old);
command.setNewName(newName);
return command;
Schema schema = findSchema(schemaName);
if (schema == null) {
if (ifExists) {
return new NoOperation(session);
} else {
throw DbException.get(ErrorCode.SCHEMA_NOT_FOUND_1, schemaName);
}
} else {
AlterSchemaRename command = new AlterSchemaRename(session);
command.setOldSchema(schema);
checkSchema(old);
command.setNewName(newName);
return command;
}
}
private AlterSequence parseAlterSequence() {
......
......@@ -10431,3 +10431,21 @@ drop table x;
drop table z;
> ok
create schema x;
> ok
alter schema if exists y rename to z;
> ok
alter schema if exists x rename to z;
> ok
alter schema if exists x rename to z;
> ok
create table z.z (id int);
> ok
drop schema z;
> ok
\ No newline at end of file
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论