diff --git a/src/main/java/org/duckdb/DuckDBAppender.java b/src/main/java/org/duckdb/DuckDBAppender.java index 1a022b04..8407cd52 100644 --- a/src/main/java/org/duckdb/DuckDBAppender.java +++ b/src/main/java/org/duckdb/DuckDBAppender.java @@ -5,7 +5,6 @@ import java.sql.SQLException; import java.time.LocalDateTime; import java.math.BigDecimal; -import org.duckdb.DuckDBTimestamp; public class DuckDBAppender implements AutoCloseable { @@ -51,6 +50,10 @@ public void append(long value) throws SQLException { DuckDBNative.duckdb_jdbc_appender_append_long(appender_ref, value); } + public void appendBytes(byte[] value) throws SQLException { + DuckDBNative.duckdb_jdbc_appender_append_string(appender_ref, value); + } + // New naming schema for object params to keep compatibility with calling "append(null)" public void appendLocalDateTime(LocalDateTime value) throws SQLException { if (value == null) { diff --git a/src/test/java/org/duckdb/TestDuckDBJDBC.java b/src/test/java/org/duckdb/TestDuckDBJDBC.java index 1b4b6315..c29cd79f 100644 --- a/src/test/java/org/duckdb/TestDuckDBJDBC.java +++ b/src/test/java/org/duckdb/TestDuckDBJDBC.java @@ -2635,6 +2635,27 @@ public static void test_appender_null_varchar() throws Exception { conn.close(); } + public static void test_appender_bytes() throws Exception { + DuckDBConnection conn = DriverManager.getConnection(JDBC_URL).unwrap(DuckDBConnection.class); + Statement stmt = conn.createStatement(); + + stmt.execute("CREATE TABLE data (a BLOB)"); + DuckDBAppender appender = conn.createAppender(DuckDBConnection.DEFAULT_SCHEMA, "data"); + + appender.beginRow(); + appender.appendBytes("test".getBytes(StandardCharsets.UTF_8)); + appender.endRow(); + appender.flush(); + appender.close(); + + ResultSet results = stmt.executeQuery("SELECT * FROM data"); + assertTrue(results.next()); + assertEquals(new String(results.getBytes(1), StandardCharsets.UTF_8), "test"); + + stmt.close(); + conn.close(); + } + public static void test_get_catalog() throws Exception { Connection conn = DriverManager.getConnection(JDBC_URL); ResultSet rs = conn.getMetaData().getCatalogs();