Search in sources :

Example 31 with ResultInterface

use of org.h2.result.ResultInterface in project h2database by h2database.

the class SessionWithState method readSessionState.

/**
 * Read the session state if necessary.
 */
public void readSessionState() {
    if (!sessionStateChanged || sessionStateUpdating) {
        return;
    }
    sessionStateChanged = false;
    sessionState = New.arrayList();
    CommandInterface ci = prepareCommand("SELECT * FROM INFORMATION_SCHEMA.SESSION_STATE", Integer.MAX_VALUE);
    ResultInterface result = ci.executeQuery(0, false);
    while (result.next()) {
        Value[] row = result.currentRow();
        sessionState.add(row[1].getString());
    }
}
Also used : ResultInterface(org.h2.result.ResultInterface) Value(org.h2.value.Value) CommandInterface(org.h2.command.CommandInterface)

Example 32 with ResultInterface

use of org.h2.result.ResultInterface in project h2database by h2database.

the class Merge method update.

@Override
public int update() {
    int count;
    session.getUser().checkRight(targetTable, Right.INSERT);
    session.getUser().checkRight(targetTable, Right.UPDATE);
    setCurrentRowNumber(0);
    GeneratedKeys generatedKeys = session.getGeneratedKeys();
    if (!valuesExpressionList.isEmpty()) {
        // process values in list
        count = 0;
        generatedKeys.initialize(targetTable);
        for (int x = 0, size = valuesExpressionList.size(); x < size; x++) {
            setCurrentRowNumber(x + 1);
            generatedKeys.nextRow();
            Expression[] expr = valuesExpressionList.get(x);
            Row newRow = targetTable.getTemplateRow();
            for (int i = 0, len = columns.length; i < len; i++) {
                Column c = columns[i];
                int index = c.getColumnId();
                Expression e = expr[i];
                if (e != null) {
                    // e can be null (DEFAULT)
                    try {
                        Value v = c.convert(e.getValue(session));
                        newRow.setValue(index, v);
                        if (e instanceof SequenceValue) {
                            generatedKeys.add(c);
                        }
                    } catch (DbException ex) {
                        throw setRow(ex, count, getSQL(expr));
                    }
                }
            }
            merge(newRow);
            count++;
        }
    } else {
        // process select data for list
        query.setNeverLazy(true);
        ResultInterface rows = query.query(0);
        count = 0;
        targetTable.fire(session, Trigger.UPDATE | Trigger.INSERT, true);
        targetTable.lock(session, true, false);
        while (rows.next()) {
            count++;
            generatedKeys.nextRow();
            Value[] r = rows.currentRow();
            Row newRow = targetTable.getTemplateRow();
            setCurrentRowNumber(count);
            for (int j = 0; j < columns.length; j++) {
                Column c = columns[j];
                int index = c.getColumnId();
                try {
                    Value v = c.convert(r[j]);
                    newRow.setValue(index, v);
                } catch (DbException ex) {
                    throw setRow(ex, count, getSQL(r));
                }
            }
            merge(newRow);
        }
        rows.close();
        targetTable.fire(session, Trigger.UPDATE | Trigger.INSERT, false);
    }
    return count;
}
Also used : SequenceValue(org.h2.expression.SequenceValue) ResultInterface(org.h2.result.ResultInterface) Expression(org.h2.expression.Expression) Column(org.h2.table.Column) SequenceValue(org.h2.expression.SequenceValue) Value(org.h2.value.Value) GeneratedKeys(org.h2.engine.GeneratedKeys) Row(org.h2.result.Row) DbException(org.h2.message.DbException)

Example 33 with ResultInterface

use of org.h2.result.ResultInterface in project h2database by h2database.

the class Call method query.

@Override
public ResultInterface query(int maxrows) {
    setCurrentRowNumber(1);
    Value v = expression.getValue(session);
    if (isResultSet) {
        v = v.convertTo(Value.RESULT_SET);
        ResultSet rs = v.getResultSet();
        return LocalResult.read(session, rs, maxrows);
    }
    LocalResult result = new LocalResult(session, expressions, 1);
    Value[] row = { v };
    result.addRow(row);
    result.done();
    return result;
}
Also used : LocalResult(org.h2.result.LocalResult) Value(org.h2.value.Value) ResultSet(java.sql.ResultSet)

Example 34 with ResultInterface

use of org.h2.result.ResultInterface in project h2database by h2database.

the class FunctionTable method getResult.

/**
 * Read the result from the function. This method buffers the result in a
 * temporary file.
 *
 * @param session the session
 * @return the result
 */
public ResultInterface getResult(Session session) {
    ValueResultSet v = getValueResultSet(session);
    if (v == null) {
        return null;
    }
    if (cachedResult != null && cachedValue == v) {
        cachedResult.reset();
        return cachedResult;
    }
    LocalResult result = LocalResult.read(session, v.getResultSet(), 0);
    if (function.isDeterministic()) {
        cachedResult = result;
        cachedValue = v;
    }
    return result;
}
Also used : LocalResult(org.h2.result.LocalResult) ValueResultSet(org.h2.value.ValueResultSet)

Example 35 with ResultInterface

use of org.h2.result.ResultInterface in project h2database by h2database.

the class CommandList method query.

@Override
public ResultInterface query(int maxrows) {
    ResultInterface result = command.query(maxrows);
    executeRemaining();
    return result;
}
Also used : ResultInterface(org.h2.result.ResultInterface)

Aggregations

ResultInterface (org.h2.result.ResultInterface)34 Value (org.h2.value.Value)15 DbException (org.h2.message.DbException)11 LocalResult (org.h2.result.LocalResult)9 SQLException (java.sql.SQLException)8 CommandInterface (org.h2.command.CommandInterface)7 Expression (org.h2.expression.Expression)5 Column (org.h2.table.Column)5 SQLClientInfoException (java.sql.SQLClientInfoException)4 Prepared (org.h2.command.Prepared)4 Database (org.h2.engine.Database)4 ResultWithGeneratedKeys (org.h2.result.ResultWithGeneratedKeys)4 Row (org.h2.result.Row)4 IOException (java.io.IOException)3 ValueString (org.h2.value.ValueString)3 Savepoint (java.sql.Savepoint)2 GeneratedKeys (org.h2.engine.GeneratedKeys)2 ExpressionColumn (org.h2.expression.ExpressionColumn)2 SequenceValue (org.h2.expression.SequenceValue)2 ResultRemote (org.h2.result.ResultRemote)2