use of org.h2.result.ResultInterface in project h2database by h2database.
the class ViewIndex method findRecursive.
private Cursor findRecursive(SearchRow first, SearchRow last) {
assert recursive;
ResultInterface recursiveResult = view.getRecursiveResult();
if (recursiveResult != null) {
recursiveResult.reset();
return new ViewCursor(this, recursiveResult, first, last);
}
if (query == null) {
Parser parser = new Parser(createSession);
parser.setRightsChecked(true);
parser.setSuppliedParameterList(originalParameters);
query = (Query) parser.prepare(querySQL);
query.setNeverLazy(true);
}
if (!query.isUnion()) {
throw DbException.get(ErrorCode.SYNTAX_ERROR_2, "recursive queries without UNION");
}
SelectUnion union = (SelectUnion) query;
Query left = union.getLeft();
left.setNeverLazy(true);
// to ensure the last result is not closed
left.disableCache();
ResultInterface resultInterface = left.query(0);
LocalResult localResult = union.getEmptyResult();
// ensure it is not written to disk,
// because it is not closed normally
localResult.setMaxMemoryRows(Integer.MAX_VALUE);
while (resultInterface.next()) {
Value[] cr = resultInterface.currentRow();
localResult.addRow(cr);
}
Query right = union.getRight();
right.setNeverLazy(true);
resultInterface.reset();
view.setRecursiveResult(resultInterface);
// to ensure the last result is not closed
right.disableCache();
while (true) {
resultInterface = right.query(0);
if (!resultInterface.hasNext()) {
break;
}
while (resultInterface.next()) {
Value[] cr = resultInterface.currentRow();
localResult.addRow(cr);
}
resultInterface.reset();
view.setRecursiveResult(resultInterface);
}
view.setRecursiveResult(null);
localResult.done();
return new ViewCursor(this, localResult, first, last);
}
use of org.h2.result.ResultInterface in project h2database by h2database.
the class JdbcStatement method executeUpdateInternal.
private int executeUpdateInternal(String sql, Object generatedKeysRequest) throws SQLException {
checkClosedForWrite();
try {
closeOldResultSet();
sql = JdbcConnection.translateSQL(sql, escapeProcessing);
CommandInterface command = conn.prepareCommand(sql, fetchSize);
synchronized (session) {
setExecutingStatement(command);
try {
ResultWithGeneratedKeys result = command.executeUpdate(conn.scopeGeneratedKeys() ? false : generatedKeysRequest);
updateCount = result.getUpdateCount();
ResultInterface gk = result.getGeneratedKeys();
if (gk != null) {
int id = getNextId(TraceObject.RESULT_SET);
generatedKeys = new JdbcResultSet(conn, this, command, gk, id, false, true, false);
}
} finally {
setExecutingStatement(null);
}
}
command.close();
return updateCount;
} finally {
afterWriting();
}
}
use of org.h2.result.ResultInterface in project h2database by h2database.
the class JdbcStatement method executeQuery.
/**
* Executes a query (select statement) and returns the result set.
* If another result set exists for this statement, this will be closed
* (even if this statement fails).
*
* @param sql the SQL statement to execute
* @return the result set
*/
@Override
public ResultSet executeQuery(String sql) throws SQLException {
try {
int id = getNextId(TraceObject.RESULT_SET);
if (isDebugEnabled()) {
debugCodeAssign("ResultSet", TraceObject.RESULT_SET, id, "executeQuery(" + quote(sql) + ")");
}
synchronized (session) {
checkClosed();
closeOldResultSet();
sql = JdbcConnection.translateSQL(sql, escapeProcessing);
CommandInterface command = conn.prepareCommand(sql, fetchSize);
ResultInterface result;
boolean lazy = false;
boolean scrollable = resultSetType != ResultSet.TYPE_FORWARD_ONLY;
boolean updatable = resultSetConcurrency == ResultSet.CONCUR_UPDATABLE;
setExecutingStatement(command);
try {
result = command.executeQuery(maxRows, scrollable);
lazy = result.isLazy();
} finally {
if (!lazy) {
setExecutingStatement(null);
}
}
if (!lazy) {
command.close();
}
resultSet = new JdbcResultSet(conn, this, command, result, id, closedByResultSet, scrollable, updatable);
}
return resultSet;
} catch (Exception e) {
throw logAndConvert(e);
}
}
use of org.h2.result.ResultInterface in project h2database by h2database.
the class JdbcConnection method getGeneratedKeys.
/**
* INTERNAL
*/
ResultSet getGeneratedKeys(JdbcStatement stat, int id) {
getGeneratedKeys = prepareCommand("SELECT SCOPE_IDENTITY() " + "WHERE SCOPE_IDENTITY() IS NOT NULL", getGeneratedKeys);
ResultInterface result = getGeneratedKeys.executeQuery(0, false);
return new JdbcResultSet(this, stat, getGeneratedKeys, result, id, false, true, false);
}
use of org.h2.result.ResultInterface in project h2database by h2database.
the class JdbcConnection method getCatalog.
/**
* Gets the current catalog name.
*
* @return the catalog name
* @throws SQLException if the connection is closed
*/
@Override
public String getCatalog() throws SQLException {
try {
debugCodeCall("getCatalog");
checkClosed();
if (catalog == null) {
CommandInterface cat = prepareCommand("CALL DATABASE()", Integer.MAX_VALUE);
ResultInterface result = cat.executeQuery(0, false);
result.next();
catalog = result.currentRow()[0].getString();
cat.close();
}
return catalog;
} catch (Exception e) {
throw logAndConvert(e);
}
}
Aggregations