Search in sources :

Example 71 with Result

use of org.hsqldb_voltpatches.result.Result in project voltdb by VoltDB.

the class LobManager method setChars.

public Result setChars(Session session, long lobID, long offset, char[] chars) {
    if (chars.length == 0) {
        return ResultLob.newLobSetResponse(lobID, 0);
    }
    Object[] data = getLobHeader(session, lobID);
    if (data == null) {
        return Result.newErrorResult(Error.error(ErrorCode.X_0F502));
    }
    long length = ((Long) data[1]).longValue();
    HsqlByteArrayOutputStream os = new HsqlByteArrayOutputStream(chars.length * 2);
    os.write(chars, 0, chars.length);
    Result result = setBytesBA(session, lobID, os.getBuffer(), offset * 2, os.getBuffer().length);
    if (result.isError()) {
        return result;
    }
    if (offset + chars.length > length) {
        result = setLength(session, lobID, offset + chars.length);
        if (result.isError()) {
            return result;
        }
    }
    return ResultLob.newLobSetResponse(lobID, 0);
}
Also used : HsqlByteArrayOutputStream(org.hsqldb_voltpatches.lib.HsqlByteArrayOutputStream) Result(org.hsqldb_voltpatches.result.Result)

Example 72 with Result

use of org.hsqldb_voltpatches.result.Result in project voltdb by VoltDB.

the class ScriptWriterBase method writeDDL.

protected void writeDDL() throws IOException {
    Result ddlPart = database.getScript(!includeCachedData);
    writeSingleColumnResult(ddlPart);
}
Also used : Result(org.hsqldb_voltpatches.result.Result)

Example 73 with Result

use of org.hsqldb_voltpatches.result.Result in project voltdb by VoltDB.

the class ScriptReaderBinary method readDDL.

protected void readDDL(Session session) throws IOException {
    Result r = Result.newResult(dataStreamIn, rowIn);
    r.readAdditionalResults(session, dataStreamIn, rowIn);
    RowSetNavigator nav = r.initialiseNavigator();
    while (nav.hasNext()) {
        Object[] data = (Object[]) nav.getNext();
        String s = (String) data[0];
        Result result = session.executeDirectStatement(s);
        if (result.isError()) {
            db.logger.appLog.logContext(SimpleLog.LOG_ERROR, result.getMainString());
            throw Error.error(result);
        }
    }
}
Also used : RowSetNavigator(org.hsqldb_voltpatches.navigator.RowSetNavigator) Result(org.hsqldb_voltpatches.result.Result)

Example 74 with Result

use of org.hsqldb_voltpatches.result.Result in project voltdb by VoltDB.

the class BlobDataID method setBytes.

public int setBytes(SessionInterface session, long pos, byte[] bytes, int offset, int len) {
    ResultLob resultOut = ResultLob.newLobSetBytesRequest(id, pos, bytes);
    Result resultIn = (ResultLob) session.execute(resultOut);
    if (resultIn.isError()) {
        throw resultIn.getException();
    }
    return bytes.length;
}
Also used : ResultLob(org.hsqldb_voltpatches.result.ResultLob) Result(org.hsqldb_voltpatches.result.Result)

Example 75 with Result

use of org.hsqldb_voltpatches.result.Result in project voltdb by VoltDB.

the class FunctionSQLInvoked method getValue.

public Object getValue(Session session) {
    int variableCount = routine.getVariableCount();
    Result result;
    int extraArg = routine.javaMethodWithConnection ? 1 : 0;
    Object[] data = ValuePool.emptyObjectArray;
    Object returnValue = null;
    boolean push = routine.isPSM() || routine.dataImpact != Routine.NO_SQL;
    if (extraArg + nodes.length > 0) {
        data = new Object[nodes.length + extraArg];
        if (extraArg > 0) {
            data[0] = session.getInternalConnection();
        }
    }
    for (int i = 0; i < nodes.length; i++) {
        Expression e = nodes[i];
        Object value = e.getValue(session, e.dataType);
        if (value == null) {
            if (routine.isNullInputOutput()) {
                return null;
            }
            if (!routine.parameterNullable[i]) {
                throw Error.error(ErrorCode.X_39004);
            }
        }
        if (routine.isPSM()) {
            data[i] = value;
        } else {
            data[i + extraArg] = e.dataType.convertSQLToJava(session, value);
        }
    }
    if (push) {
        session.sessionContext.push();
    }
    if (routine.isPSM()) {
        session.sessionContext.routineArguments = data;
        session.sessionContext.routineVariables = ValuePool.emptyObjectArray;
        if (variableCount > 0) {
            session.sessionContext.routineVariables = new Object[variableCount];
        }
        result = routine.statement.execute(session);
        if (result.isError()) {
        } else if (result.isSimpleValue()) {
            returnValue = result.getValueObject();
        } else {
            result = Result.newErrorResult(Error.error(ErrorCode.X_2F005, routine.getName().name), null);
        }
    } else {
        try {
            returnValue = routine.javaMethod.invoke(null, data);
            if (routine.returnsTable()) {
            // convert ResultSet to table
            } else {
                returnValue = dataType.convertJavaToSQL(session, returnValue);
            }
            result = Result.updateZeroResult;
        } catch (InvocationTargetException e) {
            result = Result.newErrorResult(Error.error(ErrorCode.X_46000, routine.getName().name), null);
        } catch (IllegalAccessException e) {
            result = Result.newErrorResult(Error.error(ErrorCode.X_46000, routine.getName().name), null);
        } catch (Throwable e) {
            result = Result.newErrorResult(Error.error(ErrorCode.X_46000, routine.getName().name), null);
        }
    }
    if (push) {
        if (result.isError()) {
            session.rollbackToSavepoint();
        }
        session.sessionContext.pop();
    }
    if (result.isError()) {
        throw result.getException();
    }
    return returnValue;
}
Also used : InvocationTargetException(java.lang.reflect.InvocationTargetException) 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