提交 d7f16c93 authored 作者: Thomas Mueller Graf's avatar Thomas Mueller Graf

Ensure views can not refer to itself

上级 dc45888c
...@@ -824,21 +824,21 @@ public class Database implements DataHandler { ...@@ -824,21 +824,21 @@ public class Database implements DataHandler {
} }
private void recompileInvalidViews(Session session) { private void recompileInvalidViews(Session session) {
boolean recompileSuccessful; boolean atLeastOneRecompiledSuccessfully;
do { do {
recompileSuccessful = false; atLeastOneRecompiledSuccessfully = false;
for (Table obj : getAllTablesAndViews(false)) { for (Table obj : getAllTablesAndViews(false)) {
if (obj instanceof TableView) { if (obj instanceof TableView) {
TableView view = (TableView) obj; TableView view = (TableView) obj;
if (view.isInvalid()) { if (view.isInvalid()) {
view.recompile(session, true, false); view.recompile(session, true, false);
if (!view.isInvalid()) { if (!view.isInvalid()) {
recompileSuccessful = true; atLeastOneRecompiledSuccessfully = true;
} }
} }
} }
} }
} while (recompileSuccessful); } while (atLeastOneRecompiledSuccessfully);
TableView.clearIndexCaches(session.getDatabase()); TableView.clearIndexCaches(session.getDatabase());
} }
......
...@@ -7,6 +7,8 @@ package org.h2.table; ...@@ -7,6 +7,8 @@ package org.h2.table;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashSet; import java.util.HashSet;
import org.h2.api.ErrorCode;
import org.h2.command.Parser; import org.h2.command.Parser;
import org.h2.command.dml.Select; import org.h2.command.dml.Select;
import org.h2.engine.Right; import org.h2.engine.Right;
...@@ -815,6 +817,9 @@ public class TableFilter implements ColumnResolver { ...@@ -815,6 +817,9 @@ public class TableFilter implements ColumnResolver {
return buff.toString(); return buff.toString();
} }
buff.append(table.getSQL()); buff.append(table.getSQL());
if (table.isView() && ((TableView) table).isInvalid()) {
throw DbException.get(ErrorCode.VIEW_IS_INVALID_2, table.getName(), "not compiled");
}
if (alias != null) { if (alias != null) {
buff.append(' ').append(Parser.quoteIdentifier(alias)); buff.append(' ').append(Parser.quoteIdentifier(alias));
} }
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论