Search in sources :

Example 26 with Replace

use of org.h2.command.dml.Replace in project h2database by h2database.

the class TestConnectionInfo method testName.

private void testName() throws Exception {
    char differentFileSeparator = File.separatorChar == '/' ? '\\' : '/';
    ConnectionInfo connectionInfo = new ConnectionInfo("./test" + differentFileSeparator + "subDir");
    File file = new File("test" + File.separatorChar + "subDir");
    assertEquals(file.getCanonicalPath().replace('\\', '/'), connectionInfo.getName());
}
Also used : ConnectionInfo(org.h2.engine.ConnectionInfo) File(java.io.File)

Example 27 with Replace

use of org.h2.command.dml.Replace in project h2database by h2database.

the class TestMVTableEngine method testDataTypes.

private void testDataTypes() throws Exception {
    deleteDb(getTestName());
    String dbName = getTestName() + ";MV_STORE=TRUE";
    Connection conn = getConnection(dbName);
    Statement stat = conn.createStatement();
    stat.execute("create table test(id int primary key, " + "vc varchar," + "ch char(10)," + "bo boolean," + "by tinyint," + "sm smallint," + "bi bigint," + "de decimal," + "re real," + "do double," + "ti time," + "da date," + "ts timestamp," + "bin binary," + "uu uuid," + "bl blob," + "cl clob)");
    stat.execute("insert into test values(1000, '', '', null, 0, 0, 0, " + "9, 2, 3, '10:00:00', '2001-01-01', " + "'2010-10-10 10:10:10', x'00', 0, x'b1', 'clob')");
    stat.execute("insert into test values(1, 'vc', 'ch', true, 8, 16, 64, " + "123.00, 64.0, 32.0, '10:00:00', '2001-01-01', " + "'2010-10-10 10:10:10', x'00', 0, x'b1', 'clob')");
    stat.execute("insert into test values(-1, " + "'quite a long string \u1234 \u00ff', 'ch', false, -8, -16, -64, " + "0, 0, 0, '10:00:00', '2001-01-01', " + "'2010-10-10 10:10:10', SECURE_RAND(100), 0, x'b1', 'clob')");
    stat.execute("insert into test values(-1000, space(1000), 'ch', " + "false, -8, -16, -64, " + "1, 1, 1, '10:00:00', '2001-01-01', " + "'2010-10-10 10:10:10', SECURE_RAND(100), 0, x'b1', 'clob')");
    if (!config.memory) {
        conn.close();
        conn = getConnection(dbName);
        stat = conn.createStatement();
    }
    ResultSet rs;
    rs = stat.executeQuery("select * from test order by id desc");
    rs.next();
    assertEquals(1000, rs.getInt(1));
    assertEquals("", rs.getString(2));
    assertEquals("", rs.getString(3));
    assertFalse(rs.getBoolean(4));
    assertEquals(0, rs.getByte(5));
    assertEquals(0, rs.getShort(6));
    assertEquals(0, rs.getLong(7));
    assertEquals("9", rs.getBigDecimal(8).toString());
    assertEquals(2d, rs.getDouble(9));
    assertEquals(3d, rs.getFloat(10));
    assertEquals("10:00:00", rs.getString(11));
    assertEquals("2001-01-01", rs.getString(12));
    assertEquals("2010-10-10 10:10:10", rs.getString(13));
    assertEquals(1, rs.getBytes(14).length);
    assertEquals("00000000-0000-0000-0000-000000000000", rs.getString(15));
    assertEquals(1, rs.getBytes(16).length);
    assertEquals("clob", rs.getString(17));
    rs.next();
    assertEquals(1, rs.getInt(1));
    assertEquals("vc", rs.getString(2));
    assertEquals("ch", rs.getString(3));
    assertTrue(rs.getBoolean(4));
    assertEquals(8, rs.getByte(5));
    assertEquals(16, rs.getShort(6));
    assertEquals(64, rs.getLong(7));
    assertEquals("123.00", rs.getBigDecimal(8).toString());
    assertEquals(64d, rs.getDouble(9));
    assertEquals(32d, rs.getFloat(10));
    assertEquals("10:00:00", rs.getString(11));
    assertEquals("2001-01-01", rs.getString(12));
    assertEquals("2010-10-10 10:10:10", rs.getString(13));
    assertEquals(1, rs.getBytes(14).length);
    assertEquals("00000000-0000-0000-0000-000000000000", rs.getString(15));
    assertEquals(1, rs.getBytes(16).length);
    assertEquals("clob", rs.getString(17));
    rs.next();
    assertEquals(-1, rs.getInt(1));
    assertEquals("quite a long string \u1234 \u00ff", rs.getString(2));
    assertEquals("ch", rs.getString(3));
    assertFalse(rs.getBoolean(4));
    assertEquals(-8, rs.getByte(5));
    assertEquals(-16, rs.getShort(6));
    assertEquals(-64, rs.getLong(7));
    assertEquals("0", rs.getBigDecimal(8).toString());
    assertEquals(0.0d, rs.getDouble(9));
    assertEquals(0.0d, rs.getFloat(10));
    assertEquals("10:00:00", rs.getString(11));
    assertEquals("2001-01-01", rs.getString(12));
    assertEquals("2010-10-10 10:10:10", rs.getString(13));
    assertEquals(100, rs.getBytes(14).length);
    assertEquals("00000000-0000-0000-0000-000000000000", rs.getString(15));
    assertEquals(1, rs.getBytes(16).length);
    assertEquals("clob", rs.getString(17));
    rs.next();
    assertEquals(-1000, rs.getInt(1));
    assertEquals(1000, rs.getString(2).length());
    assertEquals("ch", rs.getString(3));
    assertFalse(rs.getBoolean(4));
    assertEquals(-8, rs.getByte(5));
    assertEquals(-16, rs.getShort(6));
    assertEquals(-64, rs.getLong(7));
    assertEquals("1", rs.getBigDecimal(8).toString());
    assertEquals(1.0d, rs.getDouble(9));
    assertEquals(1.0d, rs.getFloat(10));
    assertEquals("10:00:00", rs.getString(11));
    assertEquals("2001-01-01", rs.getString(12));
    assertEquals("2010-10-10 10:10:10", rs.getString(13));
    assertEquals(100, rs.getBytes(14).length);
    assertEquals("00000000-0000-0000-0000-000000000000", rs.getString(15));
    assertEquals(1, rs.getBytes(16).length);
    assertEquals("clob", rs.getString(17));
    stat.execute("drop table test");
    stat.execute("create table test(id int, obj object, " + "rs result_set, arr array, ig varchar_ignorecase)");
    PreparedStatement prep = conn.prepareStatement("insert into test values(?, ?, ?, ?, ?)");
    prep.setInt(1, 1);
    prep.setObject(2, new java.lang.AssertionError());
    prep.setObject(3, stat.executeQuery("select 1 from dual"));
    prep.setObject(4, new Object[] { 1, 2 });
    prep.setObject(5, "test");
    prep.execute();
    prep.setInt(1, 1);
    prep.setObject(2, new java.lang.AssertionError());
    prep.setObject(3, stat.executeQuery("select 1 from dual"));
    prep.setObject(4, new Object[] { new BigDecimal(new String(new char[1000]).replace((char) 0, '1')) });
    prep.setObject(5, "test");
    prep.execute();
    if (!config.memory) {
        conn.close();
        conn = getConnection(dbName);
        stat = conn.createStatement();
    }
    stat.execute("select * from test");
    rs = stat.executeQuery("script");
    int count = 0;
    while (rs.next()) {
        count++;
    }
    assertTrue(count < 10);
    stat.execute("drop table test");
    conn.close();
}
Also used : PreparedStatement(java.sql.PreparedStatement) Statement(java.sql.Statement) Connection(java.sql.Connection) JdbcConnection(org.h2.jdbc.JdbcConnection) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) BigDecimal(java.math.BigDecimal) Savepoint(java.sql.Savepoint)

Example 28 with Replace

use of org.h2.command.dml.Replace in project h2database by h2database.

the class TestMVStore method testCompressed.

private void testCompressed() {
    String fileName = getBaseDir() + "/" + getTestName();
    FileUtils.delete(fileName);
    long lastSize = 0;
    for (int level = 0; level <= 2; level++) {
        FileUtils.delete(fileName);
        MVStore.Builder builder = new MVStore.Builder().fileName(fileName);
        if (level == 1) {
            builder.compress();
        } else if (level == 2) {
            builder.compressHigh();
        }
        MVStore s = builder.open();
        MVMap<String, String> map = s.openMap("data");
        String data = new String(new char[1000]).replace((char) 0, 'x');
        for (int i = 0; i < 400; i++) {
            map.put(data + i, data);
        }
        s.close();
        long size = FileUtils.size(fileName);
        if (level > 0) {
            assertTrue(size < lastSize);
        }
        lastSize = size;
        s = new MVStore.Builder().fileName(fileName).open();
        map = s.openMap("data");
        for (int i = 0; i < 400; i++) {
            assertEquals(data, map.get(data + i));
        }
        s.close();
    }
}
Also used : MVStore(org.h2.mvstore.MVStore)

Example 29 with Replace

use of org.h2.command.dml.Replace in project h2database by h2database.

the class TestSynonymForTable method testDropSchema.

private void testDropSchema() throws SQLException {
    Connection conn = getConnection("synonym");
    Statement stat = conn.createStatement();
    stat.execute("CREATE SCHEMA IF NOT EXISTS s1");
    stat.execute("CREATE TABLE IF NOT EXISTS s1.backingtable(id INT PRIMARY KEY)");
    stat.execute("CREATE OR REPLACE SYNONYM testsynonym FOR s1.backingtable");
    stat.execute("DROP SCHEMA s1 CASCADE");
    assertThrows(JdbcSQLException.class, stat).execute("SELECT id FROM testsynonym");
    conn.close();
}
Also used : Statement(java.sql.Statement) PreparedStatement(java.sql.PreparedStatement) Connection(java.sql.Connection) JdbcSQLException(org.h2.jdbc.JdbcSQLException)

Example 30 with Replace

use of org.h2.command.dml.Replace in project h2database by h2database.

the class TestSynonymForTable method testCreateOrReplaceExistingTable.

private void testCreateOrReplaceExistingTable() throws SQLException {
    Connection conn = getConnection("synonym");
    Statement stat = conn.createStatement();
    stat.execute("CREATE TABLE IF NOT EXISTS backingtable(id INT PRIMARY KEY)");
    assertThrows(JdbcSQLException.class, stat).execute("CREATE OR REPLACE SYNONYM backingtable FOR backingtable");
    conn.close();
}
Also used : Statement(java.sql.Statement) PreparedStatement(java.sql.PreparedStatement) Connection(java.sql.Connection) JdbcSQLException(org.h2.jdbc.JdbcSQLException)

Aggregations

Connection (java.sql.Connection)7 ResultSet (java.sql.ResultSet)7 PreparedStatement (java.sql.PreparedStatement)6 Statement (java.sql.Statement)6 Expression (org.h2.expression.Expression)4 JdbcConnection (org.h2.jdbc.JdbcConnection)4 MVStore (org.h2.mvstore.MVStore)4 Column (org.h2.table.Column)4 Value (org.h2.value.Value)4 ValueString (org.h2.value.ValueString)4 BigDecimal (java.math.BigDecimal)3 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)3 ExpressionColumn (org.h2.expression.ExpressionColumn)3 SQLException (java.sql.SQLException)2 LinkedHashMap (java.util.LinkedHashMap)2 RuleFixed (org.h2.bnf.RuleFixed)2 RuleHead (org.h2.bnf.RuleHead)2 ValueExpression (org.h2.expression.ValueExpression)2 JdbcSQLException (org.h2.jdbc.JdbcSQLException)2 DbException (org.h2.message.DbException)2