Skip to content

Commit 6fc1ea6

Browse files
authored
Merge pull request #176 from staticlibs/conn_duplicate
Retain client config on connection duplication
2 parents 73139ae + b28e3e6 commit 6fc1ea6

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

src/jni/duckdb_java.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,9 @@ jobject _duckdb_jdbc_startup(JNIEnv *env, jclass, jbyteArray database_j, jboolea
108108

109109
jobject _duckdb_jdbc_connect(JNIEnv *env, jclass, jobject conn_ref_buf) {
110110
auto conn_ref = (ConnectionHolder *)env->GetDirectBufferAddress(conn_ref_buf);
111+
auto config = ClientConfig::GetConfig(*conn_ref->connection->context);
111112
auto conn = new ConnectionHolder(conn_ref->db);
113+
conn->connection->context->config = config;
112114
return env->NewDirectByteBuffer(conn, 0);
113115
}
114116

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

+17
Original file line numberDiff line numberDiff line change
@@ -4776,6 +4776,23 @@ public static void test_typed_connection_properties() throws Exception {
47764776
}
47774777
}
47784778

4779+
public static void test_client_config_retained_on_dup() throws Exception {
4780+
try (Connection conn = DriverManager.getConnection(JDBC_URL)) {
4781+
try (Statement stmt1 = conn.createStatement()) {
4782+
stmt1.execute("set home_directory='test1'");
4783+
try (ResultSet rs = stmt1.executeQuery("select current_setting('home_directory')")) {
4784+
rs.next();
4785+
assertEquals(rs.getString(1), "test1");
4786+
}
4787+
}
4788+
try (Connection dup = ((DuckDBConnection) conn).duplicate(); Statement stmt2 = dup.createStatement();
4789+
ResultSet rs = stmt2.executeQuery("select current_setting('home_directory')")) {
4790+
rs.next();
4791+
assertEquals(rs.getString(1), "test1");
4792+
}
4793+
}
4794+
}
4795+
47794796
public static void main(String[] args) throws Exception {
47804797
String arg1 = args.length > 0 ? args[0] : "";
47814798
final int statusCode;

0 commit comments

Comments
 (0)