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