Skip to content

Commit 5e419cb

Browse files
committed
Implement getPropertyInfo method for config list
`Driver#getPropertyInfo()` method allows external tools to list configuration options suppored by the DB. This method is pretty obscure and unlikely to be useful with many client tools in practice. But a full list of supported options is required anyway to implement a fix to issue duckdb#232, and it makes sense to use `getPropertyInfo` for that as a single method for this functionality. Testing: new test added.
1 parent 5bf9ae3 commit 5e419cb

File tree

2 files changed

+36
-2
lines changed

2 files changed

+36
-2
lines changed

src/main/java/org/duckdb/DuckDBDriver.java

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,24 @@ public boolean acceptsURL(String url) throws SQLException {
100100
}
101101

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

107123
public int getMajorVersion() {
@@ -229,6 +245,12 @@ public static boolean releaseDB(String url) throws SQLException {
229245
}
230246
}
231247

248+
private static DriverPropertyInfo createDriverPropInfo(String name, String value, String description) {
249+
DriverPropertyInfo dpi = new DriverPropertyInfo(name, value);
250+
dpi.description = description;
251+
return dpi;
252+
}
253+
232254
private static class ParsedProps {
233255
final String shortUrl;
234256
final LinkedHashMap<String, String> props;

src/test/java/org/duckdb/TestDuckDBJDBC.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3644,6 +3644,18 @@ public static void test_pinned_db() throws Exception {
36443644
DriverManager.getConnection(memUrl, config).close();
36453645
}
36463646

3647+
public static void test_driver_property_info() throws Exception {
3648+
Driver driver = DriverManager.getDriver(JDBC_URL);
3649+
DriverPropertyInfo[] dpis = driver.getPropertyInfo(JDBC_URL, null);
3650+
for (DriverPropertyInfo dpi : dpis) {
3651+
assertNotNull(dpi.name);
3652+
assertNotNull(dpi.value);
3653+
assertNotNull(dpi.description);
3654+
}
3655+
assertNotNull(dpis);
3656+
assertTrue(dpis.length > 0);
3657+
}
3658+
36473659
public static void main(String[] args) throws Exception {
36483660
String arg1 = args.length > 0 ? args[0] : "";
36493661
final int statusCode;

0 commit comments

Comments
 (0)