1
0
mirror of https://github.com/DATA-DOG/go-sqlmock.git synced 2025-04-02 21:45:24 +02:00

tests/NullInt: fix Scan from string/[]byte

Do not change the value if Atoi fails
This commit is contained in:
Olivier Mengué 2018-07-12 11:47:20 +02:00
parent c1f08b2bb1
commit 4f574cddfd

View File

@ -50,13 +50,19 @@ func (ni *NullInt) Scan(value interface{}) (err error) {
ni.Integer, ni.Valid = int(v), true
return
case []byte:
ni.Integer, err = strconv.Atoi(string(v))
ni.Valid = (err == nil)
return
n, err := strconv.Atoi(string(v))
if err != nil {
return err
}
ni.Integer, ni.Valid = n, true
return nil
case string:
ni.Integer, err = strconv.Atoi(v)
ni.Valid = (err == nil)
return
n, err := strconv.Atoi(v)
if err != nil {
return err
}
ni.Integer, ni.Valid = n, true
return nil
}
ni.Valid = false