提交 2b6a376e authored 作者: Thomas Mueller's avatar Thomas Mueller

It is now allowed to truncate a table if referential integrity has been disabled…

It is now allowed to truncate a table if referential integrity has been disabled for this table or database.
上级 a42ad6d6
......@@ -649,6 +649,7 @@ public class RegularTable extends TableBase {
}
public boolean canTruncate() {
if (getCheckForeignKeyConstraints() && database.getReferentialIntegrity()) {
ArrayList<Constraint> constraints = getConstraints();
for (int i = 0; constraints != null && i < constraints.size(); i++) {
Constraint c = constraints.get(i);
......@@ -660,6 +661,7 @@ public class RegularTable extends TableBase {
return false;
}
}
}
return true;
}
......
......@@ -36,6 +36,7 @@ public class TestCases extends TestBase {
}
public void test() throws Exception {
testTruncateConstraintsDisabled();
testPreparedSubquery2();
testPreparedSubquery();
testCompareDoubleWithIntColumn();
......@@ -81,6 +82,39 @@ public class TestCases extends TestBase {
deleteDb("cases");
}
private void testTruncateConstraintsDisabled() throws SQLException {
deleteDb("cases");
Connection conn = getConnection("cases");
Statement stat = conn.createStatement();
stat.execute("create table parent(id identity) as select 0");
stat.execute("create table child(id identity, parent int references parent(id)) as select 0, 0");
try {
stat.execute("truncate table parent");
fail();
} catch (SQLException e) {
// expected
}
try {
stat.execute("delete from parent");
fail();
} catch (SQLException e) {
// expected
}
stat.execute("alter table parent set referential_integrity false");
stat.execute("delete from parent");
stat.execute("truncate table parent");
stat.execute("alter table parent set referential_integrity true");
try {
stat.execute("truncate table parent");
fail();
} catch (SQLException e) {
// expected
}
stat.execute("set referential_integrity false");
stat.execute("truncate table parent");
conn.close();
}
private void testPreparedSubquery2() throws SQLException {
deleteDb("cases");
Connection conn = getConnection("cases");
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论