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());
}
}
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;
}
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;
}
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;
}
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;
}
Aggregations