Skip to content

Commit fc7e02d

Browse files
Add appendBytes method to appender
1 parent dedf7b7 commit fc7e02d

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

src/main/java/org/duckdb/DuckDBAppender.java

+4-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import java.sql.SQLException;
66
import java.time.LocalDateTime;
77
import java.math.BigDecimal;
8-
import org.duckdb.DuckDBTimestamp;
98

109
public class DuckDBAppender implements AutoCloseable {
1110

@@ -51,6 +50,10 @@ public void append(long value) throws SQLException {
5150
DuckDBNative.duckdb_jdbc_appender_append_long(appender_ref, value);
5251
}
5352

53+
public void appendBytes(byte[] value) throws SQLException {
54+
DuckDBNative.duckdb_jdbc_appender_append_string(appender_ref, value);
55+
}
56+
5457
// New naming schema for object params to keep compatibility with calling "append(null)"
5558
public void appendLocalDateTime(LocalDateTime value) throws SQLException {
5659
if (value == null) {

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

+21
Original file line numberDiff line numberDiff line change
@@ -2635,6 +2635,27 @@ public static void test_appender_null_varchar() throws Exception {
26352635
conn.close();
26362636
}
26372637

2638+
public static void test_appender_bytes() throws Exception {
2639+
DuckDBConnection conn = DriverManager.getConnection(JDBC_URL).unwrap(DuckDBConnection.class);
2640+
Statement stmt = conn.createStatement();
2641+
2642+
stmt.execute("CREATE TABLE data (a BLOB)");
2643+
DuckDBAppender appender = conn.createAppender(DuckDBConnection.DEFAULT_SCHEMA, "data");
2644+
2645+
appender.beginRow();
2646+
appender.appendBytes("test".getBytes(StandardCharsets.UTF_8));
2647+
appender.endRow();
2648+
appender.flush();
2649+
appender.close();
2650+
2651+
ResultSet results = stmt.executeQuery("SELECT * FROM data");
2652+
assertTrue(results.next());
2653+
assertEquals(new String(results.getBytes(1), StandardCharsets.UTF_8), "test");
2654+
2655+
stmt.close();
2656+
conn.close();
2657+
}
2658+
26382659
public static void test_get_catalog() throws Exception {
26392660
Connection conn = DriverManager.getConnection(JDBC_URL);
26402661
ResultSet rs = conn.getMetaData().getCatalogs();

0 commit comments

Comments
 (0)