fix error on mysql

This commit is contained in:
Lunny Xiao 2017-09-09 18:29:26 +08:00
parent f41b9968d8
commit 875f96c37c
No known key found for this signature in database
GPG Key ID: C3B7C91B632F738A
3 changed files with 13 additions and 3 deletions

View File

@ -334,3 +334,15 @@ func convertInt(v interface{}) (int64, error) {
}
return 0, fmt.Errorf("unsupported type: %v", v)
}
func asBool(bs []byte) (bool, error) {
if len(bs) == 0 {
return false, nil
}
if bs[0] == 0x00 {
return false, nil
} else if bs[0] == 0x01 {
return true, nil
}
return strconv.ParseBool(string(bs))
}

View File

@ -313,7 +313,6 @@ func (session *Session) rows2Beans(rows *core.Rows, fields []string, fieldsCount
if err != nil {
return err
}
err = sliceValueSetFunc(&newValue, pk)
if err != nil {
return err

View File

@ -144,8 +144,7 @@ func (session *Session) bytes2Value(col *core.Column, fieldValue *reflect.Value,
case reflect.String:
fieldValue.SetString(string(data))
case reflect.Bool:
d := string(data)
v, err := strconv.ParseBool(d)
v, err := asBool(data)
if err != nil {
return fmt.Errorf("arg %v as bool: %s", key, err.Error())
}