提交 edaa8645 authored 作者: Evgenij Ryazanov's avatar Evgenij Ryazanov

Remove precision parameter of Value.convertTo()

上级 a9030639
...@@ -21,7 +21,6 @@ import org.h2.message.DbException; ...@@ -21,7 +21,6 @@ import org.h2.message.DbException;
import org.h2.table.Column; import org.h2.table.Column;
import org.h2.table.ColumnResolver; import org.h2.table.ColumnResolver;
import org.h2.table.TableFilter; import org.h2.table.TableFilter;
import org.h2.util.MathUtils;
import org.h2.value.Value; import org.h2.value.Value;
import org.h2.value.ValueBoolean; import org.h2.value.ValueBoolean;
import org.h2.value.ValueGeometry; import org.h2.value.ValueGeometry;
...@@ -234,8 +233,8 @@ public class Comparison extends Condition { ...@@ -234,8 +233,8 @@ public class Comparison extends Condition {
if (constType != resType) { if (constType != resType) {
Column column = ((ExpressionColumn) left).getColumn(); Column column = ((ExpressionColumn) left).getColumn();
right = ValueExpression.get(r.convertTo(resType, right = ValueExpression.get(r.convertTo(resType,
MathUtils.convertLongToInt(left.getType().getPrecision()), session.getDatabase().getMode(),
session.getDatabase().getMode(), column, column.getType().getExtTypeInfo())); column, column.getType().getExtTypeInfo()));
} }
} else if (right instanceof Parameter) { } else if (right instanceof Parameter) {
((Parameter) right).setColumn( ((Parameter) right).setColumn(
......
...@@ -902,7 +902,7 @@ public class Function extends Expression implements FunctionCall { ...@@ -902,7 +902,7 @@ public class Function extends Expression implements FunctionCall {
case CONVERT: { case CONVERT: {
Mode mode = database.getMode(); Mode mode = database.getMode();
TypeInfo type = this.type; TypeInfo type = this.type;
v0 = v0.convertTo(dataType, MathUtils.convertLongToInt(type.getPrecision()), mode, null, extTypeInfo); v0 = v0.convertTo(dataType, mode, null, extTypeInfo);
v0 = v0.convertScale(mode.convertOnlyToSmallerScale, type.getScale()); v0 = v0.convertScale(mode.convertOnlyToSmallerScale, type.getScale());
v0 = v0.convertPrecision(type.getPrecision(), false); v0 = v0.convertPrecision(type.getPrecision(), false);
result = v0; result = v0;
......
...@@ -290,7 +290,7 @@ public final class MVSecondaryIndex extends BaseIndex implements MVIndex { ...@@ -290,7 +290,7 @@ public final class MVSecondaryIndex extends BaseIndex implements MVIndex {
Value v = r.getValue(idx); Value v = r.getValue(idx);
if (v != null) { if (v != null) {
TypeInfo type = c.getType(); TypeInfo type = c.getType();
array[i] = v.convertTo(type.getValueType(), -1, database.getMode(), null, type.getExtTypeInfo()); array[i] = v.convertTo(type.getValueType(), database.getMode(), null, type.getExtTypeInfo());
} }
} }
array[keyColumns - 1] = key != null ? key : ValueLong.get(r.getKey()); array[keyColumns - 1] = key != null ? key : ValueLong.get(r.getKey());
......
...@@ -164,8 +164,7 @@ public class Column { ...@@ -164,8 +164,7 @@ public class Column {
*/ */
public Value convert(Value v, Mode mode) { public Value convert(Value v, Mode mode) {
try { try {
return v.convertTo(type.getValueType(), MathUtils.convertLongToInt(type.getPrecision()), mode, this, return v.convertTo(type.getValueType(), mode, this, type.getExtTypeInfo());
type.getExtTypeInfo());
} catch (DbException e) { } catch (DbException e) {
if (e.getErrorCode() == ErrorCode.DATA_CONVERSION_ERROR_1) { if (e.getErrorCode() == ErrorCode.DATA_CONVERSION_ERROR_1) {
String target = (table == null ? "" : table.getName() + ": ") + String target = (table == null ? "" : table.getName() + ": ") +
......
...@@ -709,7 +709,7 @@ public abstract class Value extends VersionedValue { ...@@ -709,7 +709,7 @@ public abstract class Value extends VersionedValue {
public final Value convertToEnum(ExtTypeInfo enumerators) { public final Value convertToEnum(ExtTypeInfo enumerators) {
// Use -1 to indicate "default behaviour" where value conversion should not // Use -1 to indicate "default behaviour" where value conversion should not
// depend on any datatype precision. // depend on any datatype precision.
return convertTo(ENUM, -1, null, null, enumerators); return convertTo(ENUM, null, null, enumerators);
} }
/** /**
...@@ -720,7 +720,7 @@ public abstract class Value extends VersionedValue { ...@@ -720,7 +720,7 @@ public abstract class Value extends VersionedValue {
* @return the converted value * @return the converted value
*/ */
public final Value convertTo(int targetType, Mode mode) { public final Value convertTo(int targetType, Mode mode) {
return convertTo(targetType, -1, mode, null, null); return convertTo(targetType, mode, null, null);
} }
/** /**
...@@ -732,22 +732,19 @@ public abstract class Value extends VersionedValue { ...@@ -732,22 +732,19 @@ public abstract class Value extends VersionedValue {
* @return the converted value * @return the converted value
*/ */
public Value convertTo(TypeInfo targetType, Mode mode, Object column) { public Value convertTo(TypeInfo targetType, Mode mode, Object column) {
return convertTo(targetType.getValueType(), -1, mode, column, targetType.getExtTypeInfo()); return convertTo(targetType.getValueType(), mode, column, targetType.getExtTypeInfo());
} }
/** /**
* Convert a value to the specified type. * Convert a value to the specified type.
* *
* @param targetType the type of the returned value * @param targetType the type of the returned value
* @param precision the precision of the column to convert this value to.
* The special constant <code>-1</code> is used to indicate that
* the precision plays no role when converting the value
* @param mode the conversion mode * @param mode the conversion mode
* @param column the column (if any), used for to improve the error message if conversion fails * @param column the column (if any), used for to improve the error message if conversion fails
* @param extTypeInfo the extended data type information, or null * @param extTypeInfo the extended data type information, or null
* @return the converted value * @return the converted value
*/ */
public Value convertTo(int targetType, int precision, Mode mode, Object column, ExtTypeInfo extTypeInfo) { public Value convertTo(int targetType, Mode mode, Object column, ExtTypeInfo extTypeInfo) {
// converting NULL is done in ValueNull // converting NULL is done in ValueNull
// converting BLOB to CLOB and vice versa is done in ValueLob // converting BLOB to CLOB and vice versa is done in ValueLob
if (getValueType() == targetType) { if (getValueType() == targetType) {
......
...@@ -137,11 +137,11 @@ public class ValueEnumBase extends Value { ...@@ -137,11 +137,11 @@ public class ValueEnumBase extends Value {
} }
@Override @Override
public Value convertTo(int targetType, int precision, Mode mode, Object column, ExtTypeInfo extTypeInfo) { public Value convertTo(int targetType, Mode mode, Object column, ExtTypeInfo extTypeInfo) {
if (targetType == Value.ENUM) { if (targetType == Value.ENUM) {
return extTypeInfo.cast(this); return extTypeInfo.cast(this);
} }
return super.convertTo(targetType, precision, mode, column, extTypeInfo); return super.convertTo(targetType, mode, column, extTypeInfo);
} }
} }
...@@ -346,13 +346,13 @@ public class ValueGeometry extends Value { ...@@ -346,13 +346,13 @@ public class ValueGeometry extends Value {
} }
@Override @Override
public Value convertTo(int targetType, int precision, Mode mode, Object column, ExtTypeInfo extTypeInfo) { public Value convertTo(int targetType, Mode mode, Object column, ExtTypeInfo extTypeInfo) {
if (targetType == Value.GEOMETRY) { if (targetType == Value.GEOMETRY) {
return extTypeInfo != null ? extTypeInfo.cast(this) : this; return extTypeInfo != null ? extTypeInfo.cast(this) : this;
} else if (targetType == Value.JAVA_OBJECT) { } else if (targetType == Value.JAVA_OBJECT) {
return this; return this;
} }
return super.convertTo(targetType, precision, mode, column, null); return super.convertTo(targetType, mode, column, null);
} }
} }
...@@ -367,16 +367,13 @@ public class ValueLob extends Value { ...@@ -367,16 +367,13 @@ public class ValueLob extends Value {
* except when converting to BLOB or CLOB. * except when converting to BLOB or CLOB.
* *
* @param t the new type * @param t the new type
* @param precision the precision of the column to convert this value to.
* The special constant <code>-1</code> is used to indicate that
* the precision plays no role when converting the value
* @param mode the database mode * @param mode the database mode
* @param column the column (if any), used for to improve the error message if conversion fails * @param column the column (if any), used for to improve the error message if conversion fails
* @param extTypeInfo the extended data type information, or null * @param extTypeInfo the extended data type information, or null
* @return the converted value * @return the converted value
*/ */
@Override @Override
public Value convertTo(int t, int precision, Mode mode, Object column, ExtTypeInfo extTypeInfo) { public Value convertTo(int t, Mode mode, Object column, ExtTypeInfo extTypeInfo) {
if (t == valueType) { if (t == valueType) {
return this; return this;
} else if (t == Value.CLOB) { } else if (t == Value.CLOB) {
...@@ -384,7 +381,7 @@ public class ValueLob extends Value { ...@@ -384,7 +381,7 @@ public class ValueLob extends Value {
} else if (t == Value.BLOB) { } else if (t == Value.BLOB) {
return ValueLobDb.createTempBlob(getInputStream(), -1, handler); return ValueLobDb.createTempBlob(getInputStream(), -1, handler);
} }
return super.convertTo(t, precision, mode, column, null); return super.convertTo(t, mode, column, null);
} }
@Override @Override
......
...@@ -205,14 +205,13 @@ public class ValueLobDb extends Value { ...@@ -205,14 +205,13 @@ public class ValueLobDb extends Value {
* except when converting to BLOB or CLOB. * except when converting to BLOB or CLOB.
* *
* @param t the new type * @param t the new type
* @param precision the precision
* @param mode the mode * @param mode the mode
* @param column the column (if any), used for to improve the error message if conversion fails * @param column the column (if any), used for to improve the error message if conversion fails
* @param extTypeInfo the extended data type information, or null * @param extTypeInfo the extended data type information, or null
* @return the converted value * @return the converted value
*/ */
@Override @Override
public Value convertTo(int t, int precision, Mode mode, Object column, ExtTypeInfo extTypeInfo) { public Value convertTo(int t, Mode mode, Object column, ExtTypeInfo extTypeInfo) {
if (t == valueType) { if (t == valueType) {
return this; return this;
} else if (t == Value.CLOB) { } else if (t == Value.CLOB) {
...@@ -230,7 +229,7 @@ public class ValueLobDb extends Value { ...@@ -230,7 +229,7 @@ public class ValueLobDb extends Value {
return ValueLobDb.createSmallLob(t, small); return ValueLobDb.createSmallLob(t, small);
} }
} }
return super.convertTo(t, precision, mode, column, null); return super.convertTo(t, mode, column, null);
} }
@Override @Override
......
...@@ -139,7 +139,7 @@ public class ValueNull extends Value { ...@@ -139,7 +139,7 @@ public class ValueNull extends Value {
} }
@Override @Override
public Value convertTo(int type, int precision, Mode mode, Object column, ExtTypeInfo extTypeInfo) { public Value convertTo(int type, Mode mode, Object column, ExtTypeInfo extTypeInfo) {
return this; return this;
} }
......
...@@ -391,7 +391,7 @@ public class TestCustomDataTypesHandler extends TestDb { ...@@ -391,7 +391,7 @@ public class TestCustomDataTypesHandler extends TestDb {
} }
@Override @Override
public Value convertTo(int targetType, int precision, Mode mode, Object column, ExtTypeInfo extTypeInfo) { public Value convertTo(int targetType, Mode mode, Object column, ExtTypeInfo extTypeInfo) {
if (getValueType() == targetType) { if (getValueType() == targetType) {
return this; return this;
} }
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论