Search in sources :

Example 26 with Alias

use of org.h2.expression.Alias in project h2database by h2database.

the class TestFunctions method testWhiteSpacesInParameters.

private void testWhiteSpacesInParameters() throws SQLException {
    deleteDb("functions");
    Connection conn = getConnection("functions");
    Statement stat = conn.createStatement();
    // with white space
    stat.execute("CREATE ALIAS PARSE_INT2 FOR " + "\"java.lang.Integer.parseInt(java.lang.String, int)\"");
    ResultSet rs;
    rs = stat.executeQuery("CALL PARSE_INT2('473', 10)");
    rs.next();
    assertEquals(473, rs.getInt(1));
    stat.execute("DROP ALIAS PARSE_INT2");
    // without white space
    stat.execute("CREATE ALIAS PARSE_INT2 FOR " + "\"java.lang.Integer.parseInt(java.lang.String,int)\"");
    stat.execute("DROP ALIAS PARSE_INT2");
    conn.close();
}
Also used : PreparedStatement(java.sql.PreparedStatement) CallableStatement(java.sql.CallableStatement) Statement(java.sql.Statement) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) SimpleResultSet(org.h2.tools.SimpleResultSet)

Example 27 with Alias

use of org.h2.expression.Alias in project h2database by h2database.

the class TestDeadlock method testDeadlockInFulltextSearch.

private void testDeadlockInFulltextSearch() throws SQLException {
    deleteDb("deadlock");
    String url = "deadlock";
    Connection conn, conn2;
    conn = getConnection(url);
    conn2 = getConnection(url);
    final Statement stat = conn.createStatement();
    Statement stat2 = conn2.createStatement();
    stat.execute("create alias if not exists ft_init for " + "\"org.h2.fulltext.FullText.init\"");
    stat.execute("call ft_init()");
    stat.execute("create table test(id int primary key, name varchar)");
    stat.execute("call ft_create_index('PUBLIC', 'TEST', null)");
    Task t = new Task() {

        @Override
        public void call() throws Exception {
            while (!stop) {
                stat.executeQuery("select * from test");
            }
        }
    };
    t.execute();
    long start = System.nanoTime();
    while (System.nanoTime() - start < TimeUnit.SECONDS.toNanos(1)) {
        stat2.execute("insert into test values(1, 'Hello')");
        stat2.execute("delete from test");
    }
    t.get();
    conn2.close();
    conn.close();
    conn = getConnection(url);
    conn.createStatement().execute("drop all objects");
    conn.close();
}
Also used : Task(org.h2.util.Task) Statement(java.sql.Statement) Connection(java.sql.Connection)

Example 28 with Alias

use of org.h2.expression.Alias in project h2database by h2database.

the class TestSpatial method testJavaAlias.

/**
 * Test java alias with Geometry type.
 */
private void testJavaAlias() throws SQLException {
    deleteDb("spatial");
    try (Connection conn = getConnection(URL)) {
        Statement stat = conn.createStatement();
        stat.execute("CREATE ALIAS T_GEOM_FROM_TEXT FOR \"" + TestSpatial.class.getName() + ".geomFromText\"");
        stat.execute("create table test(id int primary key " + "auto_increment, the_geom geometry)");
        stat.execute("insert into test(the_geom) values(" + "T_GEOM_FROM_TEXT('POLYGON ((" + "62 48, 84 48, 84 42, 56 34, 62 48))',1488))");
        stat.execute("DROP ALIAS T_GEOM_FROM_TEXT");
        ResultSet rs = stat.executeQuery("select the_geom from test");
        assertTrue(rs.next());
        assertEquals("POLYGON ((62 48, 84 48, 84 42, 56 34, 62 48))", rs.getObject(1).toString());
    }
    deleteDb("spatial");
}
Also used : Statement(java.sql.Statement) Connection(java.sql.Connection) SimpleResultSet(org.h2.tools.SimpleResultSet) ResultSet(java.sql.ResultSet)

Example 29 with Alias

use of org.h2.expression.Alias in project h2database by h2database.

the class TestSpatial method testTableFunctionGeometry.

/**
 * Check that geometry column type is kept with a table function
 */
private void testTableFunctionGeometry() throws SQLException {
    deleteDb("spatial");
    try (Connection conn = getConnection(URL)) {
        Statement stat = conn.createStatement();
        stat.execute("CREATE ALIAS POINT_TABLE FOR \"" + TestSpatial.class.getName() + ".pointTable\"");
        stat.execute("create table test as select * from point_table(1, 1)");
        // Read column type
        ResultSet columnMeta = conn.getMetaData().getColumns(null, null, "TEST", "THE_GEOM");
        assertTrue(columnMeta.next());
        assertEquals("geometry", columnMeta.getString("TYPE_NAME").toLowerCase());
        assertFalse(columnMeta.next());
    }
    deleteDb("spatial");
}
Also used : Statement(java.sql.Statement) Connection(java.sql.Connection) SimpleResultSet(org.h2.tools.SimpleResultSet) ResultSet(java.sql.ResultSet)

Example 30 with Alias

use of org.h2.expression.Alias in project h2database by h2database.

the class TestOptimizations method testOptimizeInJoinSelect.

private void testOptimizeInJoinSelect() throws SQLException {
    deleteDb("optimizations");
    Connection conn = getConnection("optimizations");
    Statement stat = conn.createStatement();
    stat.execute("create table item(id int primary key)");
    stat.execute("insert into item values(1)");
    stat.execute("create alias opt for \"" + getClass().getName() + ".optimizeInJoinSelect\"");
    PreparedStatement prep = conn.prepareStatement("select * from item where id in (select x from opt())");
    ResultSet rs = prep.executeQuery();
    assertTrue(rs.next());
    assertEquals(1, rs.getInt(1));
    assertFalse(rs.next());
    conn.close();
}
Also used : PreparedStatement(java.sql.PreparedStatement) Statement(java.sql.Statement) Connection(java.sql.Connection) SimpleResultSet(org.h2.tools.SimpleResultSet) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement)

Aggregations

ResultSet (java.sql.ResultSet)38 Statement (java.sql.Statement)38 Connection (java.sql.Connection)31 SimpleResultSet (org.h2.tools.SimpleResultSet)31 PreparedStatement (java.sql.PreparedStatement)28 CallableStatement (java.sql.CallableStatement)18 ValueString (org.h2.value.ValueString)17 SQLException (java.sql.SQLException)11 Column (org.h2.table.Column)10 GridSqlColumn (org.apache.ignite.internal.processors.query.h2.sql.GridSqlColumn)6 Expression (org.h2.expression.Expression)6 ArrayList (java.util.ArrayList)5 HashMap (java.util.HashMap)5 GridSqlAlias (org.apache.ignite.internal.processors.query.h2.sql.GridSqlAlias)5 GridH2Table (org.apache.ignite.internal.processors.query.h2.opt.GridH2Table)4 GridSqlElement (org.apache.ignite.internal.processors.query.h2.sql.GridSqlElement)4 GridSqlSelect (org.apache.ignite.internal.processors.query.h2.sql.GridSqlSelect)4 GridSqlTable (org.apache.ignite.internal.processors.query.h2.sql.GridSqlTable)4 Session (org.h2.engine.Session)4 ValueExpression (org.h2.expression.ValueExpression)4