-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Closed
Labels
bugIt is confirmed a bug, but don't worry, we'll handle it.It is confirmed a bug, but don't worry, we'll handle it.
Description
Go version
go version go1.23.4 darwin/arm64
GoFrame version
2.9.0
Can this bug be reproduced with the latest release?
Option Yes
What did you do?
DROP TABLE IF EXISTS `proxy_param`;
CREATE TABLE `proxy_param` (
`proxy_id` bigint NOT NULL,
`recommend_ids` json DEFAULT NULL,
`photos` json DEFAULT NULL,
PRIMARY KEY (`proxy_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
INSERT INTO `proxy_param` (`proxy_id`, `recommend_ids`, `photos`) VALUES (1, '[584, 585]', 'null');
INSERT INTO `proxy_param` (`proxy_id`, `recommend_ids`, `photos`) VALUES (2, '[]', NULL);
模型映射为:
type ProxyParam struct {
ProxyId int64 `json:"proxyId" orm:"proxy_id" description:""`
RecommendIds []int64 `json:"recommendIds" orm:"recommend_ids" description:""`
Photos []string `json:"photos" orm:"photos" description:""`
}
var proxyParamList []*entity.ProxyParam
err := dao.ProxyParam.Ctx(context.Background()).Scan(&proxyParamList)
fmt.Println(err) // nil
for _, param := range proxyParamList {
fmt.Printf("%+v\n", param)
}
//遍历打印机结果1: &{ProxyId:1 RecommendIds:[584 585] Photos:[null]}, 这里反序列化结果明显错误了,null为有效的json内容,虽然和数据库的NULL有所不同,但是 json的null 转为[]string 结果应该是 []
//遍历打印机结果2: &{ProxyId:2 RecommendIds:[] Photos:[]}
var proxyId int64
err := dao.ProxyParam.Ctx(context.Background()).Where("proxy_id", 1).
Fields("proxy_id").Scan(&proxyId)
fmt.Println(err) // element of parameter "pointer" for function Scan should type of struct/*struct/[]struct/[]*struc
fmt.Println(proxyId)
var proxyIds []int64
err := dao.ProxyParam.Ctx(context.Background()).Fields("proxy_id").Scan(&proxyIds)
fmt.Println(err) // nil
fmt.Println(proxyIds) // [0 0] 内容错误,正确值是[1 2]
var recommendIds []int64
err := dao.ProxyParam.Ctx(context.Background()).Where("proxy_id", 1).
Fields("recommend_ids").Scan(&recommendIds)
fmt.Println(err) //nil, 没有错误
fmt.Println(recommendIds) //[0] 内容错误,正确值是[584 585]
What did you see happen?
得到的查询结果是错误
What did you expect to see?
正确的查询结果
Metadata
Metadata
Assignees
Labels
bugIt is confirmed a bug, but don't worry, we'll handle it.It is confirmed a bug, but don't worry, we'll handle it.