Skip to content

Commit 44405d4

Browse files
authored
Fix CassandraMetadataResultSet to return JDBC-specificied defaults if underlying data is NULL - fixes #10 (#12)
1 parent 9842662 commit 44405d4

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

src/main/java/com/ing/data/cassandra/jdbc/MetadataRow.java

+3
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,9 @@ public short getShort(final String name) {
180180
* @throws NumberFormatException if the value is not a parsable {@code int} value.
181181
*/
182182
public int getInt(final int i) {
183+
if (isNull(i)) {
184+
return 0;
185+
}
183186
return Integer.parseInt(this.entries.get(i));
184187
}
185188

src/test/java/com/ing/data/cassandra/jdbc/JdbcRegressionUnitTest.java

+26
Original file line numberDiff line numberDiff line change
@@ -871,4 +871,30 @@ void testOriginalIssue24() throws Exception {
871871
statementSelect.close();
872872
}
873873

874+
@Test
875+
void testIngIssue10() throws Exception {
876+
final DatabaseMetaData md = sqlConnection.getMetaData();
877+
878+
final String COLUMN = "keyname";
879+
880+
ResultSet result;
881+
882+
result = md.getColumns(sqlConnection.getCatalog(), KEYSPACE, TABLE, null);
883+
assertTrue(result.next());
884+
assertEquals(TABLE, result.getString("TABLE_NAME"));
885+
// Check column names and types.
886+
assertEquals(COLUMN, result.getString("COLUMN_NAME"));
887+
assertEquals(false, result.wasNull());
888+
889+
// The underlying value of the DECIMAL_DIGITS field is null, so
890+
// getInt should return 0, but wasNull should be true
891+
assertEquals(0, result.getInt("DECIMAL_DIGITS"));
892+
assertEquals(true, result.wasNull());
893+
894+
// Get another field to ensure wasNull is reset to false
895+
assertEquals(Types.VARCHAR, result.getInt("DATA_TYPE"));
896+
assertEquals(false, result.wasNull());
897+
898+
result.close();
899+
}
874900
}

0 commit comments

Comments
 (0)