use of org.h2.command.dml.Insert in project h2database by h2database.
the class TestMVTableEngine method testTwoPhaseCommit.
private void testTwoPhaseCommit() throws Exception {
if (config.memory) {
return;
}
Connection conn;
Statement stat;
deleteDb(getTestName());
String url = getTestName() + ";MV_STORE=TRUE";
url = getURL(url, true);
conn = getConnection(url);
stat = conn.createStatement();
stat.execute("create table test(id int primary key, name varchar)");
stat.execute("set write_delay 0");
conn.setAutoCommit(false);
stat.execute("insert into test values(1, 'Hello')");
stat.execute("prepare commit test_tx");
stat.execute("shutdown immediately");
JdbcUtils.closeSilently(conn);
conn = getConnection(url);
stat = conn.createStatement();
ResultSet rs;
rs = stat.executeQuery("select * from information_schema.in_doubt");
assertTrue(rs.next());
stat.execute("commit transaction test_tx");
rs = stat.executeQuery("select * from test");
assertTrue(rs.next());
conn.close();
}
use of org.h2.command.dml.Insert in project h2database by h2database.
the class TestMVTableEngine method testSecondaryIndex.
private void testSecondaryIndex() throws SQLException {
Connection conn;
Statement stat;
deleteDb(getTestName());
String url = getTestName() + ";MV_STORE=TRUE";
url = getURL(url, true);
conn = getConnection(url);
stat = conn.createStatement();
stat.execute("create table test(id int)");
int size = 8 * 1024;
stat.execute("insert into test select mod(x * 111, " + size + ") " + "from system_range(1, " + size + ")");
stat.execute("create index on test(id)");
ResultSet rs = stat.executeQuery("select count(*) from test inner join " + "system_range(1, " + size + ") where " + "id = mod(x * 111, " + size + ")");
rs.next();
assertEquals(size, rs.getInt(1));
conn.close();
}
use of org.h2.command.dml.Insert in project h2database by h2database.
the class TestMVTableEngine method testMinMaxWithNull.
private void testMinMaxWithNull() throws Exception {
Connection conn;
Connection conn2;
Statement stat;
Statement stat2;
deleteDb(getTestName());
String url = getTestName() + ";MV_STORE=TRUE;MVCC=TRUE";
url = getURL(url, true);
conn = getConnection(url);
stat = conn.createStatement();
stat.execute("create table test(data int)");
stat.execute("create index on test(data)");
stat.execute("insert into test values(null), (2)");
conn2 = getConnection(url);
stat2 = conn2.createStatement();
conn.setAutoCommit(false);
conn2.setAutoCommit(false);
stat.execute("insert into test values(1)");
ResultSet rs;
rs = stat.executeQuery("select min(data) from test");
rs.next();
assertEquals(1, rs.getInt(1));
rs = stat2.executeQuery("select min(data) from test");
rs.next();
// not yet committed
assertEquals(2, rs.getInt(1));
conn2.close();
conn.close();
}
use of org.h2.command.dml.Insert in project h2database by h2database.
the class TestMVTableEngine method testLobCopy.
private void testLobCopy() throws Exception {
deleteDb(getTestName());
Connection conn = getConnection(getTestName());
Statement stat = conn.createStatement();
stat.execute("create table test(id int primary key, data clob)");
stat = conn.createStatement();
stat.execute("insert into test(id, data) values(2, space(300))");
stat.execute("insert into test(id, data) values(1, space(300))");
stat.execute("alter table test add column x int");
if (!config.memory) {
conn.close();
conn = getConnection(getTestName());
}
stat = conn.createStatement();
ResultSet rs = stat.executeQuery("select data from test");
while (rs.next()) {
rs.getString(1);
}
conn.close();
}
use of org.h2.command.dml.Insert in project h2database by h2database.
the class TestMVTableEngine method testLocking.
private void testLocking() throws Exception {
deleteDb(getTestName());
String dbName = getTestName() + ";MV_STORE=TRUE;MVCC=FALSE";
Connection conn = getConnection(dbName);
Statement stat = conn.createStatement();
stat.execute("set lock_timeout 1000");
stat.execute("create table a(id int primary key, name varchar)");
stat.execute("create table b(id int primary key, name varchar)");
Connection conn1 = getConnection(dbName);
final Statement stat1 = conn1.createStatement();
stat1.execute("set lock_timeout 1000");
conn.setAutoCommit(false);
conn1.setAutoCommit(false);
stat.execute("insert into a values(1, 'Hello')");
stat1.execute("insert into b values(1, 'Hello')");
Task t = new Task() {
@Override
public void call() throws Exception {
stat1.execute("insert into a values(2, 'World')");
}
};
t.execute();
try {
stat.execute("insert into b values(2, 'World')");
throw t.getException();
} catch (SQLException e) {
assertEquals(e.toString(), ErrorCode.DEADLOCK_1, e.getErrorCode());
}
conn1.close();
conn.close();
}
Aggregations