Skip to content

Commit b28e3e6

Browse files
committed
Retain client config on connection duplication
This change copies `ClientConfig` to a new connection on `duplicate()` call. Testing: new test added that checks that `home_directory` value is retained in a duplicated connection. Fixes: #148
1 parent 955c3a0 commit b28e3e6

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

src/jni/duckdb_java.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,9 @@ jobject _duckdb_jdbc_startup(JNIEnv *env, jclass, jbyteArray database_j, jboolea
107107

108108
jobject _duckdb_jdbc_connect(JNIEnv *env, jclass, jobject conn_ref_buf) {
109109
auto conn_ref = (ConnectionHolder *)env->GetDirectBufferAddress(conn_ref_buf);
110+
auto config = ClientConfig::GetConfig(*conn_ref->connection->context);
110111
auto conn = new ConnectionHolder(conn_ref->db);
112+
conn->connection->context->config = config;
111113
return env->NewDirectByteBuffer(conn, 0);
112114
}
113115

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4798,6 +4798,23 @@ public static void test_typed_connection_properties() throws Exception {
47984798
}
47994799
}
48004800

4801+
public static void test_client_config_retained_on_dup() throws Exception {
4802+
try (Connection conn = DriverManager.getConnection(JDBC_URL)) {
4803+
try (Statement stmt1 = conn.createStatement()) {
4804+
stmt1.execute("set home_directory='test1'");
4805+
try (ResultSet rs = stmt1.executeQuery("select current_setting('home_directory')")) {
4806+
rs.next();
4807+
assertEquals(rs.getString(1), "test1");
4808+
}
4809+
}
4810+
try (Connection dup = ((DuckDBConnection) conn).duplicate(); Statement stmt2 = dup.createStatement();
4811+
ResultSet rs = stmt2.executeQuery("select current_setting('home_directory')")) {
4812+
rs.next();
4813+
assertEquals(rs.getString(1), "test1");
4814+
}
4815+
}
4816+
}
4817+
48014818
public static void main(String[] args) throws Exception {
48024819
System.exit(runTests(args, TestDuckDBJDBC.class, TestExtensionTypes.class));
48034820
}

0 commit comments

Comments
 (0)