当我尝试调用 err = row.Scan(&resourceList, resourceTypeId) 时收到以下错误
列索引 0 上的扫描错误,名称“ID”:不支持扫描,将 driver.Value 类型 int64 存储到类型 *[]authService.Permission”
type Permission struct {
ID int `json:"id"`
Name string `json:"name"`
Description string `json:"description"`
ParentResourceID int `json:"parentResourceId"`
}
func GetResourcesByResourceTypeId(resourceTypeId string) ([]Permission, string, error) {
db, ctx := db.GetDB()
query := "CALL usp_GetParentResourceListByResourceTypeID(?)"
var resourceList []Permission
stmt, err := db.Prepare(query)
defer stmt.Close()
if err != nil {
log.Errorln("Error in preparing statement. " + err.Error())
return nil, "Error in preparing statement.", err
}
row := stmt.QueryRowContext(ctx, resourceTypeId)
err = row.Scan(&resourceList, resourceTypeId)
if err == nil {
return resourceList, "Resource retrieval.", nil
}
log.Warningln("Resource retrieval failed, ResourceTypeID: " + resourceTypeId + ".")
return resourceList, "Resource retrieval failed.", nil
}
SQL 返回如下
ID Name 15 Applications 16 Subscriptions 17 Payments
当我尝试在 query 中使用带有 EXEC 语句的 SQL Server 时,相同的查询工作正常。
知道这里出了什么问题吗?提前致谢。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号