Skip to content

Commit

Permalink
Fix fetching null values (#57)
Browse files Browse the repository at this point in the history
* Fix fetching null values
* Add isNull check to getObject(String)
  • Loading branch information
kornilova203 authored May 23, 2024
1 parent 35e47fe commit 1d49d7a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -886,6 +886,10 @@ public Object getObject(final int columnIndex) throws SQLException {
final DataType cqlDataType = getCqlDataType(columnIndex);
final DataTypeEnum dataType = fromDataType(cqlDataType);

if (currentRow.isNull(columnIndex - 1)) {
return null;
}

// User-defined types
if (isCqlType(columnIndex, DataTypeEnum.UDT)) {
return this.currentRow.getUdtValue(columnIndex - 1);
Expand Down Expand Up @@ -1022,6 +1026,10 @@ public Object getObject(final String columnLabel) throws SQLException {
final DataType cqlDataType = getCqlDataType(columnLabel);
final DataTypeEnum dataType = fromDataType(cqlDataType);

if (currentRow.isNull(columnLabel)) {
return null;
}

// User-defined types
if (isCqlType(columnLabel, DataTypeEnum.UDT)) {
return this.currentRow.getUdtValue(columnLabel);
Expand Down
10 changes: 10 additions & 0 deletions src/test/java/com/ing/data/cassandra/jdbc/ResultSetUnitTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
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 static org.mockito.ArgumentMatchers.anyString;
Expand Down Expand Up @@ -140,4 +141,13 @@ void givenResultSetWithRows_whenGetCharacterStream_returnExpectedValue() throws
assertArrayEquals("testValueAsClobInUtf8 with accents: Äîéè".getBytes(StandardCharsets.UTF_8), byteArray);
}

@Test
void givenNullValue_whenFetchingValue_returnNull() throws Exception {
final String cql = "select (int) null from system.local";
final Statement statement = sqlConnection.createStatement();
final ResultSet rs = statement.executeQuery(cql);
assertTrue(rs.next());
Object result = rs.getObject(1);
assertNull(result);
}
}

0 comments on commit 1d49d7a

Please sign in to comment.