Skip to content

Commit 12e9fa3

Browse files
author
James Cor
committed
fixing up and todo
1 parent d6e8780 commit 12e9fa3

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

sql/expression/convert.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -412,6 +412,7 @@ func convertValue(ctx *sql.Context, val interface{}, castTo string, originType s
412412
if err != nil {
413413
return nil, err
414414
}
415+
// TODO: if truncation error and out of range, then throw 2's complement warning
415416
num, _, err := types.Uint64.Convert(ctx, value)
416417
if err != nil {
417418
num, _, err = types.Int64.Convert(ctx, value)

sql/types/decimal.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,14 @@ func (t DecimalType_) ConvertToNullDecimal(v interface{}) (decimal.NullDecimal,
221221
}
222222
truncStr, didTrunc := sql.TruncateStringToDouble(value)
223223
if truncStr == "0" {
224-
return t.ConvertToNullDecimal(decimal.NewFromInt(0))
224+
nullDec, cErr := t.ConvertToNullDecimal(decimal.NewFromInt(0))
225+
if cErr != nil {
226+
return decimal.NullDecimal{}, cErr
227+
}
228+
if didTrunc {
229+
return nullDec, sql.ErrTruncatedIncorrect.New(t, value)
230+
}
231+
return nullDec, nil
225232
}
226233
res, _ = decimal.NewFromString(truncStr)
227234
nullDec, cErr := t.ConvertToNullDecimal(res)

0 commit comments

Comments
 (0)