提交 69e5bb70 authored 作者: Thomas Mueller's avatar Thomas Mueller

The PUBLIC schema could be renamed, which could result in a database that can't…

The PUBLIC schema could be renamed, which could result in a database that can't be opened normally. Now it can no longer be renamed. The schema INFORMATION_SCHEMA can also no longer be renamed.
上级 8c95b033
......@@ -40,6 +40,9 @@ public class AlterSchemaRename extends DefineCommand {
public int update() {
session.commit(true);
Database db = session.getDatabase();
if (!oldSchema.canDrop()) {
throw DbException.get(ErrorCode.SCHEMA_CAN_NOT_BE_DROPPED_1, oldSchema.getName());
}
if (db.findSchema(newSchemaName) != null || newSchemaName.equals(oldSchema.getName())) {
throw DbException.get(ErrorCode.SCHEMA_ALREADY_EXISTS_1, newSchemaName);
}
......
......@@ -35,6 +35,7 @@ public class TestAlterSchemaRename extends TestBase {
deleteDb("alter");
conn = getConnection("alter");
stat = conn.createStatement();
testTryToRenameSystemSchemas();
testSimpleRename();
testRenameToExistingSchema();
testCrossSchemaViews();
......@@ -43,6 +44,21 @@ public class TestAlterSchemaRename extends TestBase {
deleteDb("alter");
}
private void testTryToRenameSystemSchemas() throws SQLException {
try {
stat.execute("alter schema information_schema rename to test_info");
fail();
} catch (SQLException e) {
assertEquals(ErrorCode.SCHEMA_CAN_NOT_BE_DROPPED_1, e.getErrorCode());
}
stat.execute("create sequence test_sequence");
try {
stat.execute("alter schema public rename to test_schema");
fail();
} catch (SQLException e) {
assertEquals(ErrorCode.SCHEMA_CAN_NOT_BE_DROPPED_1, e.getErrorCode());
}
}
private void testSimpleRename() throws SQLException {
stat.execute("create schema s1");
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论