Skip to content

Commit

Permalink
Fix fetching varint values (#59)
Browse files Browse the repository at this point in the history
* Fix fetching varint values
* Use getBigInteger() and getVarint() for varint type
  • Loading branch information
kornilova203 authored May 23, 2024
1 parent 1d49d7a commit 0c48a81
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -686,8 +686,9 @@ public Object getObject(final int columnIndex) throws SQLException {
case ASCII:
case TEXT:
return this.currentRow.getString(columnIndex - 1);
case INT:
case VARINT:
return this.currentRow.getVarint(columnIndex - 1);
case INT:
return this.currentRow.getInt(columnIndex - 1);
case SMALLINT:
return this.currentRow.getShort(columnIndex - 1);
Expand Down Expand Up @@ -734,8 +735,9 @@ public Object getObject(final String columnLabel) throws SQLException {
case ASCII:
case TEXT:
return this.currentRow.getString(columnLabel);
case INT:
case VARINT:
return this.currentRow.getVarint(columnLabel);
case INT:
return this.currentRow.getInt(columnLabel);
case SMALLINT:
return this.currentRow.getShort(columnLabel);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -981,8 +981,9 @@ public Object getObject(final int columnIndex) throws SQLException {
case ASCII:
case TEXT:
return this.currentRow.getString(columnIndex - 1);
case INT:
case VARINT:
return this.currentRow.getBigInteger(columnIndex - 1);
case INT:
return this.currentRow.getInt(columnIndex - 1);
case SMALLINT:
return this.currentRow.getShort(columnIndex - 1);
Expand Down Expand Up @@ -1121,8 +1122,9 @@ public Object getObject(final String columnLabel) throws SQLException {
case ASCII:
case TEXT:
return this.currentRow.getString(columnLabel);
case INT:
case VARINT:
return this.currentRow.getBigInteger(columnLabel);
case INT:
return this.currentRow.getInt(columnLabel);
case SMALLINT:
return this.currentRow.getShort(columnLabel);
Expand Down
12 changes: 12 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 @@ -18,6 +18,7 @@
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;

import java.math.BigInteger;
import java.nio.charset.StandardCharsets;
import java.sql.ResultSet;
import java.sql.SQLSyntaxErrorException;
Expand Down Expand Up @@ -131,6 +132,17 @@ void givenResultSetWithRows_whenGetAsciiStream_returnExpectedValue() throws Exce
assertArrayEquals("testValueAscii".getBytes(StandardCharsets.US_ASCII), byteArray);
}

@Test
void givenVarintValue_whenFetching_returnExpectedValue() throws Exception {
final String cql = "select (varint) 1 from system.local";
final Statement statement = sqlConnection.createStatement();
final ResultSet rs = statement.executeQuery(cql);
assertTrue(rs.next());
Object result = rs.getObject(1);
assertNotNull(result);
assertEquals(BigInteger.valueOf(1), result);
}

@Test
void givenResultSetWithRows_whenGetCharacterStream_returnExpectedValue() throws Exception {
final String cql = "SELECT col_blob FROM tbl_test_blobs WHERE keyname = 'key1'";
Expand Down

0 comments on commit 0c48a81

Please sign in to comment.