Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 22 additions & 4 deletions scanner/scanner.go
Original file line number Diff line number Diff line change
Expand Up @@ -380,24 +380,42 @@ func convert(mapValue interface{}, valuei reflect.Value, wrapErr convertErrWrapp

//according to go-mysql-driver/mysql, driver.Value type can only be:
//int64 or []byte(> maxInt64)
//uint64
//float32/float64
//[]byte
//time.Time if parseTime=true or DATE type will be converted into []byte
switch mvt.Kind() {
case reflect.Int64:
v := mapValue.(int64)
if isIntSeriesType(vit.Kind()) {
valuei.SetInt(mapValue.(int64))
valuei.SetInt(v)
} else if isUintSeriesType(vit.Kind()) {
valuei.SetUint(uint64(mapValue.(int64)))
valuei.SetUint(uint64(v))
} else if vit.Kind() == reflect.Bool {
v := mapValue.(int64)
if v > 0 {
valuei.SetBool(true)
} else {
valuei.SetBool(false)
}
} else if vit.Kind() == reflect.String {
valuei.SetString(strconv.FormatInt(mapValue.(int64), 10))
valuei.SetString(strconv.FormatInt(v, 10))
} else {
return wrapErr(mvt, vit)
}
case reflect.Uint64:
v := mapValue.(uint64)
if isIntSeriesType(vit.Kind()) {
valuei.SetInt(int64(v))
} else if isUintSeriesType(vit.Kind()) {
valuei.SetUint(v)
} else if vit.Kind() == reflect.Bool {
if v > 0 {
valuei.SetBool(true)
} else {
valuei.SetBool(false)
}
} else if vit.Kind() == reflect.String {
valuei.SetString(strconv.FormatUint(v, 10))
} else {
return wrapErr(mvt, vit)
}
Expand Down
11 changes: 7 additions & 4 deletions scanner/scanner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,24 @@ import (

func TestBindOne(t *testing.T) {
type Person struct {
Name string `ddb:"name"`
Age int `ddb:"ag"`
Name string `ddb:"name"`
Age int `ddb:"ag"`
Score int8 `ddb:"score"`
}
var p Person
name := "deen"
age := 23
var mp = map[string]interface{}{
"name": name,
"ag": age,
"name": name,
"ag": age,
"score": uint64(100),
}
err := bind(mp, &p)
should := require.New(t)
should.NoError(err)
should.Equal(name, p.Name)
should.Equal(age, p.Age)
should.Equal(int8(100), p.Score)
}

func TestScanner_Time(t *testing.T) {
Expand Down