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