Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add appendBytes method to appender #39

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a test with binary data, invalid utf-8, and null bytes?

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
Loading