diff --git a/src/main/java/org/duckdb/DuckDBDriver.java b/src/main/java/org/duckdb/DuckDBDriver.java index 94bdc9ad3..81523068a 100644 --- a/src/main/java/org/duckdb/DuckDBDriver.java +++ b/src/main/java/org/duckdb/DuckDBDriver.java @@ -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 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() { @@ -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 props; diff --git a/src/test/java/org/duckdb/TestDuckDBJDBC.java b/src/test/java/org/duckdb/TestDuckDBJDBC.java index 8b84aef51..d0bb17a14 100644 --- a/src/test/java/org/duckdb/TestDuckDBJDBC.java +++ b/src/test/java/org/duckdb/TestDuckDBJDBC.java @@ -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;