refactor get #1967
9
scan.go
9
scan.go
|
@ -78,6 +78,7 @@ func genScanResultsByBean(bean interface{}) (interface{}, bool, error) {
|
||||||
*string,
|
*string,
|
||||||
*int, *int8, *int16, *int32, *int64,
|
*int, *int8, *int16, *int32, *int64,
|
||||||
*uint, *uint8, *uint16, *uint32, *uint64,
|
*uint, *uint8, *uint16, *uint32, *uint64,
|
||||||
|
*float32, *float64,
|
||||||
*bool:
|
*bool:
|
||||||
return t, false, nil
|
return t, false, nil
|
||||||
case *time.Time:
|
case *time.Time:
|
||||||
|
@ -117,6 +118,10 @@ func genScanResultsByBean(bean interface{}) (interface{}, bool, error) {
|
||||||
return new(uint16), true, nil
|
return new(uint16), true, nil
|
||||||
case reflect.Uint8:
|
case reflect.Uint8:
|
||||||
return new(uint8), true, nil
|
return new(uint8), true, nil
|
||||||
|
case reflect.Float32:
|
||||||
|
return new(float32), true, nil
|
||||||
|
case reflect.Float64:
|
||||||
|
return new(float64), true, nil
|
||||||
default:
|
default:
|
||||||
return nil, false, fmt.Errorf("unsupported type: %#v", bean)
|
return nil, false, fmt.Errorf("unsupported type: %#v", bean)
|
||||||
}
|
}
|
||||||
|
@ -177,7 +182,7 @@ func (engine *Engine) scanStringInterface(rows *core.Rows, types []*sql.ColumnTy
|
||||||
}
|
}
|
||||||
|
|
||||||
// scan is a wrap of driver.Scan but will automatically change the input values according requirements
|
// scan is a wrap of driver.Scan but will automatically change the input values according requirements
|
||||||
func (engine *Engine) scan(rows *core.Rows, types []*sql.ColumnType, vv ...interface{}) error {
|
func (engine *Engine) scan(rows *core.Rows, fields []string, types []*sql.ColumnType, vv ...interface{}) error {
|
||||||
var scanResults = make([]interface{}, 0, len(types))
|
var scanResults = make([]interface{}, 0, len(types))
|
||||||
var replaces = make([]bool, 0, len(types))
|
var replaces = make([]bool, 0, len(types))
|
||||||
var err error
|
var err error
|
||||||
|
@ -188,7 +193,7 @@ func (engine *Engine) scan(rows *core.Rows, types []*sql.ColumnType, vv ...inter
|
||||||
var useNullable = true
|
var useNullable = true
|
||||||
if engine.driver.Features().SupportNullable {
|
if engine.driver.Features().SupportNullable {
|
||||||
nullable, ok := types[0].Nullable()
|
nullable, ok := types[0].Nullable()
|
||||||
useNullable = ok && !nullable
|
useNullable = ok && nullable
|
||||||
}
|
}
|
||||||
|
|
||||||
if useNullable {
|
if useNullable {
|
||||||
|
|
|
@ -256,7 +256,7 @@ func (session *Session) getVars(rows *core.Rows, types []*sql.ColumnType, fields
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
err := session.engine.scan(rows, types, scanResults...)
|
err := session.engine.scan(rows, fields, types, scanResults...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return true, err
|
return true, err
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user