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

[#285] Add support for ALTER SCHEMA IF EXISTS

上级 1dd4130d
...@@ -653,7 +653,7 @@ public class Parser { ...@@ -653,7 +653,7 @@ public class Parser {
return command; return command;
} }
private Schema getSchema(String schemaName) { private Schema findSchema(String schemaName) {
if (schemaName == null) { if (schemaName == null) {
return null; return null;
} }
...@@ -665,13 +665,22 @@ public class Parser { ...@@ -665,13 +665,22 @@ public class Parser {
} else if (database.getMode().sysDummy1 && } else if (database.getMode().sysDummy1 &&
"SYSIBM".equals(schemaName)) { "SYSIBM".equals(schemaName)) {
// IBM DB2 and Apache Derby compatibility: SYSIBM.SYSDUMMY1 // IBM DB2 and Apache Derby compatibility: SYSIBM.SYSDUMMY1
} else {
throw DbException.get(ErrorCode.SCHEMA_NOT_FOUND_1, schemaName);
} }
} }
return schema; 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() { private Schema getSchema() {
return getSchema(schemaName); return getSchema(schemaName);
} }
...@@ -4883,17 +4892,27 @@ public class Parser { ...@@ -4883,17 +4892,27 @@ public class Parser {
return command; return command;
} }
private AlterSchemaRename parseAlterSchema() { private Prepared parseAlterSchema() {
boolean ifExists = readIfExists(false);
String schemaName = readIdentifierWithSchema(); String schemaName = readIdentifierWithSchema();
Schema old = getSchema(); Schema old = getSchema();
AlterSchemaRename command = new AlterSchemaRename(session);
command.setOldSchema(getSchema(schemaName));
read("RENAME"); read("RENAME");
read("TO"); read("TO");
String newName = readIdentifierWithSchema(old.getName()); String newName = readIdentifierWithSchema(old.getName());
checkSchema(old); Schema schema = findSchema(schemaName);
command.setNewName(newName); if (schema == null) {
return command; 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() { private AlterSequence parseAlterSequence() {
......
...@@ -10431,3 +10431,21 @@ drop table x; ...@@ -10431,3 +10431,21 @@ drop table x;
drop table z; drop table z;
> ok > 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 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论