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

Merge pull request #1477 from katzyn/ddl

Throw COLUMN_IS_REFERENCED_1 instead of VIEW_IS_INVALID_2 from DROP COLUMN
...@@ -21,6 +21,8 @@ Change Log ...@@ -21,6 +21,8 @@ Change Log
<h2>Next Version (unreleased)</h2> <h2>Next Version (unreleased)</h2>
<ul> <ul>
<li>Issue #1475: Dropping column used by a view produces misleading error message
</li>
<li>Issue #1473: TestScript needs better detection of sorted result <li>Issue #1473: TestScript needs better detection of sorted result
</li> </li>
<li>PR #1471: issue 1350: TestCrashAPI: PageStore.freeListPagesPerList <li>PR #1471: issue 1350: TestCrashAPI: PageStore.freeListPagesPerList
......
...@@ -297,7 +297,7 @@ public class AlterTableAlterColumn extends CommandWithColumns { ...@@ -297,7 +297,7 @@ public class AlterTableAlterColumn extends CommandWithColumns {
checkViews(table, newTable); checkViews(table, newTable);
} catch (DbException e) { } catch (DbException e) {
execute("DROP TABLE " + newTable.getName(), true); execute("DROP TABLE " + newTable.getName(), true);
throw DbException.get(ErrorCode.VIEW_IS_INVALID_2, e, getSQL(), e.getMessage()); throw e;
} }
String tableName = table.getName(); String tableName = table.getName();
ArrayList<TableView> dependentViews = new ArrayList<>(table.getDependentViews()); ArrayList<TableView> dependentViews = new ArrayList<>(table.getDependentViews());
...@@ -547,7 +547,11 @@ public class AlterTableAlterColumn extends CommandWithColumns { ...@@ -547,7 +547,11 @@ public class AlterTableAlterColumn extends CommandWithColumns {
// check if the query is still valid // check if the query is still valid
// do not execute, not even with limit 1, because that could // do not execute, not even with limit 1, because that could
// have side effects or take a very long time // have side effects or take a very long time
session.prepare(sql); try {
session.prepare(sql);
} catch (DbException e) {
throw DbException.get(ErrorCode.COLUMN_IS_REFERENCED_1, e, view.getSQL());
}
checkViewsAreValid(view); checkViewsAreValid(view);
} }
} }
......
...@@ -73,7 +73,7 @@ public class TestViewAlterTable extends TestDb { ...@@ -73,7 +73,7 @@ public class TestViewAlterTable extends TestDb {
stat.execute("create table test(id identity, name varchar) " + stat.execute("create table test(id identity, name varchar) " +
"as select x, 'Hello'"); "as select x, 'Hello'");
stat.execute("create view test_view as select * from test"); stat.execute("create view test_view as select * from test");
assertThrows(ErrorCode.VIEW_IS_INVALID_2, stat). assertThrows(ErrorCode.COLUMN_IS_REFERENCED_1, stat).
execute("alter table test drop name"); execute("alter table test drop name");
ResultSet rs = stat.executeQuery("select * from test_view"); ResultSet rs = stat.executeQuery("select * from test_view");
assertTrue(rs.next()); assertTrue(rs.next());
...@@ -83,7 +83,7 @@ public class TestViewAlterTable extends TestDb { ...@@ -83,7 +83,7 @@ public class TestViewAlterTable extends TestDb {
// nested // nested
createTestData(); createTestData();
// should throw exception because V1 uses column A // should throw exception because V1 uses column A
assertThrows(ErrorCode.VIEW_IS_INVALID_2, stat). assertThrows(ErrorCode.COLUMN_IS_REFERENCED_1, stat).
execute("alter table test drop column a"); execute("alter table test drop column a");
stat.execute("drop table test cascade"); stat.execute("drop table test cascade");
} }
......
...@@ -78,3 +78,21 @@ SELECT * FROM TEST; ...@@ -78,3 +78,21 @@ SELECT * FROM TEST;
DROP TABLE TEST; DROP TABLE TEST;
> ok > ok
CREATE TABLE T1(ID INT PRIMARY KEY, C INT);
> ok
CREATE VIEW V1 AS SELECT C FROM T1;
> ok
ALTER TABLE T1 DROP COLUMN C;
> exception COLUMN_IS_REFERENCED_1
DROP VIEW V1;
> ok
ALTER TABLE T1 DROP COLUMN C;
> ok
DROP TABLE T1;
> ok
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论