Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,19 @@ public class Comdb2DatabaseMetaData implements DatabaseMetaData {
private String url;
Comdb2Connection conn;
private String sqlkws = null;
private String databaseProductVersion = "UNKNOWN";
private SQLException databaseProductVersionException = null;

Comdb2DatabaseMetaData(Comdb2Connection conn) throws SQLException {
url = "jdbc:comdb2:" + conn.getDatabase() + ":" + conn.getCluster();
this.conn = conn;
conn.lookup();
stmt = conn.createStatement();
try {
databaseProductVersion = readDatabaseProductVersion(stmt);
} catch (SQLException e) {
databaseProductVersionException = e;
}
}

public <T> T unwrap(Class<T> iface) throws SQLException {
Expand Down Expand Up @@ -85,12 +92,17 @@ public String getDatabaseProductName() throws SQLException {
}

public String getDatabaseProductVersion() throws SQLException {
String ret;
ResultSet rs = stmt.executeQuery("select comdb2_version()");
ret = "UNKNOWN";
while (rs.next())
ret = rs.getString(1);
rs.close();
if (databaseProductVersionException != null)
throw databaseProductVersionException;
return databaseProductVersion;
}

private String readDatabaseProductVersion(Statement statement) throws SQLException {
String ret = "UNKNOWN";
try (ResultSet rs = statement.executeQuery("select comdb2_version()")) {
while (rs.next())
ret = rs.getString(1);
}
return ret;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,21 @@ public class DatabaseMetaDataTest {
stmt.executeUpdate("drop table t1");
}

@Test public void testGetTablesResultSetSurvivesProductVersionLookup() throws SQLException {
stmt.executeUpdate("create table t1 (i int, j text)");

rs = dmd.getTables(null, null, "t1", null);
String version = dmd.getDatabaseProductVersion();

assertNotNull(version);
assertTrue(rs.next());
assertEquals(rs.getString("TABLE_NAME"), "t1");
assertFalse(rs.next());
rs.close();

stmt.executeUpdate("drop table t1");
}

@Test public void testGetColumns() throws SQLException {
stmt.executeUpdate("create table t1 (i int, j text)");
stmt.executeUpdate("create table t2 (i int, j text)");
Expand Down