use of org.h2.command.dml.Delete in project h2database by h2database.
the class TestFunctions method testTransactionId.
private void testTransactionId() throws SQLException {
if (config.memory) {
return;
}
Connection conn = getConnection("functions");
Statement stat = conn.createStatement();
stat.execute("create table test(id int)");
ResultSet rs;
rs = stat.executeQuery("call transaction_id()");
rs.next();
assertTrue(rs.getString(1) == null && rs.wasNull());
stat.execute("insert into test values(1)");
rs = stat.executeQuery("call transaction_id()");
rs.next();
assertTrue(rs.getString(1) == null && rs.wasNull());
conn.setAutoCommit(false);
stat.execute("delete from test");
rs = stat.executeQuery("call transaction_id()");
rs.next();
assertNotNull(rs.getString(1));
stat.execute("drop table test");
conn.close();
}
use of org.h2.command.dml.Delete in project h2database by h2database.
the class TestIndex method testHashIndex.
private void testHashIndex() throws SQLException {
reconnect();
stat.execute("create table testA(id int primary key, name varchar)");
stat.execute("create table testB(id int primary key hash, name varchar)");
int len = getSize(300, 3000);
stat.execute("insert into testA select x, 'Hello' from " + "system_range(1, " + len + ")");
stat.execute("insert into testB select x, 'Hello' from " + "system_range(1, " + len + ")");
Random rand = new Random(1);
for (int i = 0; i < len; i++) {
int x = rand.nextInt(len);
String sql = "";
switch(rand.nextInt(3)) {
case 0:
sql = "delete from testA where id = " + x;
break;
case 1:
sql = "update testA set name = " + rand.nextInt(100) + " where id = " + x;
break;
case 2:
sql = "select name from testA where id = " + x;
break;
default:
}
boolean result = stat.execute(sql);
if (result) {
ResultSet rs = stat.getResultSet();
String s1 = rs.next() ? rs.getString(1) : null;
rs = stat.executeQuery(sql.replace('A', 'B'));
String s2 = rs.next() ? rs.getString(1) : null;
assertEquals(s1, s2);
} else {
int count1 = stat.getUpdateCount();
int count2 = stat.executeUpdate(sql.replace('A', 'B'));
assertEquals(count1, count2);
}
}
stat.execute("drop table testA, testB");
conn.close();
}
use of org.h2.command.dml.Delete in project h2database by h2database.
the class TestIndex method testIndexTypes.
private void testIndexTypes() throws SQLException {
Connection conn = getConnection("index");
stat = conn.createStatement();
for (String type : new String[] { "unique", "hash", "unique hash" }) {
stat.execute("create table test(id int)");
stat.execute("create " + type + " index idx_name on test(id)");
stat.execute("insert into test select x from system_range(1, 1000)");
ResultSet rs = stat.executeQuery("select * from test where id=100");
assertTrue(rs.next());
assertFalse(rs.next());
stat.execute("delete from test where id=100");
rs = stat.executeQuery("select * from test where id=100");
assertFalse(rs.next());
rs = stat.executeQuery("select min(id), max(id) from test");
assertTrue(rs.next());
assertEquals(1, rs.getInt(1));
assertEquals(1000, rs.getInt(2));
stat.execute("drop table test");
}
conn.close();
deleteDb("index");
}
use of org.h2.command.dml.Delete in project h2database by h2database.
the class TestLob method testRemoveAfterDeleteAndClose.
private void testRemoveAfterDeleteAndClose() throws Exception {
if (config.memory || config.cipher != null) {
return;
}
deleteDb("lob");
Connection conn = getConnection("lob");
Statement stat = conn.createStatement();
stat.execute("create table test(id int primary key, data clob)");
for (int i = 0; i < 10; i++) {
stat.execute("insert into test values(1, space(100000))");
if (i > 5) {
ResultSet rs = stat.executeQuery("select * from test");
rs.next();
Clob c = rs.getClob(2);
stat.execute("delete from test where id = 1");
c.getSubString(1, 10);
} else {
stat.execute("delete from test where id = 1");
}
}
// some clobs are removed only here (those that were queries for)
conn.close();
Recover.execute(getBaseDir(), "lob");
long size = FileUtils.size(getBaseDir() + "/lob.h2.sql");
assertTrue("size: " + size, size > 1000 && size < 10000);
}
use of org.h2.command.dml.Delete in project h2database by h2database.
the class TestLob method testDeadlock.
/**
* Test for issue 315: Java Level Deadlock on Database & Session Objects
*/
private void testDeadlock() throws Exception {
deleteDb("lob");
Connection conn = getConnection("lob");
Statement stat = conn.createStatement();
stat.execute("create table test(id int primary key, name clob)");
stat.execute("insert into test select x, space(10000) from system_range(1, 3)");
final Connection conn2 = getConnection("lob");
Task task = new Task() {
@Override
public void call() throws Exception {
Statement stat = conn2.createStatement();
stat.setFetchSize(1);
for (int i = 0; !stop; i++) {
ResultSet rs = stat.executeQuery("select * from test where id > -" + i);
while (rs.next()) {
// ignore
}
}
}
};
task.execute();
stat.execute("create table test2(id int primary key, name clob)");
for (int i = 0; i < 100; i++) {
stat.execute("delete from test2");
stat.execute("insert into test2 values(1, space(10000 + " + i + "))");
}
task.get();
conn.close();
conn2.close();
}
Aggregations