use of org.h2.value.Value in project h2database by h2database.
the class Query method getParameterValues.
public final Value[] getParameterValues() {
ArrayList<Parameter> list = getParameters();
if (list == null) {
list = New.arrayList();
}
int size = list.size();
Value[] params = new Value[size];
for (int i = 0; i < size; i++) {
Value v = list.get(i).getParamValue();
params[i] = v;
}
return params;
}
use of org.h2.value.Value in project h2database by h2database.
the class Query method sameResultAsLast.
private boolean sameResultAsLast(Session s, Value[] params, Value[] lastParams, long lastEval) {
if (!cacheableChecked) {
long max = getMaxDataModificationId();
noCache = max == Long.MAX_VALUE;
cacheableChecked = true;
}
if (noCache) {
return false;
}
Database db = s.getDatabase();
for (int i = 0; i < params.length; i++) {
Value a = lastParams[i], b = params[i];
if (a.getType() != b.getType() || !db.areEqual(a, b)) {
return false;
}
}
if (!isEverything(ExpressionVisitor.DETERMINISTIC_VISITOR) || !isEverything(ExpressionVisitor.INDEPENDENT_VISITOR)) {
return false;
}
if (db.getModificationDataId() > lastEval && getMaxDataModificationId() > lastEval) {
return false;
}
return true;
}
use of org.h2.value.Value in project h2database by h2database.
the class ScriptCommand method add.
private void add(String s, boolean insert) throws IOException {
if (s == null) {
return;
}
if (lineSeparator.length > 1 || lineSeparator[0] != '\n') {
s = StringUtils.replaceAll(s, "\n", lineSeparatorString);
}
s += ";";
if (out != null) {
byte[] buff = s.getBytes(charset);
int len = MathUtils.roundUpInt(buff.length + lineSeparator.length, Constants.FILE_BLOCK_SIZE);
buffer = Utils.copy(buff, buffer);
if (len > buffer.length) {
buffer = new byte[len];
}
System.arraycopy(buff, 0, buffer, 0, buff.length);
for (int i = buff.length; i < len - lineSeparator.length; i++) {
buffer[i] = ' ';
}
for (int j = 0, i = len - lineSeparator.length; i < len; i++, j++) {
buffer[i] = lineSeparator[j];
}
out.write(buffer, 0, len);
if (!insert) {
Value[] row = { ValueString.get(s) };
result.addRow(row);
}
} else {
Value[] row = { ValueString.get(s) };
result.addRow(row);
}
}
use of org.h2.value.Value in project h2database by h2database.
the class ScriptCommand method writeLobStream.
private int writeLobStream(Value v) throws IOException {
if (!tempLobTableCreated) {
add("CREATE TABLE IF NOT EXISTS SYSTEM_LOB_STREAM" + "(ID INT NOT NULL, PART INT NOT NULL, " + "CDATA VARCHAR, BDATA BINARY)", true);
add("CREATE PRIMARY KEY SYSTEM_LOB_STREAM_PRIMARY_KEY " + "ON SYSTEM_LOB_STREAM(ID, PART)", true);
add("CREATE ALIAS IF NOT EXISTS " + "SYSTEM_COMBINE_CLOB FOR \"" + this.getClass().getName() + ".combineClob\"", true);
add("CREATE ALIAS IF NOT EXISTS " + "SYSTEM_COMBINE_BLOB FOR \"" + this.getClass().getName() + ".combineBlob\"", true);
tempLobTableCreated = true;
}
int id = nextLobId++;
switch(v.getType()) {
case Value.BLOB:
{
byte[] bytes = new byte[lobBlockSize];
try (InputStream input = v.getInputStream()) {
for (int i = 0; ; i++) {
StringBuilder buff = new StringBuilder(lobBlockSize * 2);
buff.append("INSERT INTO SYSTEM_LOB_STREAM VALUES(").append(id).append(", ").append(i).append(", NULL, '");
int len = IOUtils.readFully(input, bytes, lobBlockSize);
if (len <= 0) {
break;
}
buff.append(StringUtils.convertBytesToHex(bytes, len)).append("')");
String sql = buff.toString();
add(sql, true);
}
}
break;
}
case Value.CLOB:
{
char[] chars = new char[lobBlockSize];
try (Reader reader = v.getReader()) {
for (int i = 0; ; i++) {
StringBuilder buff = new StringBuilder(lobBlockSize * 2);
buff.append("INSERT INTO SYSTEM_LOB_STREAM VALUES(").append(id).append(", ").append(i).append(", ");
int len = IOUtils.readFully(reader, chars, lobBlockSize);
if (len == 0) {
break;
}
buff.append(StringUtils.quoteStringSQL(new String(chars, 0, len))).append(", NULL)");
String sql = buff.toString();
add(sql, true);
}
}
break;
}
default:
DbException.throwInternalError("type:" + v.getType());
}
return id;
}
use of org.h2.value.Value in project h2database by h2database.
the class Select method queryDistinct.
private void queryDistinct(ResultTarget result, long limitRows) {
// limitRows is never 0 here
if (limitRows > 0 && offsetExpr != null) {
int offset = offsetExpr.getValue(session).getInt();
if (offset > 0) {
limitRows += offset;
}
}
int rowNumber = 0;
setCurrentRowNumber(0);
Index index = topTableFilter.getIndex();
SearchRow first = null;
int columnIndex = index.getColumns()[0].getColumnId();
int sampleSize = getSampleSizeValue(session);
while (true) {
setCurrentRowNumber(rowNumber + 1);
Cursor cursor = index.findNext(session, first, null);
if (!cursor.next()) {
break;
}
SearchRow found = cursor.getSearchRow();
Value value = found.getValue(columnIndex);
if (first == null) {
first = topTableFilter.getTable().getTemplateSimpleRow(true);
}
first.setValue(columnIndex, value);
Value[] row = { value };
result.addRow(row);
rowNumber++;
if ((sort == null || sortUsingIndex) && limitRows > 0 && rowNumber >= limitRows) {
break;
}
if (sampleSize > 0 && rowNumber >= sampleSize) {
break;
}
}
}
Aggregations