Skip to content

Commit

Permalink
Added safe reading of decimal value
Browse files Browse the repository at this point in the history
  • Loading branch information
alex268 committed Nov 3, 2024
1 parent 3f2502c commit 2703d70
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions jdbc/src/main/java/tech/ydb/jdbc/common/MappingGetters.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,15 +66,15 @@ static Getters buildGetters(Type type) {
castToShortNotSupported(clazz),
value -> safeDecimalInt(value.getDecimal()),
value -> safeDecimalLong(value.getDecimal()),
value -> value.getDecimal().toBigDecimal().floatValue(),
value -> value.getDecimal().toBigDecimal().doubleValue(),
value -> safeDecimal(value.getDecimal()).floatValue(),
value -> safeDecimal(value.getDecimal()).doubleValue(),
castToBytesNotSupported(clazz),
value -> value.getDecimal().toBigDecimal(),
value -> safeDecimal(value.getDecimal()),
castToClassNotSupported(clazz),
castToInstantNotSupported(clazz),
castToNStringNotSupported(clazz),
castToUrlNotSupported(clazz),
value -> value.getDecimal().toBigDecimal(),
value -> safeDecimal(value.getDecimal()),
castToReaderNotSupported(clazz)
);
case VOID:
Expand Down Expand Up @@ -235,6 +235,13 @@ private static ValueToBoolean valueToBoolean(PrimitiveType id) {
}
}

private static BigDecimal safeDecimal(DecimalValue value) throws SQLException {
if (value.isInf() || value.isNegativeInf() || value.isNan()) {
throw cannotConvert(value.getType(), BigDecimal.class, value.toString());
}
return value.toBigDecimal();
}

private static int safeDecimalInt(DecimalValue value) throws SQLException {
if (value.isInf() || value.isNegativeInf() || value.isNan()) {
throw cannotConvert(value.getType(), int.class, value.toString());
Expand Down

0 comments on commit 2703d70

Please sign in to comment.