Search in sources :

Example 41 with SimpleResultSet

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

the class TestIndex method testFunctionIndexFunction.

/**
 * This method is called from the database.
 *
 * @return the result set
 */
public static ResultSet testFunctionIndexFunction() {
    // CommandContainer.recompileIfRequired()
    for (StackTraceElement element : Thread.currentThread().getStackTrace()) {
        if (element.getClassName().startsWith(Select.class.getName())) {
            testFunctionIndexCounter++;
            break;
        }
    }
    SimpleResultSet rs = new SimpleResultSet();
    rs.addColumn("ID", Types.INTEGER, ValueInt.PRECISION, 0);
    rs.addColumn("VALUE", Types.INTEGER, ValueInt.PRECISION, 0);
    rs.addRow(1, 10);
    rs.addRow(2, 20);
    rs.addRow(3, 30);
    return rs;
}
Also used : SimpleResultSet(org.h2.tools.SimpleResultSet) Select(org.h2.command.dml.Select)

Example 42 with SimpleResultSet

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

the class TestSpatial method getRandomGeometryTable.

/**
 * Generate a result set with random geometry data.
 * Used as an ALIAS function.
 *
 * @param seed the random seed
 * @param rowCount the number of rows
 * @param minX the smallest x
 * @param maxX the largest x
 * @param minY the smallest y
 * @param maxY the largest y
 * @param maxLength the maximum length
 * @return a result set
 */
public static ResultSet getRandomGeometryTable(final long seed, final long rowCount, final double minX, final double maxX, final double minY, final double maxY, final double maxLength) {
    SimpleResultSet rs = new SimpleResultSet(new SimpleRowSource() {

        private final Random random = new Random(seed);

        private int currentRow;

        @Override
        public Object[] readRow() throws SQLException {
            if (currentRow++ < rowCount) {
                return new Object[] { getRandomGeometry(random, minX, maxX, minY, maxY, maxLength) };
            }
            return null;
        }

        @Override
        public void close() {
        // nothing to do
        }

        @Override
        public void reset() throws SQLException {
            random.setSeed(seed);
        }
    });
    rs.addColumn("the_geom", Types.OTHER, "GEOMETRY", Integer.MAX_VALUE, 0);
    return rs;
}
Also used : SimpleResultSet(org.h2.tools.SimpleResultSet) Random(java.util.Random) SQLException(java.sql.SQLException) SimpleRowSource(org.h2.tools.SimpleRowSource) Point(org.locationtech.jts.geom.Point) Savepoint(java.sql.Savepoint)

Example 43 with SimpleResultSet

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

the class Function method getMatrix.

/**
 * Creates a simple result set with two columns.
 *
 * @param conn the connection
 * @param size the number of x and y values
 * @return the result set with two columns
 */
public static ResultSet getMatrix(Connection conn, Integer size) throws SQLException {
    SimpleResultSet rs = new SimpleResultSet();
    rs.addColumn("X", Types.INTEGER, 10, 0);
    rs.addColumn("Y", Types.INTEGER, 10, 0);
    String url = conn.getMetaData().getURL();
    if (url.equals("jdbc:columnlist:connection")) {
        return rs;
    }
    for (int s = size.intValue(), x = 0; x < s; x++) {
        for (int y = 0; y < s; y++) {
            rs.addRow(x, y);
        }
    }
    return rs;
}
Also used : SimpleResultSet(org.h2.tools.SimpleResultSet)

Example 44 with SimpleResultSet

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

the class Function method simpleResultSet.

/**
 * Creates a simple result set with one row.
 *
 * @return the result set
 */
public static ResultSet simpleResultSet() {
    SimpleResultSet rs = new SimpleResultSet();
    rs.addColumn("ID", Types.INTEGER, 10, 0);
    rs.addColumn("NAME", Types.VARCHAR, 255, 0);
    rs.addRow(0, "Hello");
    return rs;
}
Also used : SimpleResultSet(org.h2.tools.SimpleResultSet)

Example 45 with SimpleResultSet

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

the class ValueResultSet method getCopy.

/**
 * Create a result set value for the given result set. The result set will
 * be fully read in memory. The original result set is not closed.
 *
 * @param rs the result set
 * @param maxrows the maximum number of rows to read (0 to just read the
 *            meta data)
 * @return the value
 */
public static ValueResultSet getCopy(ResultSet rs, int maxrows) {
    try {
        ResultSetMetaData meta = rs.getMetaData();
        int columnCount = meta.getColumnCount();
        SimpleResultSet simple = new SimpleResultSet();
        simple.setAutoClose(false);
        ValueResultSet val = new ValueResultSet(simple);
        for (int i = 0; i < columnCount; i++) {
            String name = meta.getColumnLabel(i + 1);
            int sqlType = meta.getColumnType(i + 1);
            int precision = meta.getPrecision(i + 1);
            int scale = meta.getScale(i + 1);
            simple.addColumn(name, sqlType, precision, scale);
        }
        for (int i = 0; i < maxrows && rs.next(); i++) {
            Object[] list = new Object[columnCount];
            for (int j = 0; j < columnCount; j++) {
                list[j] = rs.getObject(j + 1);
            }
            simple.addRow(list);
        }
        return val;
    } catch (SQLException e) {
        throw DbException.convert(e);
    }
}
Also used : ResultSetMetaData(java.sql.ResultSetMetaData) SimpleResultSet(org.h2.tools.SimpleResultSet) SQLException(java.sql.SQLException)

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