We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent b7bba45 commit 83decf7Copy full SHA for 83decf7
memory/table.go
@@ -1413,7 +1413,8 @@ func (t *Table) ModifyColumn(ctx *sql.Context, columnName string, column *sql.Co
1413
var oldRowWithoutVal sql.Row
1414
oldRowWithoutVal = append(oldRowWithoutVal, row[:oldIdx]...)
1415
oldRowWithoutVal = append(oldRowWithoutVal, row[oldIdx+1:]...)
1416
- newVal, inRange, err := column.Type.Convert(ctx, row[oldIdx])
+ oldType := data.schema.Schema[oldIdx].Type
1417
+ newVal, inRange, err := types.TypeAwareConversion(ctx, row[oldIdx], oldType, column.Type)
1418
if err != nil {
1419
if sql.ErrNotMatchingSRID.Is(err) {
1420
err = sql.ErrNotMatchingSRIDWithColName.New(columnName, err)
sql/expression/case.go
@@ -136,7 +136,7 @@ func (c *Case) Eval(ctx *sql.Context, row sql.Row) (interface{}, error) {
136
}
137
// When unable to convert to the type of the case, return the original value
138
// A common error here is "Out of bounds value for decimal type"
139
- if ret, err := types.TypeAwareConversion(ctx, bval, b.Value.Type(), t); err == nil {
+ if ret, inRange, err := types.TypeAwareConversion(ctx, bval, b.Value.Type(), t); inRange && err == nil {
140
return ret, nil
141
142
return bval, nil
@@ -150,7 +150,7 @@ func (c *Case) Eval(ctx *sql.Context, row sql.Row) (interface{}, error) {
150
151
152
153
- if ret, err := types.TypeAwareConversion(ctx, val, c.Else.Type(), t); err == nil {
+ if ret, inRange, err := types.TypeAwareConversion(ctx, val, c.Else.Type(), t); inRange && err == nil {
154
155
156
return val, nil
sql/expression/comparison.go
@@ -188,7 +188,7 @@ func (c *comparison) castLeftAndRight(ctx *sql.Context, left, right interface{})
188
if r, inRange, err := leftType.Convert(ctx, right); inRange && err == nil {
189
return left, r, leftType, nil
190
} else {
191
- l, err := types.TypeAwareConversion(ctx, left, leftType, rightType)
+ l, _, err := types.TypeAwareConversion(ctx, left, leftType, rightType)
192
193
return nil, nil, nil, err
194
@@ -200,7 +200,7 @@ func (c *comparison) castLeftAndRight(ctx *sql.Context, left, right interface{})
200
if l, inRange, err := rightType.Convert(ctx, left); inRange && err == nil {
201
return l, right, rightType, nil
202
203
- r, err := types.TypeAwareConversion(ctx, right, rightType, leftType)
+ r, _, err := types.TypeAwareConversion(ctx, right, rightType, leftType)
204
205
206
sql/expression/convert.go
@@ -291,10 +291,7 @@ func convertValue(ctx *sql.Context, val interface{}, castTo string, originType s
291
292
switch strings.ToLower(castTo) {
293
case ConvertToBinary:
294
- if types.IsSet(originType) || types.IsEnum(originType) {
295
- val, _ = types.TypeAwareConversion(ctx, val, originType, types.LongText)
296
- }
297
- b, _, err := types.LongBlob.Convert(ctx, val)
+ b, _, err := types.TypeAwareConversion(ctx, val, originType, types.LongBlob)
298
299
return nil, nil
300
@@ -312,7 +309,7 @@ func convertValue(ctx *sql.Context, val interface{}, castTo string, originType s
312
309
313
310
return truncateConvertedValue(b, typeLength)
314
311
case ConvertToChar, ConvertToNChar:
315
- s, err := types.TypeAwareConversion(ctx, val, originType, types.LongText)
+ s, _, err := types.TypeAwareConversion(ctx, val, originType, types.LongText)
316
317
318
sql/types/conversion.go
@@ -738,19 +738,16 @@ func GeneralizeTypes(a, b sql.Type) sql.Type {
738
// TypeAwareConversion converts a value to a specified type, with awareness of the value's original type. This is
739
// necessary because some types, such as EnumType and SetType, are stored as ints and require information from the
740
// original type to properly convert to strings.
741
-func TypeAwareConversion(ctx *sql.Context, val interface{}, originalType sql.Type, convertedType sql.Type) (interface{}, error) {
+func TypeAwareConversion(ctx *sql.Context, val interface{}, originalType sql.Type, convertedType sql.Type) (interface{}, sql.ConvertInRange, error) {
742
if val == nil {
743
- return nil, nil
+ return nil, sql.InRange, nil
744
745
- var converted interface{}
746
var err error
747
- if IsTextOnly(convertedType) {
748
- converted, _, err = ConvertToCollatedString(ctx, val, originalType)
749
- } else {
750
- converted, _, err = convertedType.Convert(ctx, val)
751
752
- if err != nil {
753
- return nil, err
+ if (IsEnum(originalType) || IsSet(originalType)) && IsText(convertedType) {
+ val, _, err = ConvertToCollatedString(ctx, val, originalType)
+ if err != nil {
+ return nil, sql.OutOfRange, err
+ }
754
755
- return converted, nil
+ return convertedType.Convert(ctx, val)
756
0 commit comments