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
15 changes: 14 additions & 1 deletion src/main/java/org/duckdb/DuckDBConnection.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import java.sql.Savepoint;
import java.sql.Statement;
import java.sql.Struct;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
import java.util.concurrent.Executor;
Expand Down Expand Up @@ -257,10 +258,22 @@ public CallableStatement prepareCall(String sql, int resultSetType, int resultSe
}

public Map<String, Class<?>> getTypeMap() throws SQLException {
throw new SQLFeatureNotSupportedException("getTypeMap");
if (isClosed()) {
throw new SQLException("Connection was closed");
}
return new HashMap<>();
}

public void setTypeMap(Map<String, Class<?>> map) throws SQLException {
if (isClosed()) {
throw new SQLException("Connection was closed");
}
if (map != null && (map instanceof java.util.HashMap)) {
// we return an empty Hash map if the user gives this back make sure we accept it.
if (map.isEmpty()) {
return;
}
}
throw new SQLFeatureNotSupportedException("setTypeMap");
}

Expand Down
13 changes: 13 additions & 0 deletions src/test/java/org/duckdb/TestDuckDBJDBC.java
Original file line number Diff line number Diff line change
Expand Up @@ -4793,6 +4793,19 @@ public static void test_client_config_retained_on_dup() throws Exception {
}
}

public static void test_empty_typemap_allowed() throws Exception {
try (Connection conn = DriverManager.getConnection(JDBC_URL)) {
Map<String, Class<?>> defaultMap = conn.getTypeMap();
assertEquals(defaultMap.size(), 0);
// check empty not throws
conn.setTypeMap(new HashMap<>());
// check custom map throws
Map<String, Class<?>> customMap = new HashMap<>();
customMap.put("foo", TestDuckDBJDBC.class);
assertThrows(() -> { conn.setTypeMap(customMap); }, SQLException.class);
}
}

public static void main(String[] args) throws Exception {
String arg1 = args.length > 0 ? args[0] : "";
final int statusCode;
Expand Down
Loading