提交 aa7a9f02 authored 作者: Thomas Mueller's avatar Thomas Mueller

New system property h2.dropRestrict (default false) to change the default action…

New system property h2.dropRestrict (default false) to change the default action for DROP TABLE and DROP VIEW.
上级 85de815a
......@@ -6,13 +6,18 @@
*/
package org.h2.command.ddl;
import java.util.ArrayList;
import org.h2.constant.ErrorCode;
import org.h2.constant.SysProperties;
import org.h2.constraint.ConstraintReferential;
import org.h2.engine.Database;
import org.h2.engine.Right;
import org.h2.engine.Session;
import org.h2.message.DbException;
import org.h2.schema.Schema;
import org.h2.table.Table;
import org.h2.table.TableView;
import org.h2.util.StatementBuilder;
/**
* This class represents the statement
......@@ -25,6 +30,7 @@ public class DropTable extends SchemaCommand {
private Table table;
private DropTable next;
private int dropTableId;
private int dropAction = SysProperties.DROP_RESTRICT ? ConstraintReferential.RESTRICT : ConstraintReferential.CASCADE;
public DropTable(Session session, Schema schema) {
super(session, schema);
......@@ -66,6 +72,17 @@ public class DropTable extends SchemaCommand {
if (!table.canDrop()) {
throw DbException.get(ErrorCode.CANNOT_DROP_TABLE_1, tableName);
}
if (dropAction == ConstraintReferential.RESTRICT) {
ArrayList<TableView> views = table.getViews();
if (views != null && views.size() > 0) {
StatementBuilder buff = new StatementBuilder();
for (TableView v : views) {
buff.appendExceptFirst(", ");
buff.append(v.getName());
}
throw DbException.get(ErrorCode.CANNOT_DROP_2, tableName, buff.toString());
}
}
table.lock(session, true, true);
}
if (next != null) {
......@@ -96,4 +113,11 @@ public class DropTable extends SchemaCommand {
return 0;
}
public void setDropAction(int dropAction) {
this.dropAction = dropAction;
if (next != null) {
next.setDropAction(dropAction);
}
}
}
\ No newline at end of file
......@@ -7,6 +7,7 @@
package org.h2.command.ddl;
import org.h2.constant.ErrorCode;
import org.h2.constant.SysProperties;
import org.h2.constraint.ConstraintReferential;
import org.h2.engine.DbObject;
import org.h2.engine.Right;
......@@ -24,7 +25,7 @@ public class DropView extends SchemaCommand {
private String viewName;
private boolean ifExists;
private int dropAction = ConstraintReferential.CASCADE;
private int dropAction = SysProperties.DROP_RESTRICT ? ConstraintReferential.RESTRICT : ConstraintReferential.CASCADE;
public DropView(Session session, Schema schema) {
super(session, schema);
......
--- special grammar and test cases ---------------------------------------------------------------------------------------------
create table test(id int);
> ok
create view x as select * from test;
> ok
drop table test restrict;
> exception
drop table test cascade;
> ok
select 1, 2 from (select * from dual) union all select 3, 4 from dual;
> 1 2
> - -
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论