use of org.hsqldb_voltpatches.result.Result in project voltdb by VoltDB.
the class Session method executeResultUpdate.
/**
* Retrieves the result of inserting, updating or deleting a row
* from an updatable result.
*
* @return the result of executing the statement
*/
private Result executeResultUpdate(Result cmd) {
long id = cmd.getResultId();
int actionType = cmd.getActionType();
Result result = sessionData.getDataResult(id);
if (result == null) {
return Result.newErrorResult(Error.error(ErrorCode.X_24501));
}
Object[] pvals = cmd.getParameterData();
Type[] types = cmd.metaData.columnTypes;
StatementQuery statement = (StatementQuery) result.getStatement();
QueryExpression qe = statement.queryExpression;
Table baseTable = qe.getBaseTable();
int[] columnMap = qe.getBaseTableColumnMap();
sessionContext.rowUpdateStatement.setRowActionProperties(actionType, baseTable, types, columnMap);
Result resultOut = executeCompiledStatement(sessionContext.rowUpdateStatement, pvals);
return resultOut;
}
use of org.hsqldb_voltpatches.result.Result in project voltdb by VoltDB.
the class Session method executeDirectBatchStatement.
private Result executeDirectBatchStatement(Result cmd) {
int[] updateCounts;
int count;
count = 0;
RowSetNavigator nav = cmd.initialiseNavigator();
updateCounts = new int[nav.getSize()];
Result error = null;
isBatch = true;
while (nav.hasNext()) {
Result in;
Object[] data = (Object[]) nav.getNext();
String sql = (String) data[0];
try {
in = executeDirectStatement(sql);
} catch (StackOverflowError caught) {
// in a higher-level caller.
throw caught;
} catch (Throwable t) {
in = Result.newErrorResult(t);
// if (t instanceof OutOfMemoryError) {
// System.gc();
// }
// "in" alread equals "err"
// maybe test for OOME and do a gc() ?
// t.printStackTrace();
}
if (in.isUpdateCount()) {
updateCounts[count++] = in.getUpdateCount();
} else if (in.isData()) {
// FIXME: we don't have what it takes yet
// to differentiate between things like
// stored procedure calls to methods with
// void return type and select statements with
// a single row/column containg null
updateCounts[count++] = ResultConstants.SUCCESS_NO_INFO;
} else if (in.isError()) {
updateCounts = ArrayUtil.arraySlice(updateCounts, 0, count);
error = in;
break;
} else {
throw Error.runtimeError(ErrorCode.U_S0500, "Session");
}
}
isBatch = false;
sessionData.updateLobUsageForBatch();
return Result.newBatchedExecuteResponse(updateCounts, null, error);
}
use of org.hsqldb_voltpatches.result.Result in project voltdb by VoltDB.
the class Session method executeCompiledBatchStatement.
private Result executeCompiledBatchStatement(Result cmd) {
long csid;
Statement cs;
int[] updateCounts;
int count;
csid = cmd.getStatementID();
cs = database.compiledStatementManager.getStatement(this, csid);
if (cs == null) {
// invalid sql has been removed already
return Result.newErrorResult(Error.error(ErrorCode.X_07501));
}
count = 0;
RowSetNavigator nav = cmd.initialiseNavigator();
updateCounts = new int[nav.getSize()];
Result generatedResult = null;
if (cs.hasGeneratedColumns()) {
generatedResult = Result.newDataResult(cs.generatedResultMetaData());
}
Result error = null;
isBatch = true;
while (nav.hasNext()) {
Object[] pvals = (Object[]) nav.getNext();
Result in = executeCompiledStatement(cs, pvals);
// esultConstants.EXECUTE_FAILED is encountered in the result
if (in.isUpdateCount()) {
if (cs.hasGeneratedColumns()) {
Object generatedRow = in.getNavigator().getNext();
generatedResult.getNavigator().add(generatedRow);
}
updateCounts[count++] = in.getUpdateCount();
} else if (in.isData()) {
// FIXME: we don't have what it takes yet
// to differentiate between things like
// stored procedure calls to methods with
// void return type and select statements with
// a single row/column containg null
updateCounts[count++] = ResultConstants.SUCCESS_NO_INFO;
} else if (in.isError()) {
updateCounts = ArrayUtil.arraySlice(updateCounts, 0, count);
error = in;
break;
} else {
throw Error.runtimeError(ErrorCode.U_S0500, "Session");
}
}
isBatch = false;
sessionData.updateLobUsageForBatch();
return Result.newBatchedExecuteResponse(updateCounts, generatedResult, error);
}
use of org.hsqldb_voltpatches.result.Result in project voltdb by VoltDB.
the class StatementCompound method handleCondition.
private Result handleCondition(Session session, Result result) {
String sqlState = null;
if (result.isError()) {
sqlState = result.getSubString();
} else if (session.getLastWarnings() != null) {
sqlState = session.getLastWarnings().getSQLState();
} else {
return result;
}
if (sqlState != null) {
for (int i = 0; i < handlers.length; i++) {
StatementHandler handler = handlers[i];
session.clearWarnings();
/**
* @todo - if condition is "transaction rollback" promote to
* top call level without any further action
* if condition is system related promote to top level
* schema manipulation conditions are never handled
*/
if (handler.handlesCondition(result.getSubString())) {
session.resetSchema();
switch(handler.handlerType) {
case StatementHandler.CONTINUE:
result = Result.updateZeroResult;
break;
case StatementHandler.UNDO:
session.rollbackToSavepoint();
result = Result.newPSMResult(StatementTypes.LEAVE, null, null);
break;
case StatementHandler.EXIT:
result = Result.newPSMResult(StatementTypes.LEAVE, null, null);
break;
}
Result actionResult = handler.statement.execute(session);
if (actionResult.isError()) {
result = actionResult;
handleCondition(session, result);
} else {
return result;
}
}
}
if (parent != null) {
// unhandled exception condition
return parent.handleCondition(session, result);
}
}
return result;
}
use of org.hsqldb_voltpatches.result.Result in project voltdb by VoltDB.
the class StatementCompound method executeBlock.
private Result executeBlock(Session session) {
Result result = Result.updateZeroResult;
int i = 0;
session.sessionContext.push();
for (; i < statements.length; i++) {
result = statements[i].execute(session);
result = handleCondition(session, result);
if (result.isError()) {
break;
}
if (result.getType() == ResultConstants.VALUE) {
break;
}
}
if (result.getType() == ResultConstants.VALUE) {
if (result.getErrorCode() == StatementTypes.LEAVE) {
if (result.getMainString() == null) {
result = Result.updateZeroResult;
} else if (label != null && label.name.equals(result.getMainString())) {
result = Result.updateZeroResult;
}
}
}
session.sessionContext.pop();
return result;
}
Aggregations