提交 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;
import org.h2.table.Column;
import org.h2.table.ColumnResolver;
import org.h2.table.TableFilter;
import org.h2.value.TypeInfo;
import org.h2.value.Value;
import org.h2.value.ValueBoolean;
import org.h2.value.ValueGeometry;
......@@ -224,17 +225,17 @@ public class Comparison extends Condition {
return ValueExpression.getNull();
}
}
int colType = left.getType().getValueType();
int constType = r.getValueType();
int resType = Value.getHigherOrder(colType, constType);
// If not, the column values will need to be promoted
// to constant type, but vise versa, then let's do this here
// once.
if (constType != resType) {
Column column = ((ExpressionColumn) left).getColumn();
right = ValueExpression.get(r.convertTo(resType,
session.getDatabase().getMode(),
column, column.getType().getExtTypeInfo()));
TypeInfo colType = left.getType(), constType = r.getType();
int constValueType = constType.getValueType();
if (constValueType != colType.getValueType()) {
TypeInfo resType = Value.getHigherType(colType, constType);
// If not, the column values will need to be promoted
// to constant type, but vise versa, then let's do this here
// once.
if (constValueType != resType.getValueType()) {
Column column = ((ExpressionColumn) left).getColumn();
right = ValueExpression.get(r.convertTo(resType, session.getDatabase().getMode(), column));
}
}
} else if (right instanceof Parameter) {
((Parameter) right).setColumn(
......
......@@ -902,7 +902,7 @@ public class Function extends Expression implements FunctionCall {
case CONVERT: {
Mode mode = database.getMode();
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.convertPrecision(type.getPrecision(), false);
result = v0;
......
......@@ -30,7 +30,6 @@ import org.h2.table.Column;
import org.h2.table.IndexColumn;
import org.h2.table.TableFilter;
import org.h2.value.CompareMode;
import org.h2.value.TypeInfo;
import org.h2.value.Value;
import org.h2.value.ValueArray;
import org.h2.value.ValueLong;
......@@ -289,8 +288,7 @@ public final class MVSecondaryIndex extends BaseIndex implements MVIndex {
int idx = c.getColumnId();
Value v = r.getValue(idx);
if (v != null) {
TypeInfo type = c.getType();
array[i] = v.convertTo(type.getValueType(), database.getMode(), null, type.getExtTypeInfo());
array[i] = v.convertTo(c.getType(), database.getMode(), null);
}
}
array[keyColumns - 1] = key != null ? key : ValueLong.get(r.getKey());
......
......@@ -164,7 +164,7 @@ public class Column {
*/
public Value convert(Value v, Mode mode) {
try {
return v.convertTo(type.getValueType(), mode, this, type.getExtTypeInfo());
return v.convertTo(type, mode, this);
} catch (DbException e) {
if (e.getErrorCode() == ErrorCode.DATA_CONVERSION_ERROR_1) {
String target = (table == null ? "" : table.getName() + ": ") +
......
......@@ -696,9 +696,7 @@ public abstract class Value extends VersionedValue {
* @return the converted value
*/
public final Value convertTo(int targetType) {
// Use -1 to indicate "default behaviour" where value conversion should not
// depend on any datatype precision.
return convertTo(targetType, null);
return convertTo(targetType, null, null, null);
}
/**
......@@ -706,9 +704,7 @@ public abstract class Value extends VersionedValue {
* @param enumerators the extended type information for the ENUM data type
* @return value represented as ENUM
*/
public final Value convertToEnum(ExtTypeInfo enumerators) {
// Use -1 to indicate "default behaviour" where value conversion should not
// depend on any datatype precision.
private Value convertToEnum(ExtTypeInfo enumerators) {
return convertTo(ENUM, null, null, enumerators);
}
......@@ -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
* @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());
}
......@@ -744,7 +740,7 @@ public abstract class Value extends VersionedValue {
* @param extTypeInfo the extended data type information, or null
* @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 BLOB to CLOB and vice versa is done in ValueLob
if (getValueType() == targetType) {
......
......@@ -137,7 +137,7 @@ public class ValueEnumBase extends Value {
}
@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) {
return extTypeInfo.cast(this);
}
......
......@@ -346,7 +346,7 @@ public class ValueGeometry extends Value {
}
@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) {
return extTypeInfo != null ? extTypeInfo.cast(this) : this;
} else if (targetType == Value.JAVA_OBJECT) {
......
......@@ -373,7 +373,7 @@ public class ValueLob extends Value {
* @return the converted value
*/
@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) {
return this;
} else if (t == Value.CLOB) {
......
......@@ -211,7 +211,7 @@ public class ValueLobDb extends Value {
* @return the converted value
*/
@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) {
return this;
} else if (t == Value.CLOB) {
......
......@@ -139,7 +139,7 @@ public class ValueNull extends Value {
}
@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;
}
......
......@@ -391,7 +391,7 @@ public class TestCustomDataTypesHandler extends TestDb {
}
@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) {
return this;
}
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论