NumberType.java (hsqldb-2.6.0) | : | NumberType.java (hsqldb-2.6.1) | ||
---|---|---|---|---|
skipping to change at line 50 | skipping to change at line 50 | |||
import org.hsqldb.Tokens; | import org.hsqldb.Tokens; | |||
import org.hsqldb.error.Error; | import org.hsqldb.error.Error; | |||
import org.hsqldb.error.ErrorCode; | import org.hsqldb.error.ErrorCode; | |||
import org.hsqldb.lib.java.JavaSystem; | import org.hsqldb.lib.java.JavaSystem; | |||
import org.hsqldb.map.ValuePool; | import org.hsqldb.map.ValuePool; | |||
/** | /** | |||
* Type subclass for all NUMBER types.<p> | * Type subclass for all NUMBER types.<p> | |||
* | * | |||
* @author Fred Toussi (fredt@users dot sourceforge.net) | * @author Fred Toussi (fredt@users dot sourceforge.net) | |||
* @version 2.5.1 | * @version 2.6.1 | |||
* @since 1.9.0 | * @since 1.9.0 | |||
*/ | */ | |||
public final class NumberType extends Type { | public final class NumberType extends Type { | |||
static final int tinyintPrecision = 3; | static final int tinyintPrecision = 3; | |||
static final int smallintPrecision = 5; | static final int smallintPrecision = 5; | |||
static final int integerPrecision = 10; | static final int integerPrecision = 10; | |||
public static final int bigintPrecision = 19; | public static final int bigintPrecision = 19; | |||
static final int doublePrecision = 0; | static final int doublePrecision = 0; | |||
public static final int defaultNumericPrecision = 128; | public static final int defaultNumericPrecision = 128; | |||
public static final int defaultNumericScale = 32; | public static final int defaultNumericScale = 32; | |||
public static final int maxNumericPrecision = Integer.MAX_VALUE; | public static final int maxNumericPrecision = Integer.MAX_VALUE; | |||
static final int bigintSquareNumericPrecision = 40; | static final int bigintSquareNumericPrecision = 40; | |||
static final int decimalLiteralPrecision = 24; | ||||
// | // | |||
public static final int TINYINT_WIDTH = 8; | public static final int TINYINT_WIDTH = 8; | |||
public static final int SMALLINT_WIDTH = 16; | public static final int SMALLINT_WIDTH = 16; | |||
public static final int INTEGER_WIDTH = 32; | public static final int INTEGER_WIDTH = 32; | |||
public static final int BIGINT_WIDTH = 64; | public static final int BIGINT_WIDTH = 64; | |||
public static final int DOUBLE_WIDTH = 128; // nominal width | public static final int DOUBLE_WIDTH = 128; // nominal width | |||
public static final int DECIMAL_WIDTH = 256; // nominal width | public static final int DECIMAL_WIDTH = 256; // nominal width | |||
// | // | |||
skipping to change at line 795 | skipping to change at line 796 | |||
return a; | return a; | |||
case Types.SQL_NUMERIC : | case Types.SQL_NUMERIC : | |||
case Types.SQL_DECIMAL : { | case Types.SQL_DECIMAL : { | |||
BigDecimal dec = (BigDecimal) a; | BigDecimal dec = (BigDecimal) a; | |||
if (scale != dec.scale()) { | if (scale != dec.scale()) { | |||
dec = dec.setScale(scale, RoundingMode.HALF_DOWN); | dec = dec.setScale(scale, RoundingMode.HALF_DOWN); | |||
} | } | |||
int p = JavaSystem.precision(dec); | int p = precision(dec); | |||
if (p > precision) { | if (p > precision) { | |||
throw Error.error(ErrorCode.X_22003); | throw Error.error(ErrorCode.X_22003); | |||
} | } | |||
return dec; | return dec; | |||
} | } | |||
default : | default : | |||
throw Error.runtimeError(ErrorCode.U_S0500, "NumberType"); | throw Error.runtimeError(ErrorCode.U_S0500, "NumberType"); | |||
} | } | |||
skipping to change at line 826 | skipping to change at line 827 | |||
switch (typeCode) { | switch (typeCode) { | |||
case Types.SQL_NUMERIC : | case Types.SQL_NUMERIC : | |||
case Types.SQL_DECIMAL : { | case Types.SQL_DECIMAL : { | |||
BigDecimal dec = (BigDecimal) a; | BigDecimal dec = (BigDecimal) a; | |||
if (scale != dec.scale()) { | if (scale != dec.scale()) { | |||
dec = dec.setScale(scale, RoundingMode.HALF_DOWN); | dec = dec.setScale(scale, RoundingMode.HALF_DOWN); | |||
} | } | |||
if (JavaSystem.precision(dec) > precision) { | if (precision(dec) > precision) { | |||
throw Error.error(ErrorCode.X_22003); | throw Error.error(ErrorCode.X_22003); | |||
} | } | |||
return dec; | return dec; | |||
} | } | |||
default : | default : | |||
return a; | return a; | |||
} | } | |||
} | } | |||
skipping to change at line 1401 | skipping to change at line 1402 | |||
return 0; | return 0; | |||
} | } | |||
if (precision - scale >= NumberType.integerPrecision | if (precision - scale >= NumberType.integerPrecision | |||
&& o instanceof Integer) { | && o instanceof Integer) { | |||
return 0; | return 0; | |||
} | } | |||
BigDecimal dec = convertToDecimal(o); | BigDecimal dec = convertToDecimal(o); | |||
int s = dec.scale(); | int s = dec.scale(); | |||
int p = JavaSystem.precision(dec); | int p = precision(dec); | |||
if (s < 0) { | if (s < 0) { | |||
p -= s; | p -= s; | |||
s = 0; | s = 0; | |||
} | } | |||
return (precision - scale >= p - s) ? 0 | return (precision - scale >= p - s) ? 0 | |||
: dec.signum(); | : dec.signum(); | |||
} | } | |||
default : | default : | |||
skipping to change at line 2028 | skipping to change at line 2029 | |||
: -1; | : -1; | |||
} | } | |||
if (Double.isNaN(value2)) { | if (Double.isNaN(value2)) { | |||
return 1; | return 1; | |||
} | } | |||
return Double.compare(value1, value2); | return Double.compare(value1, value2); | |||
} | } | |||
static final BigDecimal BD_1 = BigDecimal.valueOf(1L); | ||||
static final BigDecimal MBD_1 = BigDecimal.valueOf(-1L); | ||||
public static int precision(BigDecimal o) { | ||||
if (o == null) { | ||||
return 0; | ||||
} | ||||
int precision; | ||||
if (o.compareTo(BD_1) < 0 && o.compareTo(MBD_1) > 0) { | ||||
precision = o.scale(); | ||||
} else { | ||||
precision = o.precision(); | ||||
} | ||||
return precision; | ||||
} | ||||
public static NumberType getNumberTypeForLiteral(BigDecimal value) { | ||||
int precision = precision(value); | ||||
int scale = value.scale(); | ||||
if (precision < decimalLiteralPrecision) { | ||||
precision = decimalLiteralPrecision; | ||||
} | ||||
return new NumberType(Types.SQL_DECIMAL, precision, scale); | ||||
} | ||||
public static NumberType getNumberType(int type, long precision, | public static NumberType getNumberType(int type, long precision, | |||
int scale) { | int scale) { | |||
switch (type) { | switch (type) { | |||
case Types.SQL_INTEGER : | case Types.SQL_INTEGER : | |||
return SQL_INTEGER; | return SQL_INTEGER; | |||
case Types.SQL_SMALLINT : | case Types.SQL_SMALLINT : | |||
return SQL_SMALLINT; | return SQL_SMALLINT; | |||
End of changes. 6 change blocks. | ||||
4 lines changed or deleted | 37 lines changed or added |