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

Statement.cancel() did not work when running RUNSCRIPT and SCRIPT.

上级 f848d7da
......@@ -42,6 +42,9 @@ public class RunScriptCommand extends ScriptBase {
}
execute(sql);
count++;
if ((count & 127) == 0) {
checkCanceled();
}
}
reader.close();
} catch (IOException e) {
......
......@@ -195,11 +195,12 @@ public class ScriptCommand extends ScriptBase {
}
for (SchemaObject obj : db.getAllSchemaObjects(DbObject.SEQUENCE)) {
Sequence sequence = (Sequence) obj;
if (drop && !sequence.getBelongsToTable()) {
if (drop) {
add(sequence.getDropSQL(), false);
}
add(sequence.getCreateSQL(), false);
}
int count = 0;
for (Table table : tables) {
if (table.isHidden()) {
continue;
......@@ -272,6 +273,10 @@ public class ScriptCommand extends ScriptBase {
}
}
buff.append(')');
count++;
if ((count & 127) == 0) {
checkCanceled();
}
if (simple || buff.length() > Constants.IO_BUFFER_SIZE) {
add(buff.toString(), true);
buff = null;
......
......@@ -11,6 +11,7 @@ import java.sql.SQLException;
import java.sql.Statement;
import org.h2.api.Trigger;
import org.h2.constant.ErrorCode;
import org.h2.test.TestBase;
import org.h2.util.IOUtils;
......@@ -28,7 +29,8 @@ public class TestRunscript extends TestBase implements Trigger {
TestBase.createCaller().init().test();
}
public void test() throws SQLException {
public void test() throws Exception {
testCancelScript();
testEncoding();
testClobPrimaryKey();
test(false);
......@@ -36,6 +38,59 @@ public class TestRunscript extends TestBase implements Trigger {
deleteDb("runscript");
}
private void testCancelScript() throws Exception {
deleteDb("runscript");
Connection conn;
conn = getConnection("runscript");
final Statement stat = conn.createStatement();
stat.execute("create table test(id int primary key) as select x from system_range(1, 10000)");
stat.execute("script simple drop to '"+getBaseDir()+"/backup.sql'");
stat.execute("set throttle 1000");
final String dir = getBaseDir();
final SQLException[] ex = new SQLException[1];
Thread thread;
SQLException e;
ex[0] = null;
thread = new Thread() {
public void run() {
try {
stat.execute("script simple drop to '"+dir+"/backup2.sql'");
} catch (SQLException e) {
ex[0] = e;
}
}
};
thread.start();
Thread.sleep(100);
stat.cancel();
thread.join();
e = ex[0];
assertTrue(e != null);
assertEquals(ErrorCode.STATEMENT_WAS_CANCELED, e.getErrorCode());
thread = new Thread() {
public void run() {
try {
stat.execute("runscript from '"+dir+"/backup.sql'");
} catch (SQLException e) {
ex[0] = e;
}
}
};
thread.start();
Thread.sleep(100);
stat.cancel();
thread.join();
e = ex[0];
assertTrue(e != null);
assertEquals(ErrorCode.STATEMENT_WAS_CANCELED, e.getErrorCode());
conn.close();
IOUtils.delete(getBaseDir() + "/backup.sql");
IOUtils.delete(getBaseDir() + "/backup2.sql");
}
private void testEncoding() throws SQLException {
deleteDb("runscript");
Connection conn;
......@@ -52,6 +107,7 @@ public class TestRunscript extends TestBase implements Trigger {
stat.execute("runscript from '"+getBaseDir()+"/backup.sql' charset 'UTF-8'");
stat.execute("select * from \"t\u00f6\"");
conn.close();
IOUtils.delete(getBaseDir() + "/backup.sql");
}
/**
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论