Skip to content
Merged
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
2 changes: 1 addition & 1 deletion src/main/java/org/duckdb/DuckDBResultSet.java
Original file line number Diff line number Diff line change
Expand Up @@ -576,7 +576,7 @@ public BigDecimal getBigDecimal(String columnLabel, int scale) throws SQLExcepti
}

public byte[] getBytes(String columnLabel) throws SQLException {
throw new SQLFeatureNotSupportedException("getBytes");
return getBytes(findColumn(columnLabel));
}

public Date getDate(String columnLabel) throws SQLException {
Expand Down
35 changes: 35 additions & 0 deletions src/test/java/org/duckdb/TestDuckDBJDBC.java
Original file line number Diff line number Diff line change
Expand Up @@ -2061,6 +2061,41 @@ public static void test_get_bytes() throws Exception {
}
}

public static void test_get_bytes_by_label() throws Exception {
try (Connection connection = DriverManager.getConnection(JDBC_URL); Statement s = connection.createStatement();
ResultSet rs =
s.executeQuery("SELECT 'abc'::BLOB AS abcCol, ''::BLOB AS emptyCol, NULL::BLOB AS nullCol")) {

assertTrue(rs.next());

assertEquals(rs.getBytes("abcCol"), rs.getBytes(1));
assertEquals(rs.getBytes(1), "abc".getBytes(UTF_8));
assertNotNull(rs.getBytes("abcCol"));
assertFalse(rs.wasNull());

assertEquals(rs.getBytes("emptyCol"), new byte[0]);
assertNotNull(rs.getBytes("emptyCol"));
assertFalse(rs.wasNull());

assertNull(rs.getBytes("nullCol"));
assertTrue(rs.wasNull());

assertEquals(rs.getBytes("ABCCOL"), "abc".getBytes(UTF_8));
assertEquals(rs.getBytes("AbCcOl"), "abc".getBytes(UTF_8));

assertThrows(() -> rs.getBytes("does_not_exist"), SQLException.class);
}

try (Connection connection = DriverManager.getConnection(JDBC_URL);
Statement s = connection.createStatement()) {
ResultSet rs = s.executeQuery("SELECT 'abc'::BLOB AS abcCol");
assertTrue(rs.next());
rs.close();
assertTrue(rs.isClosed());
assertThrows(() -> rs.getBytes("abcCol"), SQLException.class);
}
}

public static void test_set_streams() throws Exception {
try (Connection connection = DriverManager.getConnection(JDBC_URL);
PreparedStatement ps = connection.prepareStatement("select ?::VARCHAR")) {
Expand Down
Loading