1
0
mirror of https://github.com/DATA-DOG/go-sqlmock.git synced 2025-03-23 21:09:19 +02:00

Merge pull request #129 from dolmen/apply-ParameterConverter-on-Row-values

Apply parameter converter on row values
This commit is contained in:
Gediminas Morkevicius 2018-07-20 11:32:39 +03:00 committed by GitHub
commit 852fc940e4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 14 deletions

11
rows.go
View File

@ -126,6 +126,17 @@ func (r *Rows) AddRow(values ...driver.Value) *Rows {
row := make([]driver.Value, len(r.cols))
for i, v := range values {
// Convert user-friendly values (such as int or driver.Valuer)
// to database/sql native value (driver.Value such as int64)
var err error
v, err = driver.DefaultParameterConverter.ConvertValue(v)
if err != nil {
panic(fmt.Errorf(
"row #%d, column #%d (%q) type %T: %s",
len(r.rows)+1, i, r.cols[i], values[i], err,
))
}
row[i] = v
}

View File

@ -23,20 +23,6 @@ func (ni *NullInt) Scan(value interface{}) error {
switch v := value.(type) {
case nil:
ni.Integer, ni.Valid = 0, false
// FIXME int, int8, int16, int32 types are handled here but that should not
// be necessary: only int64 is a driver.Value
// Unfortunately, the sqlmock testsuite currently relies on that because
// sqlmock doesn't properly limits itself internally to pure driver.Value.
case int:
ni.Integer, ni.Valid = v, true
case int8:
ni.Integer, ni.Valid = int(v), true
case int16:
ni.Integer, ni.Valid = int(v), true
case int32:
ni.Integer, ni.Valid = int(v), true
case int64:
const maxUint = ^uint(0)
const minUint = 0