提交 f42e330f authored 作者: Noel Grandin's avatar Noel Grandin

don't drop session local temp tables when

doing DROP ALL OBJECTS

leads to an NPE when the session closes
上级 be0f8ddc
......@@ -14,6 +14,7 @@ import org.h2.engine.Session;
import org.h2.engine.User;
import org.h2.schema.Schema;
import org.h2.schema.SchemaObject;
import org.h2.schema.Sequence;
import org.h2.table.Table;
import org.h2.table.TableType;
import org.h2.util.New;
......@@ -83,7 +84,7 @@ public class DropDatabase extends DefineCommand {
runLoopAgain = false;
for (Table t : toRemove) {
if (t.getName() == null) {
// ignore
// ignore, already dead
} else if (db.getDependentTable(t, t) == null) {
db.removeSchemaObject(session, t);
} else {
......@@ -92,15 +93,21 @@ public class DropDatabase extends DefineCommand {
}
} while (runLoopAgain);
// TODO local temp tables are not removed
// TODO session-local temp tables are not removed
for (Schema schema : db.getAllSchemas()) {
if (schema.canDrop()) {
db.removeDatabaseObject(session, schema);
}
}
session.findLocalTempTable(null);
ArrayList<SchemaObject> list = New.arrayList();
list.addAll(db.getAllSchemaObjects(DbObject.SEQUENCE));
for (SchemaObject obj : db.getAllSchemaObjects(DbObject.SEQUENCE)) {
// ignore these. the ones we want to drop will get dropped when we drop
// their associated tables, and we will ignore the problematic ones
// that belong to session-local temp tables.
if (!((Sequence)obj).getBelongsToTable()) {
list.add(obj);
}
}
// maybe constraints and triggers on system tables will be allowed in
// the future
list.addAll(db.getAllSchemaObjects(DbObject.CONSTRAINT));
......
......@@ -5,8 +5,11 @@
*/
package org.h2.engine;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.util.ArrayList;
import org.h2.command.Parser;
import org.h2.message.DbException;
import org.h2.message.Trace;
/**
......@@ -123,16 +126,28 @@ public abstract class DbObjectBase implements DbObject {
return objectName;
}
private String invalidateStackTrace;
/**
* Set the main attributes to null to make sure the object is no longer
* used.
*/
protected void invalidate() {
if (SysProperties.CHECK && id == -1) {
throw DbException.throwInternalError();
}
setModified();
id = -1;
database = null;
trace = null;
objectName = null;
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
new Throwable().printStackTrace(pw);
invalidateStackTrace = sw.toString();
}
public final boolean isValid() {
return id != -1;
}
@Override
......
......@@ -34,7 +34,8 @@ public class TestRandomSQL extends TestBase {
if (config.networked) {
return;
}
int len = getSize(2, 6);
config.memory = true;
int len = 567897; // getSize(2, 6);
for (int a = 0; a < len; a++) {
int s = MathUtils.randomInt(Integer.MAX_VALUE);
testCase(s);
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论