Search in sources :

Example 61 with Result

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;
}
Also used : Type(org.hsqldb_voltpatches.types.Type) Result(org.hsqldb_voltpatches.result.Result)

Example 62 with Result

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);
}
Also used : RowSetNavigator(org.hsqldb_voltpatches.navigator.RowSetNavigator) Result(org.hsqldb_voltpatches.result.Result)

Example 63 with Result

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);
}
Also used : RowSetNavigator(org.hsqldb_voltpatches.navigator.RowSetNavigator) Result(org.hsqldb_voltpatches.result.Result)

Example 64 with Result

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;
}
Also used : Result(org.hsqldb_voltpatches.result.Result)

Example 65 with 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;
}
Also used : Result(org.hsqldb_voltpatches.result.Result)

Aggregations

Result (org.hsqldb_voltpatches.result.Result)83 Session (org.hsqldb_voltpatches.Session)18 PersistentStore (org.hsqldb_voltpatches.persist.PersistentStore)16 HsqlName (org.hsqldb_voltpatches.HsqlNameManager.HsqlName)15 Table (org.hsqldb_voltpatches.Table)14 ResultLob (org.hsqldb_voltpatches.result.ResultLob)13 TextTable (org.hsqldb_voltpatches.TextTable)12 ResultMetaData (org.hsqldb_voltpatches.result.ResultMetaData)11 RowSetNavigator (org.hsqldb_voltpatches.navigator.RowSetNavigator)10 HsqlException (org.hsqldb_voltpatches.HsqlException)5 RowSetNavigatorData (org.hsqldb_voltpatches.navigator.RowSetNavigatorData)4 EOFException (java.io.EOFException)3 RowSetNavigatorClient (org.hsqldb_voltpatches.navigator.RowSetNavigatorClient)3 IOException (java.io.IOException)2 RangeIteratorBase (org.hsqldb_voltpatches.RangeVariable.RangeIteratorBase)2 Statement (org.hsqldb_voltpatches.Statement)2 HashMappedList (org.hsqldb_voltpatches.lib.HashMappedList)2 HsqlArrayList (org.hsqldb_voltpatches.lib.HsqlArrayList)2 HsqlByteArrayInputStream (org.hsqldb_voltpatches.lib.HsqlByteArrayInputStream)2 Iterator (org.hsqldb_voltpatches.lib.Iterator)2