From 8dd666e131ee21ad97789e30d094e2287c5097b0 Mon Sep 17 00:00:00 2001 From: Orange flavored banana <106858113+moonwhistle@users.noreply.github.com> Date: Tue, 4 Nov 2025 17:32:33 +0900 Subject: [PATCH] feat(jdbc): test setBinaryStream method in JDBC4PreparedStatementTest --- .../jdbc4/JDBC4PreparedStatementTest.java | 66 +++++++++++++++++++ 1 file changed, 66 insertions(+) diff --git a/bindings/java/src/test/java/tech/turso/jdbc4/JDBC4PreparedStatementTest.java b/bindings/java/src/test/java/tech/turso/jdbc4/JDBC4PreparedStatementTest.java index 459b0371a..8a170d622 100644 --- a/bindings/java/src/test/java/tech/turso/jdbc4/JDBC4PreparedStatementTest.java +++ b/bindings/java/src/test/java/tech/turso/jdbc4/JDBC4PreparedStatementTest.java @@ -418,6 +418,7 @@ class JDBC4PreparedStatementTest { connection.prepareStatement("CREATE TABLE test (col TEXT)").execute(); PreparedStatement stmt = connection.prepareStatement("INSERT INTO test (col) VALUES (?)"); + stmt.setAsciiStream(1, null, 0); stmt.execute(); @@ -434,6 +435,7 @@ class JDBC4PreparedStatementTest { PreparedStatement stmt = connection.prepareStatement("INSERT INTO test (col) VALUES (?)"); InputStream empty = new ByteArrayInputStream(new byte[0]); + stmt.setAsciiStream(1, empty, 10); stmt.execute(); @@ -457,6 +459,70 @@ class JDBC4PreparedStatementTest { assertThrows(SQLException.class, () -> stmt.setAsciiStream(1, stream, -1)); } + @Test + void testSetBinaryStream_insert_and_select() throws SQLException { + connection.prepareStatement("CREATE TABLE test (col BLOB)").execute(); + + PreparedStatement stmt = connection.prepareStatement("INSERT INTO test (col) VALUES (?)"); + + byte[] data = {1, 2, 3, 4, 5}; + InputStream stream = new ByteArrayInputStream(data); + + stmt.setBinaryStream(1, stream, data.length); + stmt.execute(); + + PreparedStatement stmt2 = connection.prepareStatement("SELECT col FROM test"); + ResultSet rs = stmt2.executeQuery(); + + assertTrue(rs.next()); + assertArrayEquals(data, rs.getBytes(1)); + } + + @Test + void testSetBinaryStream_nullStream() throws SQLException { + connection.prepareStatement("CREATE TABLE test (col BLOB)").execute(); + + PreparedStatement stmt = connection.prepareStatement("INSERT INTO test (col) VALUES (?)"); + + stmt.setBinaryStream(1, null, 0); + stmt.execute(); + + PreparedStatement stmt2 = connection.prepareStatement("SELECT col FROM test"); + ResultSet rs = stmt2.executeQuery(); + + assertTrue(rs.next()); + assertNull(rs.getBytes(1)); + } + + @Test + void testSetBinaryStream_emptyStream() throws SQLException { + connection.prepareStatement("CREATE TABLE test (col BLOB)").execute(); + + PreparedStatement stmt = connection.prepareStatement("INSERT INTO test (col) VALUES (?)"); + + InputStream empty = new ByteArrayInputStream(new byte[0]); + stmt.setBinaryStream(1, empty, 10); + stmt.execute(); + + PreparedStatement stmt2 = connection.prepareStatement("SELECT col FROM test"); + ResultSet rs = stmt2.executeQuery(); + + assertTrue(rs.next()); + assertNull(rs.getBytes(1)); + } + + @Test + void testSetBinaryStream_negativeLength() throws SQLException { + connection.prepareStatement("CREATE TABLE test (col BLOB)").execute(); + + PreparedStatement stmt = connection.prepareStatement("INSERT INTO test (col) VALUES (?)"); + + byte[] data = {1, 2, 3}; + InputStream stream = new ByteArrayInputStream(data); + + assertThrows(SQLException.class, () -> stmt.setBinaryStream(1, stream, -1)); + } + @Test void execute_insert_should_return_number_of_inserted_elements() throws Exception { connection.prepareStatement("CREATE TABLE test (col INTEGER)").execute();