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

Global temporary tables are now deleted when closing the database.

上级 09027986
......@@ -1038,7 +1038,11 @@ public class Database implements DataHandler {
if (systemSession != null) {
if (powerOffCount != -1) {
for (Table table : getAllTablesAndViews(false)) {
table.close(systemSession);
if (table.isGlobalTemporary()) {
table.removeChildrenAndResources(systemSession);
} else {
table.close(systemSession);
}
}
for (SchemaObject obj : getAllSchemaObjects(DbObject.SEQUENCE)) {
Sequence sequence = (Sequence) obj;
......
......@@ -6,10 +6,12 @@
*/
package org.h2.test.db;
import java.io.File;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import org.h2.engine.Constants;
import org.h2.test.TestBase;
/**
......@@ -28,6 +30,7 @@ public class TestTempTables extends TestBase {
public void test() throws SQLException {
deleteDb("tempTables");
testDeleteGlobalTempTableWhenClosing();
Connection c1 = getConnection("tempTables");
testAlter(c1);
Connection c2 = getConnection("tempTables");
......@@ -39,6 +42,30 @@ public class TestTempTables extends TestBase {
deleteDb("tempTables");
}
private void testDeleteGlobalTempTableWhenClosing() throws SQLException {
if (config.memory) {
return;
}
deleteDb("tempTables");
Connection conn = getConnection("tempTables");
Statement stat = conn.createStatement();
stat.execute("create global temporary table test(id int, data varchar)");
stat.execute("insert into test select x, space(1000) from system_range(1, 1000)");
stat.execute("shutdown compact");
try {
conn.close();
} catch (SQLException e) {
// expected
}
String dbName = baseDir + "/tempTables" + Constants.SUFFIX_PAGE_FILE;
long before = new File(dbName).length();
assertTrue(before > 0);
conn = getConnection("tempTables");
conn.close();
long after = new File(dbName).length();
assertEquals(after, before);
}
private void testAlter(Connection conn) throws SQLException {
Statement stat;
stat = conn.createStatement();
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论