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

Use the result interface instead of the class (prepare for server side cursors).

上级 ef9a67cb
...@@ -7,7 +7,6 @@ ...@@ -7,7 +7,6 @@
package org.h2.command; package org.h2.command;
import java.sql.SQLException; import java.sql.SQLException;
import org.h2.constant.ErrorCode; import org.h2.constant.ErrorCode;
import org.h2.engine.Constants; import org.h2.engine.Constants;
import org.h2.engine.Database; import org.h2.engine.Database;
...@@ -16,7 +15,6 @@ import org.h2.expression.ParameterInterface; ...@@ -16,7 +15,6 @@ import org.h2.expression.ParameterInterface;
import org.h2.message.Message; import org.h2.message.Message;
import org.h2.message.Trace; import org.h2.message.Trace;
import org.h2.message.TraceObject; import org.h2.message.TraceObject;
import org.h2.result.LocalResult;
import org.h2.result.ResultInterface; import org.h2.result.ResultInterface;
import org.h2.util.MemoryUtils; import org.h2.util.MemoryUtils;
import org.h2.util.ObjectArray; import org.h2.util.ObjectArray;
...@@ -88,7 +86,7 @@ public abstract class Command implements CommandInterface { ...@@ -88,7 +86,7 @@ public abstract class Command implements CommandInterface {
* *
* @return an empty result set * @return an empty result set
*/ */
public abstract LocalResult queryMeta() throws SQLException; public abstract ResultInterface queryMeta() throws SQLException;
/** /**
* Execute an updating statement, if this is possible. * Execute an updating statement, if this is possible.
...@@ -107,30 +105,23 @@ public abstract class Command implements CommandInterface { ...@@ -107,30 +105,23 @@ public abstract class Command implements CommandInterface {
* @return the local result set * @return the local result set
* @throws SQLException if the command is not a query * @throws SQLException if the command is not a query
*/ */
public LocalResult query(int maxrows) throws SQLException { public ResultInterface query(int maxrows) throws SQLException {
throw Message.getSQLException(ErrorCode.METHOD_ONLY_ALLOWED_FOR_QUERY); throw Message.getSQLException(ErrorCode.METHOD_ONLY_ALLOWED_FOR_QUERY);
} }
public final LocalResult getMetaDataLocal() throws SQLException {
return queryMeta();
}
public final ResultInterface getMetaData() throws SQLException { public final ResultInterface getMetaData() throws SQLException {
return queryMeta(); return queryMeta();
} }
public ResultInterface executeQuery(int maxrows, boolean scrollable) throws SQLException {
return executeQueryLocal(maxrows);
}
/** /**
* Execute a query and return a local result set. * Execute a query and return the result.
* This method prepares everything and calls {@link #query(int)} finally. * This method prepares everything and calls {@link #query(int)} finally.
* *
* @param maxrows the maximum number of rows to return * @param maxrows the maximum number of rows to return
* @return the local result set * @param scrollable if the result set must be scrollable (ignored)
* @return the result set
*/ */
public LocalResult executeQueryLocal(int maxrows) throws SQLException { public ResultInterface executeQuery(int maxrows, boolean scrollable) throws SQLException {
startTime = System.currentTimeMillis(); startTime = System.currentTimeMillis();
Database database = session.getDatabase(); Database database = session.getDatabase();
Object sync = database.isMultiThreaded() ? (Object) session : (Object) database; Object sync = database.isMultiThreaded() ? (Object) session : (Object) database;
...@@ -190,7 +181,6 @@ public abstract class Command implements CommandInterface { ...@@ -190,7 +181,6 @@ public abstract class Command implements CommandInterface {
trace.info("slow query: " + time); trace.info("slow query: " + time);
} }
} }
session.getDatabase().afterWriting();
} }
public int executeUpdate() throws SQLException { public int executeUpdate() throws SQLException {
...@@ -199,6 +189,8 @@ public abstract class Command implements CommandInterface { ...@@ -199,6 +189,8 @@ public abstract class Command implements CommandInterface {
MemoryUtils.allocateReserveMemory(); MemoryUtils.allocateReserveMemory();
Object sync = database.isMultiThreaded() ? (Object) session : (Object) database; Object sync = database.isMultiThreaded() ? (Object) session : (Object) database;
session.waitIfExclusiveModeEnabled(); session.waitIfExclusiveModeEnabled();
boolean callStop = true;
session.getDatabase().beforeWriting();
synchronized (sync) { synchronized (sync) {
int rollback = session.getLogId(); int rollback = session.getLogId();
session.setCurrentCommand(this, startTime); session.setCurrentCommand(this, startTime);
...@@ -238,25 +230,25 @@ public abstract class Command implements CommandInterface { ...@@ -238,25 +230,25 @@ public abstract class Command implements CommandInterface {
if (e.getErrorCode() == ErrorCode.DEADLOCK_1) { if (e.getErrorCode() == ErrorCode.DEADLOCK_1) {
session.rollback(); session.rollback();
} else if (e.getErrorCode() == ErrorCode.OUT_OF_MEMORY) { } else if (e.getErrorCode() == ErrorCode.OUT_OF_MEMORY) {
// try to rollback, saving memory // there is a serious problem:
try { // the transaction may be applied partially
session.rollbackTo(rollback, true); // in this case we need to panic:
} catch (SQLException e2) { // close the database
if (e2.getErrorCode() == ErrorCode.OUT_OF_MEMORY) { callStop = false;
// if rollback didn't work, there is a serious problem: session.getDatabase().shutdownImmediately();
// the transaction may be applied partially throw e;
// in this case we need to panic:
// close the database
session.getDatabase().shutdownImmediately();
}
throw e2;
}
} else { } else {
session.rollbackTo(rollback, false); session.rollbackTo(rollback, false);
} }
throw e; throw e;
} finally { } finally {
stop(); try {
if (callStop) {
stop();
}
} finally {
session.getDatabase().afterWriting();
}
} }
} }
} }
......
...@@ -7,10 +7,9 @@ ...@@ -7,10 +7,9 @@
package org.h2.command; package org.h2.command;
import java.sql.SQLException; import java.sql.SQLException;
import org.h2.expression.Parameter; import org.h2.expression.Parameter;
import org.h2.expression.ParameterInterface; import org.h2.expression.ParameterInterface;
import org.h2.result.LocalResult; import org.h2.result.ResultInterface;
import org.h2.util.ObjectArray; import org.h2.util.ObjectArray;
import org.h2.value.Value; import org.h2.value.Value;
...@@ -74,12 +73,12 @@ public class CommandContainer extends Command { ...@@ -74,12 +73,12 @@ public class CommandContainer extends Command {
return updateCount; return updateCount;
} }
public LocalResult query(int maxrows) throws SQLException { public ResultInterface query(int maxrows) throws SQLException {
recompileIfRequired(); recompileIfRequired();
// TODO query time: should keep lock time separate from running time // TODO query time: should keep lock time separate from running time
start(); start();
prepared.checkParameters(); prepared.checkParameters();
LocalResult result = prepared.query(maxrows); ResultInterface result = prepared.query(maxrows);
prepared.trace(startTime, result.getRowCount()); prepared.trace(startTime, result.getRowCount());
return result; return result;
} }
...@@ -88,7 +87,7 @@ public class CommandContainer extends Command { ...@@ -88,7 +87,7 @@ public class CommandContainer extends Command {
return prepared.isReadOnly(); return prepared.isReadOnly();
} }
public LocalResult queryMeta() throws SQLException { public ResultInterface queryMeta() throws SQLException {
return prepared.queryMeta(); return prepared.queryMeta();
} }
......
...@@ -7,9 +7,8 @@ ...@@ -7,9 +7,8 @@
package org.h2.command; package org.h2.command;
import java.sql.SQLException; import java.sql.SQLException;
import org.h2.expression.ParameterInterface; import org.h2.expression.ParameterInterface;
import org.h2.result.LocalResult; import org.h2.result.ResultInterface;
import org.h2.util.ObjectArray; import org.h2.util.ObjectArray;
/** /**
...@@ -45,8 +44,8 @@ public class CommandList extends Command { ...@@ -45,8 +44,8 @@ public class CommandList extends Command {
return updateCount; return updateCount;
} }
public LocalResult query(int maxrows) throws SQLException { public ResultInterface query(int maxrows) throws SQLException {
LocalResult result = command.query(maxrows); ResultInterface result = command.query(maxrows);
executeRemaining(); executeRemaining();
return result; return result;
} }
...@@ -63,7 +62,7 @@ public class CommandList extends Command { ...@@ -63,7 +62,7 @@ public class CommandList extends Command {
return false; return false;
} }
public LocalResult queryMeta() throws SQLException { public ResultInterface queryMeta() throws SQLException {
return command.queryMeta(); return command.queryMeta();
} }
......
...@@ -7,7 +7,6 @@ ...@@ -7,7 +7,6 @@
package org.h2.command; package org.h2.command;
import java.sql.SQLException; import java.sql.SQLException;
import org.h2.constant.ErrorCode; import org.h2.constant.ErrorCode;
import org.h2.constant.SysProperties; import org.h2.constant.SysProperties;
import org.h2.engine.Database; import org.h2.engine.Database;
...@@ -17,7 +16,7 @@ import org.h2.expression.Parameter; ...@@ -17,7 +16,7 @@ import org.h2.expression.Parameter;
import org.h2.index.Index; import org.h2.index.Index;
import org.h2.jdbc.JdbcSQLException; import org.h2.jdbc.JdbcSQLException;
import org.h2.message.Message; import org.h2.message.Message;
import org.h2.result.LocalResult; import org.h2.result.ResultInterface;
import org.h2.util.ObjectArray; import org.h2.util.ObjectArray;
import org.h2.util.StatementBuilder; import org.h2.util.StatementBuilder;
import org.h2.value.Value; import org.h2.value.Value;
...@@ -81,9 +80,9 @@ public abstract class Prepared { ...@@ -81,9 +80,9 @@ public abstract class Prepared {
/** /**
* Get an empty result set containing the meta data. * Get an empty result set containing the meta data.
* *
* @return an empty result set * @return the result set
*/ */
public abstract LocalResult queryMeta() throws SQLException; public abstract ResultInterface queryMeta() throws SQLException;
/** /**
* Check if this command is read only. * Check if this command is read only.
...@@ -202,7 +201,7 @@ public abstract class Prepared { ...@@ -202,7 +201,7 @@ public abstract class Prepared {
* @return the result set * @return the result set
* @throws SQLException if it is not a query * @throws SQLException if it is not a query
*/ */
public LocalResult query(int maxrows) throws SQLException { public ResultInterface query(int maxrows) throws SQLException {
throw Message.getSQLException(ErrorCode.METHOD_ONLY_ALLOWED_FOR_QUERY); throw Message.getSQLException(ErrorCode.METHOD_ONLY_ALLOWED_FOR_QUERY);
} }
......
...@@ -7,7 +7,6 @@ ...@@ -7,7 +7,6 @@
package org.h2.command.ddl; package org.h2.command.ddl;
import java.sql.SQLException; import java.sql.SQLException;
import org.h2.command.Parser; import org.h2.command.Parser;
import org.h2.command.Prepared; import org.h2.command.Prepared;
import org.h2.constant.ErrorCode; import org.h2.constant.ErrorCode;
...@@ -21,7 +20,7 @@ import org.h2.expression.Expression; ...@@ -21,7 +20,7 @@ import org.h2.expression.Expression;
import org.h2.index.Index; import org.h2.index.Index;
import org.h2.index.IndexType; import org.h2.index.IndexType;
import org.h2.message.Message; import org.h2.message.Message;
import org.h2.result.LocalResult; import org.h2.result.ResultInterface;
import org.h2.schema.Schema; import org.h2.schema.Schema;
import org.h2.schema.SchemaObject; import org.h2.schema.SchemaObject;
import org.h2.schema.Sequence; import org.h2.schema.Sequence;
...@@ -412,7 +411,7 @@ public class AlterTableAlterColumn extends SchemaCommand { ...@@ -412,7 +411,7 @@ public class AlterTableAlterColumn extends SchemaCommand {
private void checkNoNullValues() throws SQLException { private void checkNoNullValues() throws SQLException {
String sql = "SELECT COUNT(*) FROM " + table.getSQL() + " WHERE " + oldColumn.getSQL() + " IS NULL"; String sql = "SELECT COUNT(*) FROM " + table.getSQL() + " WHERE " + oldColumn.getSQL() + " IS NULL";
Prepared command = session.prepare(sql); Prepared command = session.prepare(sql);
LocalResult result = command.query(0); ResultInterface result = command.query(0);
result.next(); result.next();
if (result.currentRow()[0].getInt() > 0) { if (result.currentRow()[0].getInt() > 0) {
throw Message.getSQLException(ErrorCode.COLUMN_CONTAINS_NULL_VALUES_1, oldColumn.getSQL()); throw Message.getSQLException(ErrorCode.COLUMN_CONTAINS_NULL_VALUES_1, oldColumn.getSQL());
......
...@@ -11,7 +11,7 @@ import org.h2.command.Prepared; ...@@ -11,7 +11,7 @@ import org.h2.command.Prepared;
import org.h2.engine.Constants; import org.h2.engine.Constants;
import org.h2.engine.Database; import org.h2.engine.Database;
import org.h2.engine.Session; import org.h2.engine.Session;
import org.h2.result.LocalResult; import org.h2.result.ResultInterface;
import org.h2.table.Column; import org.h2.table.Column;
import org.h2.table.Table; import org.h2.table.Table;
import org.h2.table.TableData; import org.h2.table.TableData;
...@@ -50,7 +50,7 @@ public class Analyze extends DefineCommand { ...@@ -50,7 +50,7 @@ public class Analyze extends DefineCommand {
} }
String sql = buff.toString(); String sql = buff.toString();
Prepared command = session.prepare(sql); Prepared command = session.prepare(sql);
LocalResult result = command.query(0); ResultInterface result = command.query(0);
result.next(); result.next();
for (int j = 0; j < columns.length; j++) { for (int j = 0; j < columns.length; j++) {
int selectivity = result.currentRow()[j].getInt(); int selectivity = result.currentRow()[j].getInt();
......
...@@ -8,7 +8,7 @@ package org.h2.command.ddl; ...@@ -8,7 +8,7 @@ package org.h2.command.ddl;
import org.h2.command.Prepared; import org.h2.command.Prepared;
import org.h2.engine.Session; import org.h2.engine.Session;
import org.h2.result.LocalResult; import org.h2.result.ResultInterface;
/** /**
* This class represents a non-transaction statement, for example a CREATE or * This class represents a non-transaction statement, for example a CREATE or
...@@ -33,7 +33,7 @@ public abstract class DefineCommand extends Prepared { ...@@ -33,7 +33,7 @@ public abstract class DefineCommand extends Prepared {
return false; return false;
} }
public LocalResult queryMeta() { public ResultInterface queryMeta() {
return null; return null;
} }
......
...@@ -23,7 +23,7 @@ import org.h2.expression.Expression; ...@@ -23,7 +23,7 @@ import org.h2.expression.Expression;
import org.h2.log.LogFile; import org.h2.log.LogFile;
import org.h2.log.LogSystem; import org.h2.log.LogSystem;
import org.h2.message.Message; import org.h2.message.Message;
import org.h2.result.LocalResult; import org.h2.result.ResultInterface;
import org.h2.store.DiskFile; import org.h2.store.DiskFile;
import org.h2.store.FileLister; import org.h2.store.FileLister;
import org.h2.store.PageStore; import org.h2.store.PageStore;
...@@ -179,7 +179,7 @@ public class BackupCommand extends Prepared { ...@@ -179,7 +179,7 @@ public class BackupCommand extends Prepared {
return false; return false;
} }
public LocalResult queryMeta() { public ResultInterface queryMeta() {
return null; return null;
} }
......
...@@ -8,13 +8,13 @@ package org.h2.command.dml; ...@@ -8,13 +8,13 @@ package org.h2.command.dml;
import java.sql.ResultSet; import java.sql.ResultSet;
import java.sql.SQLException; import java.sql.SQLException;
import org.h2.command.Prepared; import org.h2.command.Prepared;
import org.h2.engine.Session; import org.h2.engine.Session;
import org.h2.expression.Expression; import org.h2.expression.Expression;
import org.h2.expression.ExpressionColumn; import org.h2.expression.ExpressionColumn;
import org.h2.expression.ExpressionVisitor; import org.h2.expression.ExpressionVisitor;
import org.h2.result.LocalResult; import org.h2.result.LocalResult;
import org.h2.result.ResultInterface;
import org.h2.table.Column; import org.h2.table.Column;
import org.h2.util.ObjectArray; import org.h2.util.ObjectArray;
import org.h2.value.Value; import org.h2.value.Value;
...@@ -33,7 +33,7 @@ public class Call extends Prepared { ...@@ -33,7 +33,7 @@ public class Call extends Prepared {
super(session); super(session);
} }
public LocalResult queryMeta() throws SQLException { public ResultInterface queryMeta() throws SQLException {
LocalResult result = new LocalResult(session, expressions, 1); LocalResult result = new LocalResult(session, expressions, 1);
result.done(); result.done();
return result; return result;
...@@ -56,7 +56,7 @@ public class Call extends Prepared { ...@@ -56,7 +56,7 @@ public class Call extends Prepared {
} }
} }
public LocalResult query(int maxrows) throws SQLException { public ResultInterface query(int maxrows) throws SQLException {
setCurrentRowNumber(1); setCurrentRowNumber(1);
Value v = value.getValue(session); Value v = value.getValue(session);
if (v.getType() == Value.RESULT_SET) { if (v.getType() == Value.RESULT_SET) {
......
...@@ -7,13 +7,12 @@ ...@@ -7,13 +7,12 @@
package org.h2.command.dml; package org.h2.command.dml;
import java.sql.SQLException; import java.sql.SQLException;
import org.h2.command.Prepared; import org.h2.command.Prepared;
import org.h2.engine.Right; import org.h2.engine.Right;
import org.h2.engine.Session; import org.h2.engine.Session;
import org.h2.expression.Expression; import org.h2.expression.Expression;
import org.h2.log.UndoLogRecord; import org.h2.log.UndoLogRecord;
import org.h2.result.LocalResult; import org.h2.result.ResultInterface;
import org.h2.result.Row; import org.h2.result.Row;
import org.h2.result.RowList; import org.h2.result.RowList;
import org.h2.table.PlanItem; import org.h2.table.PlanItem;
...@@ -108,7 +107,7 @@ public class Delete extends Prepared { ...@@ -108,7 +107,7 @@ public class Delete extends Prepared {
return true; return true;
} }
public LocalResult queryMeta() { public ResultInterface queryMeta() {
return null; return null;
} }
......
...@@ -7,13 +7,12 @@ ...@@ -7,13 +7,12 @@
package org.h2.command.dml; package org.h2.command.dml;
import java.sql.SQLException; import java.sql.SQLException;
import org.h2.command.Prepared; import org.h2.command.Prepared;
import org.h2.engine.Procedure; import org.h2.engine.Procedure;
import org.h2.engine.Session; import org.h2.engine.Session;
import org.h2.expression.Expression; import org.h2.expression.Expression;
import org.h2.expression.Parameter; import org.h2.expression.Parameter;
import org.h2.result.LocalResult; import org.h2.result.ResultInterface;
import org.h2.util.ObjectArray; import org.h2.util.ObjectArray;
/** /**
...@@ -64,7 +63,7 @@ public class ExecuteProcedure extends Prepared { ...@@ -64,7 +63,7 @@ public class ExecuteProcedure extends Prepared {
return prepared.update(); return prepared.update();
} }
public final LocalResult query(int limit) throws SQLException { public ResultInterface query(int limit) throws SQLException {
setParameters(); setParameters();
Prepared prepared = procedure.getPrepared(); Prepared prepared = procedure.getPrepared();
return prepared.query(limit); return prepared.query(limit);
...@@ -74,7 +73,7 @@ public class ExecuteProcedure extends Prepared { ...@@ -74,7 +73,7 @@ public class ExecuteProcedure extends Prepared {
return true; return true;
} }
public LocalResult queryMeta() throws SQLException { public ResultInterface queryMeta() throws SQLException {
Prepared prepared = procedure.getPrepared(); Prepared prepared = procedure.getPrepared();
return prepared.queryMeta(); return prepared.queryMeta();
} }
......
...@@ -7,12 +7,12 @@ ...@@ -7,12 +7,12 @@
package org.h2.command.dml; package org.h2.command.dml;
import java.sql.SQLException; import java.sql.SQLException;
import org.h2.command.Prepared; import org.h2.command.Prepared;
import org.h2.engine.Session; import org.h2.engine.Session;
import org.h2.expression.Expression; import org.h2.expression.Expression;
import org.h2.expression.ExpressionColumn; import org.h2.expression.ExpressionColumn;
import org.h2.result.LocalResult; import org.h2.result.LocalResult;
import org.h2.result.ResultInterface;
import org.h2.table.Column; import org.h2.table.Column;
import org.h2.value.Value; import org.h2.value.Value;
import org.h2.value.ValueString; import org.h2.value.ValueString;
...@@ -38,11 +38,11 @@ public class ExplainPlan extends Prepared { ...@@ -38,11 +38,11 @@ public class ExplainPlan extends Prepared {
command.prepare(); command.prepare();
} }
public LocalResult queryMeta() throws SQLException { public ResultInterface queryMeta() throws SQLException {
return query(-1); return query(-1);
} }
public LocalResult query(int maxrows) throws SQLException { public ResultInterface query(int maxrows) throws SQLException {
Column column = new Column("PLAN", Value.STRING); Column column = new Column("PLAN", Value.STRING);
ExpressionColumn expr = new ExpressionColumn(session.getDatabase(), column); ExpressionColumn expr = new ExpressionColumn(session.getDatabase(), column);
Expression[] expressions = new Expression[] { Expression[] expressions = new Expression[] {
......
...@@ -7,7 +7,6 @@ ...@@ -7,7 +7,6 @@
package org.h2.command.dml; package org.h2.command.dml;
import java.sql.SQLException; import java.sql.SQLException;
import org.h2.command.Command; import org.h2.command.Command;
import org.h2.command.Prepared; import org.h2.command.Prepared;
import org.h2.constant.ErrorCode; import org.h2.constant.ErrorCode;
...@@ -19,7 +18,7 @@ import org.h2.expression.Parameter; ...@@ -19,7 +18,7 @@ import org.h2.expression.Parameter;
import org.h2.index.PageIndex; import org.h2.index.PageIndex;
import org.h2.log.UndoLogRecord; import org.h2.log.UndoLogRecord;
import org.h2.message.Message; import org.h2.message.Message;
import org.h2.result.LocalResult; import org.h2.result.ResultInterface;
import org.h2.result.Row; import org.h2.result.Row;
import org.h2.table.Column; import org.h2.table.Column;
import org.h2.table.Table; import org.h2.table.Table;
...@@ -123,7 +122,7 @@ public class Insert extends Prepared { ...@@ -123,7 +122,7 @@ public class Insert extends Prepared {
count++; count++;
} }
} else { } else {
LocalResult rows = query.query(0); ResultInterface rows = query.query(0);
count = 0; count = 0;
table.fireBefore(session); table.fireBefore(session);
table.lock(session, true, false); table.lock(session, true, false);
...@@ -225,7 +224,7 @@ public class Insert extends Prepared { ...@@ -225,7 +224,7 @@ public class Insert extends Prepared {
return true; return true;
} }
public LocalResult queryMeta() { public ResultInterface queryMeta() {
return null; return null;
} }
......
...@@ -7,7 +7,6 @@ ...@@ -7,7 +7,6 @@
package org.h2.command.dml; package org.h2.command.dml;
import java.sql.SQLException; import java.sql.SQLException;
import org.h2.command.Command; import org.h2.command.Command;
import org.h2.command.Prepared; import org.h2.command.Prepared;
import org.h2.constant.ErrorCode; import org.h2.constant.ErrorCode;
...@@ -18,7 +17,7 @@ import org.h2.expression.Parameter; ...@@ -18,7 +17,7 @@ import org.h2.expression.Parameter;
import org.h2.index.Index; import org.h2.index.Index;
import org.h2.log.UndoLogRecord; import org.h2.log.UndoLogRecord;
import org.h2.message.Message; import org.h2.message.Message;
import org.h2.result.LocalResult; import org.h2.result.ResultInterface;
import org.h2.result.Row; import org.h2.result.Row;
import org.h2.table.Column; import org.h2.table.Column;
import org.h2.table.Table; import org.h2.table.Table;
...@@ -127,7 +126,7 @@ public class Merge extends Prepared { ...@@ -127,7 +126,7 @@ public class Merge extends Prepared {
count++; count++;
} }
} else { } else {
LocalResult rows = query.query(0); ResultInterface rows = query.query(0);
count = 0; count = 0;
table.fireBefore(session); table.fireBefore(session);
table.lock(session, true, false); table.lock(session, true, false);
...@@ -269,7 +268,7 @@ public class Merge extends Prepared { ...@@ -269,7 +268,7 @@ public class Merge extends Prepared {
return true; return true;
} }
public LocalResult queryMeta() { public ResultInterface queryMeta() {
return null; return null;
} }
......
...@@ -8,7 +8,7 @@ package org.h2.command.dml; ...@@ -8,7 +8,7 @@ package org.h2.command.dml;
import org.h2.command.Prepared; import org.h2.command.Prepared;
import org.h2.engine.Session; import org.h2.engine.Session;
import org.h2.result.LocalResult; import org.h2.result.ResultInterface;
/** /**
* Represents an empty statement or a statement that has no effect. * Represents an empty statement or a statement that has no effect.
...@@ -39,7 +39,7 @@ public class NoOperation extends Prepared { ...@@ -39,7 +39,7 @@ public class NoOperation extends Prepared {
return true; return true;
} }
public LocalResult queryMeta() { public ResultInterface queryMeta() {
return null; return null;
} }
......
...@@ -21,6 +21,7 @@ import org.h2.expression.Parameter; ...@@ -21,6 +21,7 @@ import org.h2.expression.Parameter;
import org.h2.expression.ValueExpression; import org.h2.expression.ValueExpression;
import org.h2.message.Message; import org.h2.message.Message;
import org.h2.result.LocalResult; import org.h2.result.LocalResult;
import org.h2.result.ResultInterface;
import org.h2.result.SortOrder; import org.h2.result.SortOrder;
import org.h2.table.ColumnResolver; import org.h2.table.ColumnResolver;
import org.h2.table.Table; import org.h2.table.Table;
...@@ -214,7 +215,7 @@ public abstract class Query extends Prepared { ...@@ -214,7 +215,7 @@ public abstract class Query extends Prepared {
return params; return params;
} }
public LocalResult query(int limit) throws SQLException { public ResultInterface query(int limit) throws SQLException {
if (!session.getDatabase().getOptimizeReuseResults()) { if (!session.getDatabase().getOptimizeReuseResults()) {
return queryWithoutCache(limit); return queryWithoutCache(limit);
} }
......
...@@ -14,7 +14,7 @@ import org.h2.command.Prepared; ...@@ -14,7 +14,7 @@ import org.h2.command.Prepared;
import org.h2.constant.SysProperties; import org.h2.constant.SysProperties;
import org.h2.engine.Session; import org.h2.engine.Session;
import org.h2.message.Message; import org.h2.message.Message;
import org.h2.result.LocalResult; import org.h2.result.ResultInterface;
import org.h2.util.ScriptReader; import org.h2.util.ScriptReader;
/** /**
...@@ -73,7 +73,7 @@ public class RunScriptCommand extends ScriptBase { ...@@ -73,7 +73,7 @@ public class RunScriptCommand extends ScriptBase {
this.charset = charset; this.charset = charset;
} }
public LocalResult queryMeta() { public ResultInterface queryMeta() {
return null; return null;
} }
......
...@@ -36,6 +36,7 @@ import org.h2.index.Cursor; ...@@ -36,6 +36,7 @@ import org.h2.index.Cursor;
import org.h2.index.Index; import org.h2.index.Index;
import org.h2.message.Message; import org.h2.message.Message;
import org.h2.result.LocalResult; import org.h2.result.LocalResult;
import org.h2.result.ResultInterface;
import org.h2.result.Row; import org.h2.result.Row;
import org.h2.schema.Constant; import org.h2.schema.Constant;
import org.h2.schema.Schema; import org.h2.schema.Schema;
...@@ -103,7 +104,7 @@ public class ScriptCommand extends ScriptBase { ...@@ -103,7 +104,7 @@ public class ScriptCommand extends ScriptBase {
this.drop = drop; this.drop = drop;
} }
public LocalResult queryMeta() throws SQLException { public ResultInterface queryMeta() throws SQLException {
LocalResult r = createResult(); LocalResult r = createResult();
r.done(); r.done();
return r; return r;
...@@ -115,7 +116,7 @@ public class ScriptCommand extends ScriptBase { ...@@ -115,7 +116,7 @@ public class ScriptCommand extends ScriptBase {
return new LocalResult(session, expressions, 1); return new LocalResult(session, expressions, 1);
} }
public LocalResult query(int maxrows) throws SQLException { public ResultInterface query(int maxrows) throws SQLException {
session.getUser().checkAdmin(); session.getUser().checkAdmin();
reset(); reset();
try { try {
...@@ -318,7 +319,8 @@ public class ScriptCommand extends ScriptBase { ...@@ -318,7 +319,8 @@ public class ScriptCommand extends ScriptBase {
private int writeLobStream(ValueLob v) throws IOException, SQLException { private int writeLobStream(ValueLob v) throws IOException, SQLException {
if (!tempLobTableCreated) { if (!tempLobTableCreated) {
add("CREATE TABLE IF NOT EXISTS SYSTEM_LOB_STREAM(ID INT, PART INT, CDATA VARCHAR, BDATA BINARY, PRIMARY KEY(ID, PART))", true); add("CREATE TABLE IF NOT EXISTS SYSTEM_LOB_STREAM(ID INT NOT NULL, PART INT NOT NULL, CDATA VARCHAR, BDATA BINARY)", true);
add("CREATE PRIMARY KEY SYSTEM_LOB_STREAM_PRIMARY_KEY ON SYSTEM_LOB_STREAM(ID, PART)", true);
add("CREATE ALIAS IF NOT EXISTS SYSTEM_COMBINE_CLOB FOR \"" + this.getClass().getName() + ".combineClob\"", true); add("CREATE ALIAS IF NOT EXISTS SYSTEM_COMBINE_CLOB FOR \"" + this.getClass().getName() + ".combineClob\"", true);
add("CREATE ALIAS IF NOT EXISTS SYSTEM_COMBINE_BLOB FOR \"" + this.getClass().getName() + ".combineBlob\"", true); add("CREATE ALIAS IF NOT EXISTS SYSTEM_COMBINE_BLOB FOR \"" + this.getClass().getName() + ".combineBlob\"", true);
tempLobTableCreated = true; tempLobTableCreated = true;
......
...@@ -28,6 +28,7 @@ import org.h2.index.Index; ...@@ -28,6 +28,7 @@ import org.h2.index.Index;
import org.h2.index.IndexType; import org.h2.index.IndexType;
import org.h2.message.Message; import org.h2.message.Message;
import org.h2.result.LocalResult; import org.h2.result.LocalResult;
import org.h2.result.ResultInterface;
import org.h2.result.SearchRow; import org.h2.result.SearchRow;
import org.h2.result.SortOrder; import org.h2.result.SortOrder;
import org.h2.table.Column; import org.h2.table.Column;
...@@ -515,7 +516,7 @@ public class Select extends Query { ...@@ -515,7 +516,7 @@ public class Select extends Query {
result.addRow(row); result.addRow(row);
} }
public LocalResult queryMeta() throws SQLException { public ResultInterface queryMeta() throws SQLException {
LocalResult result = new LocalResult(session, expressions, visibleColumnCount); LocalResult result = new LocalResult(session, expressions, visibleColumnCount);
result.done(); result.done();
return result; return result;
......
...@@ -19,6 +19,7 @@ import org.h2.expression.Parameter; ...@@ -19,6 +19,7 @@ import org.h2.expression.Parameter;
import org.h2.expression.ValueExpression; import org.h2.expression.ValueExpression;
import org.h2.message.Message; import org.h2.message.Message;
import org.h2.result.LocalResult; import org.h2.result.LocalResult;
import org.h2.result.ResultInterface;
import org.h2.result.SortOrder; import org.h2.result.SortOrder;
import org.h2.table.Column; import org.h2.table.Column;
import org.h2.table.ColumnResolver; import org.h2.table.ColumnResolver;
...@@ -92,7 +93,7 @@ public class SelectUnion extends Query { ...@@ -92,7 +93,7 @@ public class SelectUnion extends Query {
return values; return values;
} }
public LocalResult queryMeta() throws SQLException { public ResultInterface queryMeta() throws SQLException {
ObjectArray<Expression> leftExpressions = left.getExpressions(); ObjectArray<Expression> leftExpressions = left.getExpressions();
int columnCount = left.getColumnCount(); int columnCount = left.getColumnCount();
LocalResult result = new LocalResult(session, leftExpressions, columnCount); LocalResult result = new LocalResult(session, leftExpressions, columnCount);
...@@ -131,8 +132,8 @@ public class SelectUnion extends Query { ...@@ -131,8 +132,8 @@ public class SelectUnion extends Query {
default: default:
Message.throwInternalError("type=" + unionType); Message.throwInternalError("type=" + unionType);
} }
LocalResult l = left.query(0); ResultInterface l = left.query(0);
LocalResult r = right.query(0); ResultInterface r = right.query(0);
l.reset(); l.reset();
r.reset(); r.reset();
switch (unionType) { switch (unionType) {
...@@ -330,7 +331,7 @@ public class SelectUnion extends Query { ...@@ -330,7 +331,7 @@ public class SelectUnion extends Query {
return buff.toString(); return buff.toString();
} }
public LocalResult query(int limit) throws SQLException { public ResultInterface query(int limit) throws SQLException {
// union doesn't always know the parameter list of the left and right queries // union doesn't always know the parameter list of the left and right queries
return queryWithoutCache(limit); return queryWithoutCache(limit);
} }
......
...@@ -8,7 +8,6 @@ package org.h2.command.dml; ...@@ -8,7 +8,6 @@ package org.h2.command.dml;
import java.sql.SQLException; import java.sql.SQLException;
import java.text.Collator; import java.text.Collator;
import org.h2.command.Prepared; import org.h2.command.Prepared;
import org.h2.compress.Compressor; import org.h2.compress.Compressor;
import org.h2.constant.ErrorCode; import org.h2.constant.ErrorCode;
...@@ -19,7 +18,7 @@ import org.h2.engine.Setting; ...@@ -19,7 +18,7 @@ import org.h2.engine.Setting;
import org.h2.expression.Expression; import org.h2.expression.Expression;
import org.h2.expression.ValueExpression; import org.h2.expression.ValueExpression;
import org.h2.message.Message; import org.h2.message.Message;
import org.h2.result.LocalResult; import org.h2.result.ResultInterface;
import org.h2.schema.Schema; import org.h2.schema.Schema;
import org.h2.table.Table; import org.h2.table.Table;
import org.h2.tools.CompressTool; import org.h2.tools.CompressTool;
...@@ -370,7 +369,7 @@ public class Set extends Prepared { ...@@ -370,7 +369,7 @@ public class Set extends Prepared {
return false; return false;
} }
public LocalResult queryMeta() { public ResultInterface queryMeta() {
return null; return null;
} }
......
...@@ -7,13 +7,12 @@ ...@@ -7,13 +7,12 @@
package org.h2.command.dml; package org.h2.command.dml;
import java.sql.SQLException; import java.sql.SQLException;
import org.h2.command.Prepared; import org.h2.command.Prepared;
import org.h2.engine.Database; import org.h2.engine.Database;
import org.h2.engine.Session; import org.h2.engine.Session;
import org.h2.log.LogSystem; import org.h2.log.LogSystem;
import org.h2.message.Message; import org.h2.message.Message;
import org.h2.result.LocalResult; import org.h2.result.ResultInterface;
/** /**
* Represents a transactional statement. * Represents a transactional statement.
...@@ -207,7 +206,7 @@ public class TransactionCommand extends Prepared { ...@@ -207,7 +206,7 @@ public class TransactionCommand extends Prepared {
this.transactionName = string; this.transactionName = string;
} }
public LocalResult queryMeta() { public ResultInterface queryMeta() {
return null; return null;
} }
......
...@@ -7,7 +7,6 @@ ...@@ -7,7 +7,6 @@
package org.h2.command.dml; package org.h2.command.dml;
import java.sql.SQLException; import java.sql.SQLException;
import org.h2.command.Prepared; import org.h2.command.Prepared;
import org.h2.constant.ErrorCode; import org.h2.constant.ErrorCode;
import org.h2.engine.Right; import org.h2.engine.Right;
...@@ -16,7 +15,7 @@ import org.h2.expression.Expression; ...@@ -16,7 +15,7 @@ import org.h2.expression.Expression;
import org.h2.expression.Parameter; import org.h2.expression.Parameter;
import org.h2.expression.ValueExpression; import org.h2.expression.ValueExpression;
import org.h2.message.Message; import org.h2.message.Message;
import org.h2.result.LocalResult; import org.h2.result.ResultInterface;
import org.h2.result.Row; import org.h2.result.Row;
import org.h2.result.RowList; import org.h2.result.RowList;
import org.h2.table.Column; import org.h2.table.Column;
...@@ -177,7 +176,7 @@ public class Update extends Prepared { ...@@ -177,7 +176,7 @@ public class Update extends Prepared {
return true; return true;
} }
public LocalResult queryMeta() { public ResultInterface queryMeta() {
return null; return null;
} }
......
...@@ -7,13 +7,12 @@ ...@@ -7,13 +7,12 @@
package org.h2.constraint; package org.h2.constraint;
import java.sql.SQLException; import java.sql.SQLException;
import org.h2.constant.ErrorCode; import org.h2.constant.ErrorCode;
import org.h2.engine.Session; import org.h2.engine.Session;
import org.h2.expression.Expression; import org.h2.expression.Expression;
import org.h2.index.Index; import org.h2.index.Index;
import org.h2.message.Message; import org.h2.message.Message;
import org.h2.result.LocalResult; import org.h2.result.ResultInterface;
import org.h2.result.Row; import org.h2.result.Row;
import org.h2.schema.Schema; import org.h2.schema.Schema;
import org.h2.table.Column; import org.h2.table.Column;
...@@ -117,7 +116,7 @@ public class ConstraintCheck extends Constraint { ...@@ -117,7 +116,7 @@ public class ConstraintCheck extends Constraint {
return; return;
} }
String sql = "SELECT 1 FROM " + filter.getTable().getSQL() + " WHERE NOT(" + expr.getSQL() + ")"; String sql = "SELECT 1 FROM " + filter.getTable().getSQL() + " WHERE NOT(" + expr.getSQL() + ")";
LocalResult r = session.prepare(sql).query(1); ResultInterface r = session.prepare(sql).query(1);
if (r.next()) { if (r.next()) {
throw Message.getSQLException(ErrorCode.CHECK_CONSTRAINT_VIOLATED_1, getName()); throw Message.getSQLException(ErrorCode.CHECK_CONSTRAINT_VIOLATED_1, getName());
} }
......
...@@ -7,7 +7,6 @@ ...@@ -7,7 +7,6 @@
package org.h2.constraint; package org.h2.constraint;
import java.sql.SQLException; import java.sql.SQLException;
import org.h2.command.Parser; import org.h2.command.Parser;
import org.h2.command.Prepared; import org.h2.command.Prepared;
import org.h2.constant.ErrorCode; import org.h2.constant.ErrorCode;
...@@ -17,7 +16,7 @@ import org.h2.expression.Parameter; ...@@ -17,7 +16,7 @@ import org.h2.expression.Parameter;
import org.h2.index.Cursor; import org.h2.index.Cursor;
import org.h2.index.Index; import org.h2.index.Index;
import org.h2.message.Message; import org.h2.message.Message;
import org.h2.result.LocalResult; import org.h2.result.ResultInterface;
import org.h2.result.Row; import org.h2.result.Row;
import org.h2.result.SearchRow; import org.h2.result.SearchRow;
import org.h2.schema.Schema; import org.h2.schema.Schema;
...@@ -627,7 +626,7 @@ public class ConstraintReferential extends Constraint { ...@@ -627,7 +626,7 @@ public class ConstraintReferential extends Constraint {
} }
buff.append(')'); buff.append(')');
String sql = buff.toString(); String sql = buff.toString();
LocalResult r = session.prepare(sql).query(1); ResultInterface r = session.prepare(sql).query(1);
if (r.next()) { if (r.next()) {
throw Message.getSQLException(ErrorCode.REFERENTIAL_INTEGRITY_VIOLATED_PARENT_MISSING_1, throw Message.getSQLException(ErrorCode.REFERENTIAL_INTEGRITY_VIOLATED_PARENT_MISSING_1,
getShortDescription()); getShortDescription());
......
...@@ -7,10 +7,9 @@ ...@@ -7,10 +7,9 @@
package org.h2.expression; package org.h2.expression;
import java.sql.SQLException; import java.sql.SQLException;
import org.h2.command.dml.Query; import org.h2.command.dml.Query;
import org.h2.engine.Session; import org.h2.engine.Session;
import org.h2.result.LocalResult; import org.h2.result.ResultInterface;
import org.h2.table.ColumnResolver; import org.h2.table.ColumnResolver;
import org.h2.table.TableFilter; import org.h2.table.TableFilter;
import org.h2.value.Value; import org.h2.value.Value;
...@@ -29,7 +28,7 @@ public class ConditionExists extends Condition { ...@@ -29,7 +28,7 @@ public class ConditionExists extends Condition {
public Value getValue(Session session) throws SQLException { public Value getValue(Session session) throws SQLException {
query.setSession(session); query.setSession(session);
LocalResult result = query.query(1); ResultInterface result = query.query(1);
session.addTemporaryResult(result); session.addTemporaryResult(result);
boolean r = result.getRowCount() > 0; boolean r = result.getRowCount() > 0;
return ValueBoolean.get(r); return ValueBoolean.get(r);
......
...@@ -7,7 +7,6 @@ ...@@ -7,7 +7,6 @@
package org.h2.expression; package org.h2.expression;
import java.sql.SQLException; import java.sql.SQLException;
import org.h2.command.dml.Query; import org.h2.command.dml.Query;
import org.h2.command.dml.Select; import org.h2.command.dml.Select;
import org.h2.constant.ErrorCode; import org.h2.constant.ErrorCode;
...@@ -17,7 +16,7 @@ import org.h2.engine.Session; ...@@ -17,7 +16,7 @@ import org.h2.engine.Session;
import org.h2.index.Index; import org.h2.index.Index;
import org.h2.index.IndexCondition; import org.h2.index.IndexCondition;
import org.h2.message.Message; import org.h2.message.Message;
import org.h2.result.LocalResult; import org.h2.result.ResultInterface;
import org.h2.table.ColumnResolver; import org.h2.table.ColumnResolver;
import org.h2.table.TableFilter; import org.h2.table.TableFilter;
import org.h2.table.TableView; import org.h2.table.TableView;
...@@ -46,7 +45,7 @@ public class ConditionInSelect extends Condition { ...@@ -46,7 +45,7 @@ public class ConditionInSelect extends Condition {
public Value getValue(Session session) throws SQLException { public Value getValue(Session session) throws SQLException {
query.setSession(session); query.setSession(session);
LocalResult rows = query.query(0); ResultInterface rows = query.query(0);
session.addTemporaryResult(rows); session.addTemporaryResult(rows);
boolean hasNull = false; boolean hasNull = false;
boolean result = all; boolean result = all;
......
...@@ -7,12 +7,11 @@ ...@@ -7,12 +7,11 @@
package org.h2.expression; package org.h2.expression;
import java.sql.SQLException; import java.sql.SQLException;
import org.h2.command.dml.Query; import org.h2.command.dml.Query;
import org.h2.constant.ErrorCode; import org.h2.constant.ErrorCode;
import org.h2.engine.Session; import org.h2.engine.Session;
import org.h2.message.Message; import org.h2.message.Message;
import org.h2.result.LocalResult; import org.h2.result.ResultInterface;
import org.h2.table.ColumnResolver; import org.h2.table.ColumnResolver;
import org.h2.table.TableFilter; import org.h2.table.TableFilter;
import org.h2.value.Value; import org.h2.value.Value;
...@@ -33,7 +32,7 @@ public class Subquery extends Expression { ...@@ -33,7 +32,7 @@ public class Subquery extends Expression {
public Value getValue(Session session) throws SQLException { public Value getValue(Session session) throws SQLException {
query.setSession(session); query.setSession(session);
LocalResult result = query.query(2); ResultInterface result = query.query(2);
try { try {
int rowcount = result.getRowCount(); int rowcount = result.getRowCount();
if (rowcount > 1) { if (rowcount > 1) {
......
...@@ -13,6 +13,7 @@ import org.h2.engine.Database; ...@@ -13,6 +13,7 @@ import org.h2.engine.Database;
import org.h2.engine.Session; import org.h2.engine.Session;
import org.h2.message.Message; import org.h2.message.Message;
import org.h2.result.LocalResult; import org.h2.result.LocalResult;
import org.h2.result.ResultInterface;
import org.h2.table.Column; import org.h2.table.Column;
import org.h2.tools.SimpleResultSet; import org.h2.tools.SimpleResultSet;
import org.h2.util.MathUtils; import org.h2.util.MathUtils;
...@@ -124,7 +125,7 @@ public class TableFunction extends Function { ...@@ -124,7 +125,7 @@ public class TableFunction extends Function {
return vr; return vr;
} }
private SimpleResultSet getSimpleResultSet(LocalResult rs, int maxrows) throws SQLException { private SimpleResultSet getSimpleResultSet(ResultInterface rs, int maxrows) throws SQLException {
int columnCount = rs.getVisibleColumnCount(); int columnCount = rs.getVisibleColumnCount();
SimpleResultSet simple = new SimpleResultSet(); SimpleResultSet simple = new SimpleResultSet();
for (int i = 0; i < columnCount; i++) { for (int i = 0; i < columnCount; i++) {
......
...@@ -7,9 +7,8 @@ ...@@ -7,9 +7,8 @@
package org.h2.index; package org.h2.index;
import java.sql.SQLException; import java.sql.SQLException;
import org.h2.message.Message; import org.h2.message.Message;
import org.h2.result.LocalResult; import org.h2.result.ResultInterface;
import org.h2.result.Row; import org.h2.result.Row;
import org.h2.result.SearchRow; import org.h2.result.SearchRow;
import org.h2.value.Value; import org.h2.value.Value;
...@@ -19,11 +18,11 @@ import org.h2.value.Value; ...@@ -19,11 +18,11 @@ import org.h2.value.Value;
*/ */
public class FunctionCursor implements Cursor { public class FunctionCursor implements Cursor {
private LocalResult result; private ResultInterface result;
private Value[] values; private Value[] values;
private Row row; private Row row;
FunctionCursor(LocalResult result) { FunctionCursor(ResultInterface result) {
this.result = result; this.result = result;
} }
......
...@@ -7,11 +7,10 @@ ...@@ -7,11 +7,10 @@
package org.h2.index; package org.h2.index;
import java.sql.SQLException; import java.sql.SQLException;
import org.h2.constant.SysProperties; import org.h2.constant.SysProperties;
import org.h2.engine.Session; import org.h2.engine.Session;
import org.h2.message.Message; import org.h2.message.Message;
import org.h2.result.LocalResult; import org.h2.result.ResultInterface;
import org.h2.result.Row; import org.h2.result.Row;
import org.h2.result.SearchRow; import org.h2.result.SearchRow;
import org.h2.table.FunctionTable; import org.h2.table.FunctionTable;
...@@ -24,7 +23,7 @@ import org.h2.table.IndexColumn; ...@@ -24,7 +23,7 @@ import org.h2.table.IndexColumn;
public class FunctionIndex extends BaseIndex { public class FunctionIndex extends BaseIndex {
private FunctionTable functionTable; private FunctionTable functionTable;
private LocalResult result; private ResultInterface result;
public FunctionIndex(FunctionTable functionTable, IndexColumn[] columns) { public FunctionIndex(FunctionTable functionTable, IndexColumn[] columns) {
initBaseIndex(functionTable, 0, null, columns, IndexType.createNonUnique(true)); initBaseIndex(functionTable, 0, null, columns, IndexType.createNonUnique(true));
......
...@@ -17,7 +17,7 @@ import org.h2.expression.Expression; ...@@ -17,7 +17,7 @@ import org.h2.expression.Expression;
import org.h2.expression.ExpressionColumn; import org.h2.expression.ExpressionColumn;
import org.h2.expression.ExpressionVisitor; import org.h2.expression.ExpressionVisitor;
import org.h2.message.Message; import org.h2.message.Message;
import org.h2.result.LocalResult; import org.h2.result.ResultInterface;
import org.h2.table.Column; import org.h2.table.Column;
import org.h2.util.ObjectArray; import org.h2.util.ObjectArray;
import org.h2.util.StatementBuilder; import org.h2.util.StatementBuilder;
...@@ -155,7 +155,7 @@ public class IndexCondition { ...@@ -155,7 +155,7 @@ public class IndexCondition {
* @param session the session * @param session the session
* @return the result * @return the result
*/ */
public LocalResult getCurrentResult(Session session) throws SQLException { public ResultInterface getCurrentResult(Session session) throws SQLException {
return expressionQuery.query(0); return expressionQuery.query(0);
} }
......
...@@ -11,7 +11,7 @@ import java.util.HashSet; ...@@ -11,7 +11,7 @@ import java.util.HashSet;
import org.h2.engine.Session; import org.h2.engine.Session;
import org.h2.expression.Comparison; import org.h2.expression.Comparison;
import org.h2.message.Message; import org.h2.message.Message;
import org.h2.result.LocalResult; import org.h2.result.ResultInterface;
import org.h2.result.Row; import org.h2.result.Row;
import org.h2.result.SearchRow; import org.h2.result.SearchRow;
import org.h2.result.SortOrder; import org.h2.result.SortOrder;
...@@ -37,7 +37,7 @@ public class IndexCursor implements Cursor { ...@@ -37,7 +37,7 @@ public class IndexCursor implements Cursor {
private Column inColumn; private Column inColumn;
private int inListIndex; private int inListIndex;
private Value[] inList; private Value[] inList;
private LocalResult inResult; private ResultInterface inResult;
private HashSet<Value> inResultTested; private HashSet<Value> inResultTested;
public void setIndex(Index index) { public void setIndex(Index index) {
......
...@@ -7,9 +7,8 @@ ...@@ -7,9 +7,8 @@
package org.h2.index; package org.h2.index;
import java.sql.SQLException; import java.sql.SQLException;
import org.h2.message.Message; import org.h2.message.Message;
import org.h2.result.LocalResult; import org.h2.result.ResultInterface;
import org.h2.result.Row; import org.h2.result.Row;
import org.h2.result.SearchRow; import org.h2.result.SearchRow;
import org.h2.table.Table; import org.h2.table.Table;
...@@ -22,10 +21,10 @@ import org.h2.value.ValueNull; ...@@ -22,10 +21,10 @@ import org.h2.value.ValueNull;
public class ViewCursor implements Cursor { public class ViewCursor implements Cursor {
private Table table; private Table table;
private LocalResult result; private ResultInterface result;
private Row current; private Row current;
ViewCursor(Table table, LocalResult result) { ViewCursor(Table table, ResultInterface result) {
this.table = table; this.table = table;
this.result = result; this.result = result;
} }
......
...@@ -13,7 +13,7 @@ import org.h2.engine.Session; ...@@ -13,7 +13,7 @@ import org.h2.engine.Session;
import org.h2.expression.Comparison; import org.h2.expression.Comparison;
import org.h2.expression.Parameter; import org.h2.expression.Parameter;
import org.h2.message.Message; import org.h2.message.Message;
import org.h2.result.LocalResult; import org.h2.result.ResultInterface;
import org.h2.result.Row; import org.h2.result.Row;
import org.h2.result.SearchRow; import org.h2.result.SearchRow;
import org.h2.table.Column; import org.h2.table.Column;
...@@ -189,7 +189,7 @@ public class ViewIndex extends BaseIndex { ...@@ -189,7 +189,7 @@ public class ViewIndex extends BaseIndex {
} }
} }
} }
LocalResult result = query.query(0); ResultInterface result = query.query(0);
return new ViewCursor(table, result); return new ViewCursor(table, result);
} }
......
...@@ -367,11 +367,6 @@ public class LocalResult implements ResultInterface { ...@@ -367,11 +367,6 @@ public class LocalResult implements ResultInterface {
} }
} }
/**
* Check if this result set is buffered using a temporary file.
*
* @return true if it is
*/
public boolean needToClose() { public boolean needToClose() {
return disk != null; return disk != null;
} }
......
...@@ -59,6 +59,14 @@ public interface ResultInterface { ...@@ -59,6 +59,14 @@ public interface ResultInterface {
*/ */
int getRowCount(); int getRowCount();
/**
* Check if this result set should be closed, for example because it is
* buffered using a temporary file.
*
* @return true if close should be called.
*/
boolean needToClose();
/** /**
* Close the result and delete any temporary files * Close the result and delete any temporary files
*/ */
......
...@@ -248,4 +248,8 @@ public class ResultRemote implements ResultInterface { ...@@ -248,4 +248,8 @@ public class ResultRemote implements ResultInterface {
this.fetchSize = fetchSize; this.fetchSize = fetchSize;
} }
public boolean needToClose() {
return true;
}
} }
...@@ -11,7 +11,6 @@ import java.io.PrintWriter; ...@@ -11,7 +11,6 @@ import java.io.PrintWriter;
import java.io.StringWriter; import java.io.StringWriter;
import java.net.Socket; import java.net.Socket;
import java.sql.SQLException; import java.sql.SQLException;
import org.h2.command.Command; import org.h2.command.Command;
import org.h2.constant.ErrorCode; import org.h2.constant.ErrorCode;
import org.h2.constant.SysProperties; import org.h2.constant.SysProperties;
...@@ -25,8 +24,8 @@ import org.h2.expression.ParameterInterface; ...@@ -25,8 +24,8 @@ import org.h2.expression.ParameterInterface;
import org.h2.expression.ParameterRemote; import org.h2.expression.ParameterRemote;
import org.h2.jdbc.JdbcSQLException; import org.h2.jdbc.JdbcSQLException;
import org.h2.message.Message; import org.h2.message.Message;
import org.h2.result.LocalResult;
import org.h2.result.ResultColumn; import org.h2.result.ResultColumn;
import org.h2.result.ResultInterface;
import org.h2.util.ObjectArray; import org.h2.util.ObjectArray;
import org.h2.util.SmallMap; import org.h2.util.SmallMap;
import org.h2.util.StringUtils; import org.h2.util.StringUtils;
...@@ -263,7 +262,7 @@ public class TcpServerThread implements Runnable { ...@@ -263,7 +262,7 @@ public class TcpServerThread implements Runnable {
int id = transfer.readInt(); int id = transfer.readInt();
int objectId = transfer.readInt(); int objectId = transfer.readInt();
Command command = (Command) cache.getObject(id, false); Command command = (Command) cache.getObject(id, false);
LocalResult result = command.getMetaDataLocal(); ResultInterface result = command.getMetaData();
cache.addObject(objectId, result); cache.addObject(objectId, result);
int columnCount = result.getVisibleColumnCount(); int columnCount = result.getVisibleColumnCount();
transfer.writeInt(SessionRemote.STATUS_OK).writeInt(columnCount).writeInt(0); transfer.writeInt(SessionRemote.STATUS_OK).writeInt(columnCount).writeInt(0);
...@@ -281,7 +280,7 @@ public class TcpServerThread implements Runnable { ...@@ -281,7 +280,7 @@ public class TcpServerThread implements Runnable {
Command command = (Command) cache.getObject(id, false); Command command = (Command) cache.getObject(id, false);
setParameters(command); setParameters(command);
int old = session.getModificationId(); int old = session.getModificationId();
LocalResult result = command.executeQueryLocal(maxRows); ResultInterface result = command.executeQuery(maxRows, false);
cache.addObject(objectId, result); cache.addObject(objectId, result);
int columnCount = result.getVisibleColumnCount(); int columnCount = result.getVisibleColumnCount();
int state = getState(old); int state = getState(old);
...@@ -326,7 +325,7 @@ public class TcpServerThread implements Runnable { ...@@ -326,7 +325,7 @@ public class TcpServerThread implements Runnable {
case SessionRemote.RESULT_FETCH_ROWS: { case SessionRemote.RESULT_FETCH_ROWS: {
int id = transfer.readInt(); int id = transfer.readInt();
int count = transfer.readInt(); int count = transfer.readInt();
LocalResult result = (LocalResult) cache.getObject(id, false); ResultInterface result = (ResultInterface) cache.getObject(id, false);
transfer.writeInt(SessionRemote.STATUS_OK); transfer.writeInt(SessionRemote.STATUS_OK);
for (int i = 0; i < count; i++) { for (int i = 0; i < count; i++) {
sendRow(result); sendRow(result);
...@@ -336,13 +335,13 @@ public class TcpServerThread implements Runnable { ...@@ -336,13 +335,13 @@ public class TcpServerThread implements Runnable {
} }
case SessionRemote.RESULT_RESET: { case SessionRemote.RESULT_RESET: {
int id = transfer.readInt(); int id = transfer.readInt();
LocalResult result = (LocalResult) cache.getObject(id, false); ResultInterface result = (ResultInterface) cache.getObject(id, false);
result.reset(); result.reset();
break; break;
} }
case SessionRemote.RESULT_CLOSE: { case SessionRemote.RESULT_CLOSE: {
int id = transfer.readInt(); int id = transfer.readInt();
LocalResult result = (LocalResult) cache.getObject(id, true); ResultInterface result = (ResultInterface) cache.getObject(id, true);
if (result != null) { if (result != null) {
result.close(); result.close();
cache.freeObject(id); cache.freeObject(id);
...@@ -376,7 +375,7 @@ public class TcpServerThread implements Runnable { ...@@ -376,7 +375,7 @@ public class TcpServerThread implements Runnable {
return SessionRemote.STATUS_OK_STATE_CHANGED; return SessionRemote.STATUS_OK_STATE_CHANGED;
} }
private void sendRow(LocalResult result) throws IOException, SQLException { private void sendRow(ResultInterface result) throws IOException, SQLException {
if (result.next()) { if (result.next()) {
transfer.writeBoolean(true); transfer.writeBoolean(true);
Value[] v = result.currentRow(); Value[] v = result.currentRow();
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论