Skip to content

Commit 884a616

Browse files
committed
fix int32 convert
1 parent 786998c commit 884a616

File tree

3 files changed

+5
-6
lines changed

3 files changed

+5
-6
lines changed

sql/types/decimal.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -312,9 +312,7 @@ func (t DecimalType_) SQL(ctx *sql.Context, dest []byte, v interface{}) (sqltype
312312
if err != nil {
313313
return sqltypes.Value{}, err
314314
}
315-
316315
val := encodings.StringToBytes(t.DecimalValueStringFixed(value.Decimal))
317-
318316
return sqltypes.MakeTrusted(sqltypes.Decimal, val), nil
319317
}
320318

sql/types/number.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -453,10 +453,10 @@ func (t NumberTypeImpl_) SQLInt32(ctx *sql.Context, dest []byte, v interface{})
453453
if err != nil {
454454
return nil, err
455455
}
456-
if num > (1<<23 - 1) {
457-
num = int64(1<<23 - 1)
458-
} else if num < (-1 << 23) {
459-
num = int64(-1 << 23)
456+
if num > math.MaxInt32 {
457+
num = math.MaxInt32
458+
} else if num < math.MinInt32 {
459+
num = math.MinInt32
460460
}
461461
dest = strconv.AppendInt(dest, num, 10)
462462
return dest, nil

sql/types/number_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,7 @@ func TestNumberConvert(t *testing.T) {
177177
{typ: Int16, inp: uint16(1), exp: int16(1), err: false, inRange: sql.InRange},
178178
{typ: Int24, inp: false, exp: int32(0), err: false, inRange: sql.InRange},
179179
{typ: Int32, inp: nil, exp: nil, err: false, inRange: sql.InRange},
180+
{typ: Int32, inp: 2147483647, exp: int32(2147483647), err: false, inRange: sql.InRange},
180181
{typ: Int64, inp: "33", exp: int64(33), err: false, inRange: sql.InRange},
181182
{typ: Int64, inp: "33.0", exp: int64(33), err: false, inRange: sql.InRange},
182183
{typ: Int64, inp: "33.1", exp: int64(33), err: false, inRange: sql.InRange},

0 commit comments

Comments
 (0)