[jOOQ/jOOQ#10880] Add DECFLOAT support

This includes:

- Support integer values as data (without exponent)
- Support DefaultConverterProvider conversions
- Support DataType.hasPrecision()
- Add 1E0 and 0E0 as TRUE_VALUES and FALSE_VALUES
This commit is contained in:
Lukas Eder 2024-08-14 12:26:39 +02:00
parent 044cebb85b
commit c3d66506cf
3 changed files with 22 additions and 2 deletions

View File

@ -212,8 +212,13 @@ public final class Decfloat extends Number implements Data {
i = data.indexOf("e");
try {
coefficient = new BigDecimal(data.substring(0, i)).stripTrailingZeros();
exponent = Integer.parseInt(data.substring(i + 1));
if (i == -1) {
coefficient = new BigDecimal(data).stripTrailingZeros();
}
else {
coefficient = new BigDecimal(data.substring(0, i)).stripTrailingZeros();
exponent = Integer.parseInt(data.substring(i + 1));
}
}
// [#10880] If we cannot represent the value internally, then we'll just work with data

View File

@ -418,6 +418,7 @@ implements
return tType == BigInteger.class
|| tType == BigDecimal.class
|| tType == Decfloat.class
|| tType == Timestamp.class
|| tType == Time.class
|| tType == LocalDateTime.class
@ -532,6 +533,8 @@ implements
return Types.BIGINT;
else if (tType == BigDecimal.class)
return Types.DECIMAL;
else if (tType == Decfloat.class)
return Types.FLOAT;
else if (tType == Byte.class)
return Types.TINYINT;
else if (tType == byte[].class)

View File

@ -41,6 +41,7 @@ import static java.time.temporal.ChronoField.INSTANT_SECONDS;
import static java.time.temporal.ChronoField.MILLI_OF_DAY;
import static java.time.temporal.ChronoField.MILLI_OF_SECOND;
import static org.jooq.ContextConverter.scoped;
import static org.jooq.Decfloat.decfloat;
import static org.jooq.impl.Internal.arrayType;
import static org.jooq.impl.Internal.converterContext;
import static org.jooq.impl.Tools.configuration;
@ -100,6 +101,7 @@ import org.jooq.Converter;
import org.jooq.ConverterContext;
import org.jooq.ConverterProvider;
import org.jooq.Converters.UnknownType;
import org.jooq.Decfloat;
import org.jooq.EnumType;
import org.jooq.Field;
import org.jooq.JSON;
@ -177,6 +179,8 @@ final class Convert {
trueValues.add("1");
trueValues.add("1.0");
trueValues.add("1E0");
trueValues.add("1e0");
trueValues.add("y");
trueValues.add("Y");
trueValues.add("yes");
@ -192,6 +196,8 @@ final class Convert {
falseValues.add("0");
falseValues.add("0.0");
falseValues.add("0E0");
falseValues.add("0e0");
falseValues.add("n");
falseValues.add("N");
falseValues.add("no");
@ -992,6 +998,12 @@ final class Convert {
return null;
}
}
else if (toClass == Decfloat.class) {
if (wrapperFrom == Boolean.class)
return (U) (((Boolean) from) ? decfloat("1") : decfloat("0"));
return (U) decfloat(from.toString());
}
else if (toClass == Year.class) {
if (Number.class.isAssignableFrom(wrapperFrom))
return (U) Year.of((((Number) from).intValue()));