mirror of
https://github.com/aljazceru/turso.git
synced 2025-12-26 12:34:22 +01:00
feat(java): implement getCharacterStream() in JDBC4ResultSet
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package tech.turso.jdbc4;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.io.StringReader;
|
||||
import java.io.Reader;
|
||||
import java.math.BigDecimal;
|
||||
import java.math.RoundingMode;
|
||||
@@ -380,13 +381,17 @@ public final class JDBC4ResultSet implements ResultSet, ResultSetMetaData {
|
||||
@Override
|
||||
@SkipNullableCheck
|
||||
public Reader getCharacterStream(int columnIndex) throws SQLException {
|
||||
throw new UnsupportedOperationException("not implemented");
|
||||
final Object result = resultSet.get(columnIndex);
|
||||
if (result == null) {
|
||||
return null;
|
||||
}
|
||||
return wrapTypeConversion(() -> new StringReader((String) result));
|
||||
}
|
||||
|
||||
@Override
|
||||
@SkipNullableCheck
|
||||
public Reader getCharacterStream(String columnLabel) throws SQLException {
|
||||
throw new UnsupportedOperationException("not implemented");
|
||||
return getCharacterStream(findColumn(columnLabel));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -7,6 +7,7 @@ import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
import java.io.Reader;
|
||||
import java.math.BigDecimal;
|
||||
import java.math.RoundingMode;
|
||||
import java.sql.ResultSet;
|
||||
@@ -589,4 +590,45 @@ class JDBC4ResultSetTest {
|
||||
assertEquals(1, resultSet.findColumn("user name"));
|
||||
assertEquals(2, resultSet.findColumn("user-id"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void test_getCharacterStream() throws Exception {
|
||||
stmt.executeUpdate("CREATE TABLE test_char_stream (text_col TEXT);");
|
||||
stmt.executeUpdate("INSERT INTO test_char_stream (text_col) VALUES ('Hello World');");
|
||||
|
||||
ResultSet resultSet = stmt.executeQuery("SELECT * FROM test_char_stream");
|
||||
assertTrue(resultSet.next());
|
||||
|
||||
Reader reader = resultSet.getCharacterStream(1);
|
||||
char[] buffer = new char[11];
|
||||
int charsRead = reader.read(buffer);
|
||||
|
||||
assertEquals(11, charsRead);
|
||||
assertEquals("Hello World", new String(buffer));
|
||||
}
|
||||
|
||||
@Test
|
||||
void test_getCharacterStream_with_columnLabel() throws Exception {
|
||||
stmt.executeUpdate("CREATE TABLE test_char_stream (text_col TEXT);");
|
||||
stmt.executeUpdate("INSERT INTO test_char_stream (text_col) VALUES ('Test Data');");
|
||||
|
||||
ResultSet resultSet = stmt.executeQuery("SELECT * FROM test_char_stream");
|
||||
assertTrue(resultSet.next());
|
||||
|
||||
Reader reader = resultSet.getCharacterStream("text_col");
|
||||
char[] buffer = new char[9];
|
||||
reader.read(buffer);
|
||||
|
||||
assertEquals("Test Data", new String(buffer));
|
||||
}
|
||||
|
||||
@Test
|
||||
void test_getCharacterStream_returns_null_on_null() throws Exception {
|
||||
stmt.executeUpdate("CREATE TABLE test_null (text_col TEXT);");
|
||||
stmt.executeUpdate("INSERT INTO test_null (text_col) VALUES (NULL);");
|
||||
|
||||
ResultSet resultSet = stmt.executeQuery("SELECT * FROM test_null");
|
||||
assertTrue(resultSet.next());
|
||||
assertNull(resultSet.getCharacterStream(1));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user