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
26 changes: 24 additions & 2 deletions src/main/java/org/duckdb/DuckDBDriver.java
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,24 @@ public boolean acceptsURL(String url) throws SQLException {
}

public DriverPropertyInfo[] getPropertyInfo(String url, Properties info) throws SQLException {
DriverPropertyInfo[] ret = {};
return ret; // no properties
List<DriverPropertyInfo> list = new ArrayList<>();
try (Connection conn = DriverManager.getConnection(url, info); Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery("SELECT name, value, description FROM duckdb_settings()")) {
while (rs.next()) {
String name = rs.getString(1);
String value = rs.getString(2);
String description = rs.getString(3);
list.add(createDriverPropInfo(name, value, description));
}
}
list.add(createDriverPropInfo(DUCKDB_READONLY_PROPERTY, "", "Set connection to read-only mode"));
list.add(createDriverPropInfo(DUCKDB_USER_AGENT_PROPERTY, "", "Custom user agent string"));
list.add(createDriverPropInfo(JDBC_STREAM_RESULTS, "", "Enable result set streaming"));
list.add(createDriverPropInfo(JDBC_AUTO_COMMIT, "", "Set default auto-commit mode"));
list.add(createDriverPropInfo(JDBC_PIN_DB, "",
"Do not close the DB instance after all connections to it are closed"));
list.sort((o1, o2) -> o1.name.compareToIgnoreCase(o2.name));
return list.toArray(new DriverPropertyInfo[0]);
}

public int getMajorVersion() {
Expand Down Expand Up @@ -229,6 +245,12 @@ public static boolean releaseDB(String url) throws SQLException {
}
}

private static DriverPropertyInfo createDriverPropInfo(String name, String value, String description) {
DriverPropertyInfo dpi = new DriverPropertyInfo(name, value);
dpi.description = description;
return dpi;
}

private static class ParsedProps {
final String shortUrl;
final LinkedHashMap<String, String> props;
Expand Down
12 changes: 12 additions & 0 deletions src/test/java/org/duckdb/TestDuckDBJDBC.java
Original file line number Diff line number Diff line change
Expand Up @@ -3644,6 +3644,18 @@ public static void test_pinned_db() throws Exception {
DriverManager.getConnection(memUrl, config).close();
}

public static void test_driver_property_info() throws Exception {
Driver driver = DriverManager.getDriver(JDBC_URL);
DriverPropertyInfo[] dpis = driver.getPropertyInfo(JDBC_URL, null);
for (DriverPropertyInfo dpi : dpis) {
assertNotNull(dpi.name);
assertNotNull(dpi.value);
assertNotNull(dpi.description);
}
assertNotNull(dpis);
assertTrue(dpis.length > 0);
}

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