Search in sources :

Example 11 with SimpleResultSet

use of org.h2.tools.SimpleResultSet in project h2database by h2database.

the class CsvSample method write.

/**
 * Write a CSV file.
 */
static void write() throws SQLException {
    SimpleResultSet rs = new SimpleResultSet();
    rs.addColumn("NAME", Types.VARCHAR, 255, 0);
    rs.addColumn("EMAIL", Types.VARCHAR, 255, 0);
    rs.addColumn("PHONE", Types.VARCHAR, 255, 0);
    rs.addRow("Bob Meier", "bob.meier@abcde.abc", "+41123456789");
    rs.addRow("John Jones", "john.jones@abcde.abc", "+41976543210");
    new Csv().write("data/test.csv", rs, null);
}
Also used : SimpleResultSet(org.h2.tools.SimpleResultSet) Csv(org.h2.tools.Csv)

Example 12 with SimpleResultSet

use of org.h2.tools.SimpleResultSet in project h2database by h2database.

the class FunctionMultiReturn method polar2Cartesian.

/**
 * Convert polar coordinates to cartesian coordinates. The function may be
 * called twice, once to retrieve the result columns (with null parameters),
 * and the second time to return the data.
 *
 * @param r the distance from the point 0/0
 * @param alpha the angle
 * @return a result set with two columns: x and y
 */
public static ResultSet polar2Cartesian(Double r, Double alpha) {
    SimpleResultSet rs = new SimpleResultSet();
    rs.addColumn("X", Types.DOUBLE, 0, 0);
    rs.addColumn("Y", Types.DOUBLE, 0, 0);
    if (r != null && alpha != null) {
        double x = r.doubleValue() * Math.cos(alpha.doubleValue());
        double y = r.doubleValue() * Math.sin(alpha.doubleValue());
        rs.addRow(x, y);
    }
    return rs;
}
Also used : SimpleResultSet(org.h2.tools.SimpleResultSet)

Example 13 with SimpleResultSet

use of org.h2.tools.SimpleResultSet in project h2database by h2database.

the class FunctionMultiReturn method polar2CartesianSet.

/**
 * Convert a set of polar coordinates to cartesian coordinates. The function
 * may be called twice, once to retrieve the result columns (with null
 * parameters), and the second time to return the data.
 *
 * @param conn the connection
 * @param query the query
 * @return a result set with the coordinates
 */
public static ResultSet polar2CartesianSet(Connection conn, String query) throws SQLException {
    SimpleResultSet result = new SimpleResultSet();
    result.addColumn("R", Types.DOUBLE, 0, 0);
    result.addColumn("A", Types.DOUBLE, 0, 0);
    result.addColumn("X", Types.DOUBLE, 0, 0);
    result.addColumn("Y", Types.DOUBLE, 0, 0);
    if (query != null) {
        ResultSet rs = conn.createStatement().executeQuery(query);
        while (rs.next()) {
            double r = rs.getDouble("R");
            double alpha = rs.getDouble("A");
            double x = r * Math.cos(alpha);
            double y = r * Math.sin(alpha);
            result.addRow(r, alpha, x, y);
        }
    }
    return result;
}
Also used : SimpleResultSet(org.h2.tools.SimpleResultSet) ResultSet(java.sql.ResultSet) SimpleResultSet(org.h2.tools.SimpleResultSet)

Example 14 with SimpleResultSet

use of org.h2.tools.SimpleResultSet in project h2database by h2database.

the class ValueResultSet method convertPrecision.

@Override
public Value convertPrecision(long precision, boolean force) {
    if (!force) {
        return this;
    }
    SimpleResultSet rs = new SimpleResultSet();
    rs.setAutoClose(false);
    return ValueResultSet.get(rs);
}
Also used : SimpleResultSet(org.h2.tools.SimpleResultSet)

Example 15 with SimpleResultSet

use of org.h2.tools.SimpleResultSet 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)

Aggregations

SimpleResultSet (org.h2.tools.SimpleResultSet)46 ResultSet (java.sql.ResultSet)11 SQLException (java.sql.SQLException)10 BigDecimal (java.math.BigDecimal)9 BigInteger (java.math.BigInteger)5 Value (org.h2.value.Value)5 Date (java.sql.Date)4 ResultSetMetaData (java.sql.ResultSetMetaData)4 Time (java.sql.Time)4 Timestamp (java.sql.Timestamp)4 ValueString (org.h2.value.ValueString)4 IOException (java.io.IOException)3 PreparedStatement (java.sql.PreparedStatement)3 Document (org.apache.lucene.document.Document)3 JdbcSQLException (org.h2.jdbc.JdbcSQLException)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 Method (java.lang.reflect.Method)2 Array (java.sql.Array)2 Blob (java.sql.Blob)2 Clob (java.sql.Clob)2