提交 24817dcb authored 作者: Thomas Mueller's avatar Thomas Mueller

The statement "script drop" create a script that couldn't be executed if a table…

The statement "script drop" create a script that couldn't be executed if a table contained a reference to a user defined function.
上级 72b14eef
......@@ -161,18 +161,6 @@ public class ScriptCommand extends ScriptBase {
Constant constant = (Constant) obj;
add(constant.getCreateSQL(), false);
}
for (SchemaObject obj : db.getAllSchemaObjects(DbObject.FUNCTION_ALIAS)) {
if (drop) {
add(obj.getDropSQL(), false);
}
add(obj.getCreateSQL(), false);
}
for (UserAggregate agg : db.getAllAggregates()) {
if (drop) {
add(agg.getDropSQL(), false);
}
add(agg.getCreateSQL(), false);
}
ArrayList<Table> tables = db.getAllTablesAndViews(false);
// sort by id, so that views are after tables and views on views
// after the base views
......@@ -195,6 +183,18 @@ public class ScriptCommand extends ScriptBase {
add(table.getDropSQL(), false);
}
}
for (SchemaObject obj : db.getAllSchemaObjects(DbObject.FUNCTION_ALIAS)) {
if (drop) {
add(obj.getDropSQL(), false);
}
add(obj.getCreateSQL(), false);
}
for (UserAggregate agg : db.getAllAggregates()) {
if (drop) {
add(agg.getDropSQL(), false);
}
add(agg.getCreateSQL(), false);
}
for (SchemaObject obj : db.getAllSchemaObjects(DbObject.SEQUENCE)) {
Sequence sequence = (Sequence) obj;
if (drop) {
......
......@@ -36,7 +36,7 @@ public abstract class TableBase extends Table {
}
public String getDropSQL() {
return "DROP TABLE IF EXISTS " + getSQL();
return "DROP TABLE IF EXISTS " + getSQL() + " CASCADE";
}
public String getCreateSQL() {
......
......@@ -34,6 +34,8 @@ public class TestRunscript extends TestBase implements Trigger {
}
public void test() throws Exception {
testDropReferencedUserDefinedFunction();
testDropCascade();
testRunscriptFromClasspath();
testCancelScript();
testEncoding();
......@@ -43,6 +45,30 @@ public class TestRunscript extends TestBase implements Trigger {
deleteDb("runscript");
}
private void testDropReferencedUserDefinedFunction() throws Exception {
deleteDb("runscript");
Connection conn;
conn = getConnection("runscript");
Statement stat = conn.createStatement();
stat.execute("create alias decode for \"java.lang.Integer.decode\"");
stat.execute("create table test(x varchar, y int as decode(x))");
stat.execute("script simple drop to '" + getBaseDir() + "/backup.sql'");
stat.execute("runscript from '" + getBaseDir() + "/backup.sql'");
conn.close();
}
private void testDropCascade() throws Exception {
deleteDb("runscript");
Connection conn;
conn = getConnection("runscript");
Statement stat = conn.createStatement();
stat.execute("create table b(x int)");
stat.execute("create view a as select * from b");
stat.execute("script simple drop to '" + getBaseDir() + "/backup.sql'");
stat.execute("runscript from '" + getBaseDir() + "/backup.sql'");
conn.close();
}
private void testRunscriptFromClasspath() throws Exception {
deleteDb("runscript");
Connection conn;
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论