Skip to content

Commit

Permalink
up to 6.5.5,fix decode bug
Browse files Browse the repository at this point in the history
  • Loading branch information
zhuxiujia committed Jul 9, 2020
1 parent 5be73ca commit 04ea89a
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 14 deletions.
36 changes: 24 additions & 12 deletions GoMybatisSqlResultDecoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,20 +81,20 @@ func (it GoMybatisSqlResultDecoder) Decode(resultMap map[string]*ResultProperty,
return e
}

func makeStructMap(itemType reflect.Type) (map[string]reflect.Type, error) {
func makeStructMap(itemType reflect.Type) (map[string]*reflect.Type, error) {
if itemType.Kind() != reflect.Struct {
return nil, nil
}
var structMap = map[string]reflect.Type{}
var structMap = map[string]*reflect.Type{}
for i := 0; i < itemType.NumField(); i++ {
var item = itemType.Field(i)
structMap[strings.ToLower(item.Tag.Get("json"))] = item.Type
structMap[strings.ToLower(item.Tag.Get("json"))] = &item.Type
}
return structMap, nil
}

//make an json value
func makeJsonObjBytes(resultMap map[string]*ResultProperty, sqlData map[string][]byte, structMap map[string]reflect.Type) []byte {
func makeJsonObjBytes(resultMap map[string]*ResultProperty, sqlData map[string][]byte, structMap map[string]*reflect.Type) []byte {
var jsonData = strings.Builder{}
jsonData.WriteString("{")

Expand All @@ -106,29 +106,41 @@ func makeJsonObjBytes(resultMap map[string]*ResultProperty, sqlData map[string][
jsonData.WriteString("\":")

var isStringType = false
var fetched = true
if resultMap != nil {
var resultMapItem = resultMap[k]
if resultMapItem != nil && (resultMapItem.LangType == "string" || resultMapItem.LangType == "time.Time") {
isStringType = true
}
if resultMapItem == nil {
fetched = false
}
} else if structMap != nil {
var v = structMap[strings.ToLower(k)]
if v != nil {
if v.Kind() == reflect.String || v.String() == "time.Time" {
if (*v).Kind() == reflect.String || (*v).String() == "time.Time" {
isStringType = true
}
}
if v == nil {
fetched = false
}
} else {
isStringType = true
}
if isStringType {
jsonData.WriteString("\"")
jsonData.WriteString(encodeStringValue(sqlV))
jsonData.WriteString("\"")
} else {
if sqlV == nil || len(sqlV) == 0 {
sqlV = []byte("null")
if fetched {
if isStringType {
jsonData.WriteString("\"")
jsonData.WriteString(encodeStringValue(sqlV))
jsonData.WriteString("\"")
} else {
if sqlV == nil || len(sqlV) == 0 {
sqlV = []byte("null")
}
jsonData.Write(sqlV)
}
} else {
sqlV = []byte("null")
jsonData.Write(sqlV)
}
//write ','
Expand Down
2 changes: 1 addition & 1 deletion README-ch.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ go env -w GOSUMDB=off
//go.mod加入依赖
require (
github.com/go-sql-driver/mysql v1.5.0
github.com/zhuxiujia/GoMybatis v6.5.1+incompatible
github.com/zhuxiujia/GoMybatis v6.5.5+incompatible
)
```

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ go get github.com/go-sql-driver/mysql
//go.mod加入依赖
require (
github.com/go-sql-driver/mysql v1.5.0
github.com/zhuxiujia/GoMybatis v6.5.1+incompatible
github.com/zhuxiujia/GoMybatis v6.5.5+incompatible
)
```

Expand Down

0 comments on commit 04ea89a

Please sign in to comment.