Skip to content

Commit

Permalink
Add appendBytes method to appender
Browse files Browse the repository at this point in the history
  • Loading branch information
XuQianJin-Stars committed Jun 21, 2024
1 parent dedf7b7 commit fc7e02d
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/main/java/org/duckdb/DuckDBAppender.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down Expand Up @@ -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) {
Expand Down
21 changes: 21 additions & 0 deletions src/test/java/org/duckdb/TestDuckDBJDBC.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit fc7e02d

Please sign in to comment.