Statement stat = conn.createStatement();
test(stat, "CREATE TABLE NEST1(ID INT PRIMARY KEY,VALUE VARCHAR(255))");
test(stat, "CREATE TABLE NEST2(ID INT PRIMARY KEY,VALUE VARCHAR(255))");
DatabaseMetaData meta = conn.getMetaData();
ArrayList<String> result = New.arrayList();
ResultSet rs1, rs2;
rs1 = meta.getTables(null, null, "NEST%", null);
while (rs1.next()) {
String table = rs1.getString("TABLE_NAME");
rs2 = meta.getColumns(null, null, table, null);
while (rs2.next()) {
String column = rs2.getString("COLUMN_NAME");
trace("Table: " + table + " Column: " + column);
result.add(table + "." + column);
}
}
// should be NEST1.ID, NEST1.NAME, NEST2.ID, NEST2.NAME
assertEquals(result.toString(), 4, result.size());
result = New.arrayList();
test(stat, "INSERT INTO NEST1 VALUES(1,'A')");
test(stat, "INSERT INTO NEST1 VALUES(2,'B')");
test(stat, "INSERT INTO NEST2 VALUES(1,'1')");
test(stat, "INSERT INTO NEST2 VALUES(2,'2')");
Statement s1 = conn.createStatement();
Statement s2 = conn.createStatement();
rs1 = s1.executeQuery("SELECT * FROM NEST1 ORDER BY ID");
while (rs1.next()) {
rs2 = s2.executeQuery("SELECT * FROM NEST2 ORDER BY ID");
while (rs2.next()) {
String v1 = rs1.getString("VALUE");
String v2 = rs2.getString("VALUE");
result.add(v1 + "/" + v2);
}
}
// should be A/1, A/2, B/1, B/2
assertEquals(result.toString(), 4, result.size());
result = New.arrayList();
rs1 = s1.executeQuery("SELECT * FROM NEST1 ORDER BY ID");
rs2 = s1.executeQuery("SELECT * FROM NEST2 ORDER BY ID");
assertThrows(ErrorCode.OBJECT_CLOSED, rs1).next();
// this is already closed, so but closing again should no do any harm
rs1.close();
while (rs2.next()) {
String v1 = rs2.getString("VALUE");
result.add(v1);
}
// should be A, B