mirror of
https://github.com/aljazceru/turso.git
synced 2026-01-11 04:04:20 +01:00
feat(jdbc): test setBinaryStream method in JDBC4PreparedStatementTest
This commit is contained in:
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user