Skip to content
Merged
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
3 changes: 3 additions & 0 deletions src/main/java/org/duckdb/DuckDBConnection.java
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,7 @@ public DuckDBPreparedStatement prepare(String sql) throws SQLException {
}

public DatabaseMetaData getMetaData() throws SQLException {
checkOpen();
return new DuckDBDatabaseMetaData(this);
}

Expand Down Expand Up @@ -505,10 +506,12 @@ public Properties getClientInfo() throws SQLException {
}

public Array createArrayOf(String typeName, Object[] elements) throws SQLException {
checkOpen();
return new DuckDBUserArray(typeName, elements);
}

public Struct createStruct(String typeName, Object[] attributes) throws SQLException {
checkOpen();
return new DuckDBUserStruct(typeName, attributes);
}

Expand Down
52 changes: 52 additions & 0 deletions src/test/java/org/duckdb/TestClosure.java
Original file line number Diff line number Diff line change
Expand Up @@ -672,6 +672,58 @@ public static void test_prepared_stmt_query_timeout() throws Exception {
}
}

// JDBC contract (java.sql.Connection): getMetaData(), createArrayOf() and createStruct() must
// keep working on an open connection and must throw SQLException once it is closed.
public static void test_open_connection_factories_return_objects() throws Exception {
try (Connection conn = DriverManager.getConnection(JDBC_URL)) {
assertNotNull(conn.getMetaData());
assertNotNull(conn.createArrayOf("INTEGER", new Object[] {1, 2}));
assertNotNull(conn.createStruct("STRUCT(a INTEGER, b INTEGER)", new Object[] {1, 2}));
}
}

public static void test_closed_connection_getMetaData_throws() throws Exception {
try (Connection conn = DriverManager.getConnection(JDBC_URL)) {
conn.close();
assertTrue(conn.isClosed());
try {
conn.getMetaData();
fail("getMetaData() on a closed connection should throw SQLException");
} catch (SQLException e) {
assertEquals(e.getMessage(), "Connection was closed");
assertEquals(e.getSQLState(), "08003");
}
}
}

public static void test_closed_connection_createArrayOf_throws() throws Exception {
try (Connection conn = DriverManager.getConnection(JDBC_URL)) {
conn.close();
assertTrue(conn.isClosed());
try {
conn.createArrayOf("INTEGER", new Object[] {1, 2});
fail("createArrayOf() on a closed connection should throw SQLException");
} catch (SQLException e) {
assertEquals(e.getMessage(), "Connection was closed");
assertEquals(e.getSQLState(), "08003");
}
}
}

public static void test_closed_connection_createStruct_throws() throws Exception {
try (Connection conn = DriverManager.getConnection(JDBC_URL)) {
conn.close();
assertTrue(conn.isClosed());
try {
conn.createStruct("STRUCT(a INTEGER, b INTEGER)", new Object[] {1, 2});
fail("createStruct() on a closed connection should throw SQLException");
} catch (SQLException e) {
assertEquals(e.getMessage(), "Connection was closed");
assertEquals(e.getSQLState(), "08003");
}
}
}

public static void manual_test_set_query_timeout_wo_scheduler() throws Exception {
assertTrue(DuckDBDriver.shutdownQueryCancelScheduler());
assertFalse(DuckDBDriver.shutdownQueryCancelScheduler());
Expand Down
Loading