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

Use Value.convertTo() with TypeInfo in more places

上级 edaa8645
...@@ -21,6 +21,7 @@ import org.h2.message.DbException; ...@@ -21,6 +21,7 @@ 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.value.TypeInfo;
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;
...@@ -224,17 +225,17 @@ public class Comparison extends Condition { ...@@ -224,17 +225,17 @@ public class Comparison extends Condition {
return ValueExpression.getNull(); return ValueExpression.getNull();
} }
} }
int colType = left.getType().getValueType(); TypeInfo colType = left.getType(), constType = r.getType();
int constType = r.getValueType(); int constValueType = constType.getValueType();
int resType = Value.getHigherOrder(colType, constType); if (constValueType != colType.getValueType()) {
TypeInfo resType = Value.getHigherType(colType, constType);
// If not, the column values will need to be promoted // If not, the column values will need to be promoted
// to constant type, but vise versa, then let's do this here // to constant type, but vise versa, then let's do this here
// once. // once.
if (constType != resType) { if (constValueType != resType.getValueType()) {
Column column = ((ExpressionColumn) left).getColumn(); Column column = ((ExpressionColumn) left).getColumn();
right = ValueExpression.get(r.convertTo(resType, right = ValueExpression.get(r.convertTo(resType, session.getDatabase().getMode(), column));
session.getDatabase().getMode(), }
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, mode, null, extTypeInfo); v0 = v0.convertTo(type, mode, null);
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;
......
...@@ -30,7 +30,6 @@ import org.h2.table.Column; ...@@ -30,7 +30,6 @@ import org.h2.table.Column;
import org.h2.table.IndexColumn; import org.h2.table.IndexColumn;
import org.h2.table.TableFilter; import org.h2.table.TableFilter;
import org.h2.value.CompareMode; import org.h2.value.CompareMode;
import org.h2.value.TypeInfo;
import org.h2.value.Value; import org.h2.value.Value;
import org.h2.value.ValueArray; import org.h2.value.ValueArray;
import org.h2.value.ValueLong; import org.h2.value.ValueLong;
...@@ -289,8 +288,7 @@ public final class MVSecondaryIndex extends BaseIndex implements MVIndex { ...@@ -289,8 +288,7 @@ public final class MVSecondaryIndex extends BaseIndex implements MVIndex {
int idx = c.getColumnId(); int idx = c.getColumnId();
Value v = r.getValue(idx); Value v = r.getValue(idx);
if (v != null) { if (v != null) {
TypeInfo type = c.getType(); array[i] = v.convertTo(c.getType(), database.getMode(), null);
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,7 +164,7 @@ public class Column { ...@@ -164,7 +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(), mode, this, type.getExtTypeInfo()); return v.convertTo(type, mode, this);
} 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() + ": ") +
......
...@@ -696,9 +696,7 @@ public abstract class Value extends VersionedValue { ...@@ -696,9 +696,7 @@ public abstract class Value extends VersionedValue {
* @return the converted value * @return the converted value
*/ */
public final Value convertTo(int targetType) { public final Value convertTo(int targetType) {
// Use -1 to indicate "default behaviour" where value conversion should not return convertTo(targetType, null, null, null);
// depend on any datatype precision.
return convertTo(targetType, null);
} }
/** /**
...@@ -706,9 +704,7 @@ public abstract class Value extends VersionedValue { ...@@ -706,9 +704,7 @@ public abstract class Value extends VersionedValue {
* @param enumerators the extended type information for the ENUM data type * @param enumerators the extended type information for the ENUM data type
* @return value represented as ENUM * @return value represented as ENUM
*/ */
public final Value convertToEnum(ExtTypeInfo enumerators) { private Value convertToEnum(ExtTypeInfo enumerators) {
// Use -1 to indicate "default behaviour" where value conversion should not
// depend on any datatype precision.
return convertTo(ENUM, null, null, enumerators); return convertTo(ENUM, null, null, enumerators);
} }
...@@ -731,7 +727,7 @@ public abstract class Value extends VersionedValue { ...@@ -731,7 +727,7 @@ public abstract class Value extends VersionedValue {
* @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
* @return the converted value * @return the converted value
*/ */
public Value convertTo(TypeInfo targetType, Mode mode, Object column) { public final Value convertTo(TypeInfo targetType, Mode mode, Object column) {
return convertTo(targetType.getValueType(), mode, column, targetType.getExtTypeInfo()); return convertTo(targetType.getValueType(), mode, column, targetType.getExtTypeInfo());
} }
...@@ -744,7 +740,7 @@ public abstract class Value extends VersionedValue { ...@@ -744,7 +740,7 @@ public abstract class Value extends VersionedValue {
* @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, Mode mode, Object column, ExtTypeInfo extTypeInfo) { protected 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,7 +137,7 @@ public class ValueEnumBase extends Value { ...@@ -137,7 +137,7 @@ public class ValueEnumBase extends Value {
} }
@Override @Override
public Value convertTo(int targetType, Mode mode, Object column, ExtTypeInfo extTypeInfo) { protected 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);
} }
......
...@@ -346,7 +346,7 @@ public class ValueGeometry extends Value { ...@@ -346,7 +346,7 @@ public class ValueGeometry extends Value {
} }
@Override @Override
public Value convertTo(int targetType, Mode mode, Object column, ExtTypeInfo extTypeInfo) { protected 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) {
......
...@@ -373,7 +373,7 @@ public class ValueLob extends Value { ...@@ -373,7 +373,7 @@ public class ValueLob extends Value {
* @return the converted value * @return the converted value
*/ */
@Override @Override
public Value convertTo(int t, Mode mode, Object column, ExtTypeInfo extTypeInfo) { protected 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) {
......
...@@ -211,7 +211,7 @@ public class ValueLobDb extends Value { ...@@ -211,7 +211,7 @@ public class ValueLobDb extends Value {
* @return the converted value * @return the converted value
*/ */
@Override @Override
public Value convertTo(int t, Mode mode, Object column, ExtTypeInfo extTypeInfo) { protected 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) {
......
...@@ -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, Mode mode, Object column, ExtTypeInfo extTypeInfo) { protected 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, Mode mode, Object column, ExtTypeInfo extTypeInfo) { protected Value convertTo(int targetType, Mode mode, Object column, ExtTypeInfo extTypeInfo) {
if (getValueType() == targetType) { if (getValueType() == targetType) {
return this; return this;
} }
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论