1
0
mirror of https://github.com/zhashkevych/go-sqlxmock.git synced 2024-11-24 08:12:13 +02:00

tests/NullInt.Scan: fix integer conversion from int{8,16,32,64}

This commit is contained in:
Olivier Mengué 2018-07-12 11:23:49 +02:00
parent b9ca56ce96
commit c1f08b2bb1

View File

@ -2,6 +2,7 @@ package sqlmock
import ( import (
"database/sql/driver" "database/sql/driver"
"errors"
"fmt" "fmt"
"strconv" "strconv"
"time" "time"
@ -25,8 +26,28 @@ func (ni *NullInt) Scan(value interface{}) (err error) {
} }
switch v := value.(type) { switch v := value.(type) {
case int, int8, int16, int32, int64: case int:
ni.Integer, ni.Valid = v.(int), true ni.Integer, ni.Valid = v, true
return
case int8:
ni.Integer, ni.Valid = int(v), true
return
case int16:
ni.Integer, ni.Valid = int(v), true
return
case int32:
ni.Integer, ni.Valid = int(v), true
return
case int64:
const maxUint = ^uint(0)
const minUint = 0
const maxInt = int(maxUint >> 1)
const minInt = -maxInt - 1
if v > int64(maxInt) || v < int64(minInt) {
return errors.New("value out of int range")
}
ni.Integer, ni.Valid = int(v), true
return return
case []byte: case []byte:
ni.Integer, err = strconv.Atoi(string(v)) ni.Integer, err = strconv.Atoi(string(v))