Skip to content

Commit 6904da1

Browse files
author
James Cor
committed
decimal conversion tests
1 parent 9b5519b commit 6904da1

File tree

2 files changed

+462
-3
lines changed

2 files changed

+462
-3
lines changed

sql/types/decimal.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -144,11 +144,11 @@ func (t DecimalType_) CompareValue(ctx *sql.Context, a, b sql.Value) (int, error
144144
if hasNulls, res := CompareNullValues(a, b); hasNulls {
145145
return res, nil
146146
}
147-
aDec, err := ConvertValueToDecimal(ctx, a)
147+
aDec, err := convertValueToDecimal(ctx, a)
148148
if err != nil {
149149
return 0, err
150150
}
151-
bDec, err := ConvertValueToDecimal(ctx, b)
151+
bDec, err := convertValueToDecimal(ctx, b)
152152
if err != nil {
153153
return 0, err
154154
}
@@ -412,7 +412,7 @@ func (t DecimalType_) DecimalValueStringFixed(v decimal.Decimal) string {
412412
}
413413
}
414414

415-
func ConvertValueToDecimal(ctx *sql.Context, v sql.Value) (decimal.Decimal, error) {
415+
func convertValueToDecimal(ctx *sql.Context, v sql.Value) (decimal.Decimal, error) {
416416
switch v.Typ {
417417
case sqltypes.Int8:
418418
x := values.ReadInt8(v.Val)
@@ -448,6 +448,10 @@ func ConvertValueToDecimal(ctx *sql.Context, v sql.Value) (decimal.Decimal, erro
448448
case sqltypes.Decimal:
449449
x := values.ReadDecimal(v.Val)
450450
return x, nil
451+
case sqltypes.Bit:
452+
x := values.ReadUint64(v.Val)
453+
bi := new(big.Int).SetUint64(x)
454+
return decimal.NewFromBigInt(bi, 0), nil
451455
case sqltypes.Year:
452456
x := values.ReadUint16(v.Val)
453457
return decimal.NewFromInt(int64(x)), nil

0 commit comments

Comments
 (0)