提交 949f3afc authored 作者: Noel Grandin's avatar Noel Grandin

#537: Include the COLUMN name in message "Numeric value out of range"

上级 75e2714c
...@@ -21,6 +21,8 @@ Change Log ...@@ -21,6 +21,8 @@ Change Log
<h2>Next Version (unreleased)</h2> <h2>Next Version (unreleased)</h2>
<ul> <ul>
<li>Issue #537: Include the COLUMN name in message "Numeric value out of range"
</li>
<li>Issue #600: ROW_NUMBER() behaviour change in H2 1.4.195 <li>Issue #600: ROW_NUMBER() behaviour change in H2 1.4.195
</li> </li>
<li>Fix a bunch of race conditions found by vmlens.com, thank you to vmlens for giving us a license. <li>Fix a bunch of race conditions found by vmlens.com, thank you to vmlens for giving us a license.
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
08000=Error opening database: {0} 08000=Error opening database: {0}
21S02=Column count does not match 21S02=Column count does not match
22001=Value too long for column {0}: {1} 22001=Value too long for column {0}: {1}
22003=Numeric value out of range: {0} 22003=Numeric value out of range: {0} {1}
22007=Cannot parse {0} constant {1} 22007=Cannot parse {0} constant {1}
22012=Division by zero: {0} 22012=Division by zero: {0}
22018=Data conversion error converting {0} 22018=Data conversion error converting {0}
......
...@@ -106,6 +106,12 @@ public class ErrorCode { ...@@ -106,6 +106,12 @@ public class ErrorCode {
*/ */
public static final int NUMERIC_VALUE_OUT_OF_RANGE_1 = 22003; public static final int NUMERIC_VALUE_OUT_OF_RANGE_1 = 22003;
/**
* The error with code <code>22004</code> is thrown when a value is out of
* range when converting to another column's data type.
*/
public static final int NUMERIC_VALUE_OUT_OF_RANGE_2 = 22004;
/** /**
* The error with code <code>22007</code> is thrown when * The error with code <code>22007</code> is thrown when
* a text can not be converted to a date, time, or timestamp constant. * a text can not be converted to a date, time, or timestamp constant.
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
21S02=Počet sloupců nesouhlasí 21S02=Počet sloupců nesouhlasí
22001=Příliš dlouhá hodnota pro sloupec {0}: {1} 22001=Příliš dlouhá hodnota pro sloupec {0}: {1}
22003=Číselná hodnota je mimo rozsah: {0} 22003=Číselná hodnota je mimo rozsah: {0}
22004=Numeric value out of range: {0} in column {1}
22007=Nelze zpracovat konstantu {0} {1} 22007=Nelze zpracovat konstantu {0} {1}
22012=Dělení nulou: {0} 22012=Dělení nulou: {0}
22018=Chyba při převodu dat {0} 22018=Chyba při převodu dat {0}
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
21S02=Anzahl der Felder stimmt nicht überein 21S02=Anzahl der Felder stimmt nicht überein
22001=Wert zu gross / lang für Feld {0}: {1} 22001=Wert zu gross / lang für Feld {0}: {1}
22003=Zahlenwert ausserhalb des Bereichs: {0} 22003=Zahlenwert ausserhalb des Bereichs: {0}
22004=Numeric value out of range: {0} in column {1}
22007=Kann {0} {1} nicht umwandeln 22007=Kann {0} {1} nicht umwandeln
22012=Division durch 0: {0} 22012=Division durch 0: {0}
22018=Datenumwandlungsfehler beim Umwandeln von {0} 22018=Datenumwandlungsfehler beim Umwandeln von {0}
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
21S02=Column count does not match 21S02=Column count does not match
22001=Value too long for column {0}: {1} 22001=Value too long for column {0}: {1}
22003=Numeric value out of range: {0} 22003=Numeric value out of range: {0}
22004=Numeric value out of range: {0} in column {1}
22007=Cannot parse {0} constant {1} 22007=Cannot parse {0} constant {1}
22012=Division by zero: {0} 22012=Division by zero: {0}
22018=Data conversion error converting {0} 22018=Data conversion error converting {0}
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
21S02=La cantidad de columnas no coincide 21S02=La cantidad de columnas no coincide
22001=Valor demasiado largo para la columna {0}: {1} 22001=Valor demasiado largo para la columna {0}: {1}
22003=Valor numerico fuera de rango: {0} 22003=Valor numerico fuera de rango: {0}
22004=Numeric value out of range: {0} in column {1}
22007=Imposible interpretar la constante {0} {1} 22007=Imposible interpretar la constante {0} {1}
22012=División por cero: {0} 22012=División por cero: {0}
22018=Conversión de datos fallida, convirtiendo {0} 22018=Conversión de datos fallida, convirtiendo {0}
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
21S02=列番号が一致しません 21S02=列番号が一致しません
22001=列 {0} の値が長過ぎます: {1} 22001=列 {0} の値が長過ぎます: {1}
22003=範囲外の数値です: {0} 22003=範囲外の数値です: {0}
22004=Numeric value out of range: {0} in column {1}
22007={0} 定数 {1} を解析できません 22007={0} 定数 {1} を解析できません
22012=ゼロで除算しました: {0} 22012=ゼロで除算しました: {0}
22018=データ変換中にエラーが発生しました {0} 22018=データ変換中にエラーが発生しました {0}
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
21S02=Niezgodna ilość kolumn 21S02=Niezgodna ilość kolumn
22001=Wartość za długa dla kolumny {0}: {1} 22001=Wartość za długa dla kolumny {0}: {1}
22003=Wartość numeryczna poza zakresem: {0} 22003=Wartość numeryczna poza zakresem: {0}
22004=Numeric value out of range: {0} in column {1}
22007=Nie można odczytać {0} jako {1} 22007=Nie można odczytać {0} jako {1}
22012=Dzielenie przez zero: {0} 22012=Dzielenie przez zero: {0}
22018=Błąd konwersji danych {0} 22018=Błąd konwersji danych {0}
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
21S02=A quantidade de colunas não corresponde 21S02=A quantidade de colunas não corresponde
22001=Valor muito longo para a coluna {0}: {1} 22001=Valor muito longo para a coluna {0}: {1}
22003=Valor númerico não esta dentro do limite: {0} 22003=Valor númerico não esta dentro do limite: {0}
22004=Numeric value out of range: {0} in column {1}
22007=Não é possível converter {1} para {0} 22007=Não é possível converter {1} para {0}
22012=Divisão por zero: {0} 22012=Divisão por zero: {0}
22018=Erro na conversão de dado, convertendo {0} 22018=Erro na conversão de dado, convertendo {0}
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
21S02=Неверное количество столбцов 21S02=Неверное количество столбцов
22001=Значение слишком длинное для поля {0}: {1} 22001=Значение слишком длинное для поля {0}: {1}
22003=Численное значение вне допустимого диапазона: {0} 22003=Численное значение вне допустимого диапазона: {0}
22004=Numeric value out of range: {0} in column {1}
22007=Невозможно преобразование строки {1} в тип {0} 22007=Невозможно преобразование строки {1} в тип {0}
22012=Деление на ноль: {0} 22012=Деление на ноль: {0}
22018=Ошибка преобразования данных при конвертации {0} 22018=Ошибка преобразования данных при конвертации {0}
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
21S02=Počet stĺpcov sa nezhoduje 21S02=Počet stĺpcov sa nezhoduje
22001=Hodnota je príliš dlhá pre stĺpec {0}: {1} 22001=Hodnota je príliš dlhá pre stĺpec {0}: {1}
22003=Číselná hodnota mimo rozsah: {0} 22003=Číselná hodnota mimo rozsah: {0}
22004=Numeric value out of range: {0} in column {1}
22007=Nemožem rozobrať {0} konštantu {1} 22007=Nemožem rozobrať {0} konštantu {1}
22012=Delenie nulou: {0} 22012=Delenie nulou: {0}
22018=Chyba konverzie dát pre {0} 22018=Chyba konverzie dát pre {0}
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
21S02=字段数目不匹配 21S02=字段数目不匹配
22001=字段 {0}数值太大: {1} 22001=字段 {0}数值太大: {1}
22003=数值超出范围: {0} 22003=数值超出范围: {0}
22004=Numeric value out of range: {0} in column {1}
22007=不能解析字段 {0} 的数值 :{1} 22007=不能解析字段 {0} 的数值 :{1}
22012=除数为零: {0} 22012=除数为零: {0}
22018=转换数据{0}期间出现转换错误 22018=转换数据{0}期间出现转换错误
......
...@@ -608,18 +608,18 @@ public abstract class Value { ...@@ -608,18 +608,18 @@ public abstract class Value {
case BOOLEAN: case BOOLEAN:
return ValueByte.get(getBoolean().booleanValue() ? (byte) 1 : (byte) 0); return ValueByte.get(getBoolean().booleanValue() ? (byte) 1 : (byte) 0);
case SHORT: case SHORT:
return ValueByte.get(convertToByte(getShort())); return ValueByte.get(convertToByte(getShort(), column));
case ENUM: case ENUM:
case INT: case INT:
return ValueByte.get(convertToByte(getInt())); return ValueByte.get(convertToByte(getInt(), column));
case LONG: case LONG:
return ValueByte.get(convertToByte(getLong())); return ValueByte.get(convertToByte(getLong(), column));
case DECIMAL: case DECIMAL:
return ValueByte.get(convertToByte(convertToLong(getBigDecimal()))); return ValueByte.get(convertToByte(convertToLong(getBigDecimal(), column), column));
case DOUBLE: case DOUBLE:
return ValueByte.get(convertToByte(convertToLong(getDouble()))); return ValueByte.get(convertToByte(convertToLong(getDouble(), column), column));
case FLOAT: case FLOAT:
return ValueByte.get(convertToByte(convertToLong(getFloat()))); return ValueByte.get(convertToByte(convertToLong(getFloat(), column), column));
case BYTES: case BYTES:
return ValueByte.get((byte) Integer.parseInt(getString(), 16)); return ValueByte.get((byte) Integer.parseInt(getString(), 16));
case TIMESTAMP_TZ: case TIMESTAMP_TZ:
...@@ -636,15 +636,15 @@ public abstract class Value { ...@@ -636,15 +636,15 @@ public abstract class Value {
return ValueShort.get(getByte()); return ValueShort.get(getByte());
case ENUM: case ENUM:
case INT: case INT:
return ValueShort.get(convertToShort(getInt())); return ValueShort.get(convertToShort(getInt(), column));
case LONG: case LONG:
return ValueShort.get(convertToShort(getLong())); return ValueShort.get(convertToShort(getLong(), column));
case DECIMAL: case DECIMAL:
return ValueShort.get(convertToShort(convertToLong(getBigDecimal()))); return ValueShort.get(convertToShort(convertToLong(getBigDecimal(), column), column));
case DOUBLE: case DOUBLE:
return ValueShort.get(convertToShort(convertToLong(getDouble()))); return ValueShort.get(convertToShort(convertToLong(getDouble(), column), column));
case FLOAT: case FLOAT:
return ValueShort.get(convertToShort(convertToLong(getFloat()))); return ValueShort.get(convertToShort(convertToLong(getFloat(), column), column));
case BYTES: case BYTES:
return ValueShort.get((short) Integer.parseInt(getString(), 16)); return ValueShort.get((short) Integer.parseInt(getString(), 16));
case TIMESTAMP_TZ: case TIMESTAMP_TZ:
...@@ -664,13 +664,13 @@ public abstract class Value { ...@@ -664,13 +664,13 @@ public abstract class Value {
case SHORT: case SHORT:
return ValueInt.get(getShort()); return ValueInt.get(getShort());
case LONG: case LONG:
return ValueInt.get(convertToInt(getLong())); return ValueInt.get(convertToInt(getLong(), column));
case DECIMAL: case DECIMAL:
return ValueInt.get(convertToInt(convertToLong(getBigDecimal()))); return ValueInt.get(convertToInt(convertToLong(getBigDecimal(), column), column));
case DOUBLE: case DOUBLE:
return ValueInt.get(convertToInt(convertToLong(getDouble()))); return ValueInt.get(convertToInt(convertToLong(getDouble(), column), column));
case FLOAT: case FLOAT:
return ValueInt.get(convertToInt(convertToLong(getFloat()))); return ValueInt.get(convertToInt(convertToLong(getFloat(), column), column));
case BYTES: case BYTES:
return ValueInt.get((int) Long.parseLong(getString(), 16)); return ValueInt.get((int) Long.parseLong(getString(), 16));
case TIMESTAMP_TZ: case TIMESTAMP_TZ:
...@@ -691,11 +691,11 @@ public abstract class Value { ...@@ -691,11 +691,11 @@ public abstract class Value {
case INT: case INT:
return ValueLong.get(getInt()); return ValueLong.get(getInt());
case DECIMAL: case DECIMAL:
return ValueLong.get(convertToLong(getBigDecimal())); return ValueLong.get(convertToLong(getBigDecimal(), column));
case DOUBLE: case DOUBLE:
return ValueLong.get(convertToLong(getDouble())); return ValueLong.get(convertToLong(getDouble(), column));
case FLOAT: case FLOAT:
return ValueLong.get(convertToLong(getFloat())); return ValueLong.get(convertToLong(getFloat(), column));
case BYTES: { case BYTES: {
// parseLong doesn't work for ffffffffffffffff // parseLong doesn't work for ffffffffffffffff
byte[] d = getBytes(); byte[] d = getBytes();
...@@ -1131,45 +1131,45 @@ public abstract class Value { ...@@ -1131,45 +1131,45 @@ public abstract class Value {
return this; return this;
} }
private static byte convertToByte(long x) { private static byte convertToByte(long x, Column col) {
if (x > Byte.MAX_VALUE || x < Byte.MIN_VALUE) { if (x > Byte.MAX_VALUE || x < Byte.MIN_VALUE) {
throw DbException.get( throw DbException.get(
ErrorCode.NUMERIC_VALUE_OUT_OF_RANGE_1, Long.toString(x)); ErrorCode.NUMERIC_VALUE_OUT_OF_RANGE_2, Long.toString(x), col.getName());
} }
return (byte) x; return (byte) x;
} }
private static short convertToShort(long x) { private static short convertToShort(long x, Column col) {
if (x > Short.MAX_VALUE || x < Short.MIN_VALUE) { if (x > Short.MAX_VALUE || x < Short.MIN_VALUE) {
throw DbException.get( throw DbException.get(
ErrorCode.NUMERIC_VALUE_OUT_OF_RANGE_1, Long.toString(x)); ErrorCode.NUMERIC_VALUE_OUT_OF_RANGE_2, Long.toString(x), col.getName());
} }
return (short) x; return (short) x;
} }
private static int convertToInt(long x) { private static int convertToInt(long x, Column col) {
if (x > Integer.MAX_VALUE || x < Integer.MIN_VALUE) { if (x > Integer.MAX_VALUE || x < Integer.MIN_VALUE) {
throw DbException.get( throw DbException.get(
ErrorCode.NUMERIC_VALUE_OUT_OF_RANGE_1, Long.toString(x)); ErrorCode.NUMERIC_VALUE_OUT_OF_RANGE_2, Long.toString(x), col.getName());
} }
return (int) x; return (int) x;
} }
private static long convertToLong(double x) { private static long convertToLong(double x, Column col) {
if (x > Long.MAX_VALUE || x < Long.MIN_VALUE) { if (x > Long.MAX_VALUE || x < Long.MIN_VALUE) {
// TODO document that +Infinity, -Infinity throw an exception and // TODO document that +Infinity, -Infinity throw an exception and
// NaN returns 0 // NaN returns 0
throw DbException.get( throw DbException.get(
ErrorCode.NUMERIC_VALUE_OUT_OF_RANGE_1, Double.toString(x)); ErrorCode.NUMERIC_VALUE_OUT_OF_RANGE_2, Double.toString(x), col.getName());
} }
return Math.round(x); return Math.round(x);
} }
private static long convertToLong(BigDecimal x) { private static long convertToLong(BigDecimal x, Column col) {
if (x.compareTo(MAX_LONG_DECIMAL) > 0 || if (x.compareTo(MAX_LONG_DECIMAL) > 0 ||
x.compareTo(Value.MIN_LONG_DECIMAL) < 0) { x.compareTo(Value.MIN_LONG_DECIMAL) < 0) {
throw DbException.get( throw DbException.get(
ErrorCode.NUMERIC_VALUE_OUT_OF_RANGE_1, x.toString()); ErrorCode.NUMERIC_VALUE_OUT_OF_RANGE_2, x.toString(), col.getName());
} }
return x.setScale(0, BigDecimal.ROUND_HALF_UP).longValue(); return x.setScale(0, BigDecimal.ROUND_HALF_UP).longValue();
} }
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论