Search in sources :

Example 96 with Row

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

the class MergedResultSet method getResult.

/**
 * Returns merged results set.
 *
 * @return result set with rows from all appended result sets
 */
public SimpleResultSet getResult() {
    SimpleResultSet rs = new SimpleResultSet();
    for (SimpleColumnInfo ci : columns) {
        rs.addColumn(ci.name, ci.type, ci.typeName, ci.precision, ci.scale);
    }
    for (Map<SimpleColumnInfo, Object> map : data) {
        Object[] row = new Object[columns.size()];
        for (Map.Entry<SimpleColumnInfo, Object> entry : map.entrySet()) {
            row[columns.indexOf(entry.getKey())] = entry.getValue();
        }
        rs.addRow(row);
    }
    return rs;
}
Also used : SimpleResultSet(org.h2.tools.SimpleResultSet) Map(java.util.Map) HashMap(java.util.HashMap)

Example 97 with Row

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

the class GenerateHelp method main.

/**
 * This method is called when executing this application from the command
 * line.
 *
 * @param args the command line parameters
 */
public static void main(String... args) throws Exception {
    String in = "src/docsrc/help/help.csv";
    String out = "src/main/org/h2/res/help.csv";
    Csv csv = new Csv();
    csv.setLineCommentCharacter('#');
    ResultSet rs = csv.read(in, null, null);
    SimpleResultSet rs2 = new SimpleResultSet();
    ResultSetMetaData meta = rs.getMetaData();
    int columnCount = meta.getColumnCount() - 1;
    for (int i = 0; i < columnCount; i++) {
        rs2.addColumn(meta.getColumnLabel(1 + i), Types.VARCHAR, 0, 0);
    }
    while (rs.next()) {
        Object[] row = new Object[columnCount];
        for (int i = 0; i < columnCount; i++) {
            String s = rs.getString(1 + i);
            if (i == 3) {
                int len = s.length();
                int end = 0;
                for (; end < len; end++) {
                    char ch = s.charAt(end);
                    if (ch == '.') {
                        end++;
                        break;
                    }
                    if (ch == '"') {
                        do {
                            end++;
                        } while (end < len && s.charAt(end) != '"');
                    }
                }
                s = s.substring(0, end);
            }
            row[i] = s;
        }
        rs2.addRow(row);
    }
    BufferedWriter writer = new BufferedWriter(new FileWriter(out));
    writer.write("# Copyright 2004-2018 H2 Group. " + "Multiple-Licensed under the MPL 2.0,\n" + "# and the EPL 1.0 " + "(http://h2database.com/html/license.html).\n" + "# Initial Developer: H2 Group)\n");
    csv = new Csv();
    csv.setLineSeparator("\n");
    csv.write(writer, rs2);
}
Also used : ResultSetMetaData(java.sql.ResultSetMetaData) SimpleResultSet(org.h2.tools.SimpleResultSet) Csv(org.h2.tools.Csv) FileWriter(java.io.FileWriter) ResultSet(java.sql.ResultSet) SimpleResultSet(org.h2.tools.SimpleResultSet) BufferedWriter(java.io.BufferedWriter)

Example 98 with Row

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

the class JdbcResultSet method updateBinaryStream.

/**
 * Updates a column in the current or insert row.
 *
 * @param columnLabel the column label
 * @param x the value
 * @param length the number of characters
 * @throws SQLException if the result set is closed or not updatable
 */
@Override
public void updateBinaryStream(String columnLabel, InputStream x, long length) throws SQLException {
    try {
        if (isDebugEnabled()) {
            debugCode("updateBinaryStream(" + quote(columnLabel) + ", x, " + length + "L);");
        }
        checkClosed();
        Value v = conn.createBlob(x, length);
        update(columnLabel, v);
    } catch (Exception e) {
        throw logAndConvert(e);
    }
}
Also used : Value(org.h2.value.Value) DbException(org.h2.message.DbException) SQLException(java.sql.SQLException)

Example 99 with Row

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

the class JdbcResultSet method updateBlob.

/**
 * Updates a column in the current or insert row.
 *
 * @param columnLabel the column label
 * @param x the value
 * @throws SQLException if the result set is closed or not updatable
 */
@Override
public void updateBlob(String columnLabel, Blob x) throws SQLException {
    try {
        if (isDebugEnabled()) {
            debugCode("updateBlob(" + quote(columnLabel) + ", x);");
        }
        checkClosed();
        Value v;
        if (x == null) {
            v = ValueNull.INSTANCE;
        } else {
            v = conn.createBlob(x.getBinaryStream(), -1);
        }
        update(columnLabel, v);
    } catch (Exception e) {
        throw logAndConvert(e);
    }
}
Also used : Value(org.h2.value.Value) DbException(org.h2.message.DbException) SQLException(java.sql.SQLException)

Example 100 with Row

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

the class JdbcResultSet method patchCurrentRow.

private void patchCurrentRow(Value[] row) {
    boolean changed = false;
    Value[] current = result.currentRow();
    CompareMode mode = conn.getCompareMode();
    for (int i = 0; i < row.length; i++) {
        if (row[i].compareTo(current[i], mode) != 0) {
            changed = true;
            break;
        }
    }
    if (patchedRows == null) {
        patchedRows = new HashMap<>();
    }
    Integer rowId = result.getRowId();
    if (!changed) {
        patchedRows.remove(rowId);
    } else {
        patchedRows.put(rowId, row);
    }
}
Also used : BigInteger(java.math.BigInteger) Value(org.h2.value.Value) CompareMode(org.h2.value.CompareMode)

Aggregations

Value (org.h2.value.Value)118 Row (org.h2.result.Row)49 Column (org.h2.table.Column)48 DbException (org.h2.message.DbException)44 SearchRow (org.h2.result.SearchRow)37 SQLException (java.sql.SQLException)29 Index (org.h2.index.Index)28 IndexColumn (org.h2.table.IndexColumn)24 Cursor (org.h2.index.Cursor)21 PreparedStatement (java.sql.PreparedStatement)20 ResultSet (java.sql.ResultSet)20 StatementBuilder (org.h2.util.StatementBuilder)20 ArrayList (java.util.ArrayList)19 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)18 Expression (org.h2.expression.Expression)17 Statement (java.sql.Statement)16 Constraint (org.h2.constraint.Constraint)16 ValueString (org.h2.value.ValueString)16 Connection (java.sql.Connection)15 SimpleResultSet (org.h2.tools.SimpleResultSet)15