今日不肯埋头,明日何以抬头!每日一句努力自己的话哈哈~哈喽,今天我将给大家带来一篇《go build error" NEXT undefined (类型 *"database/sql".Rows 没有字段或方法 NEXT)》,主要内容是讲解等等,感兴趣的朋友可以收藏或者有更好的建议在评论提出,我都会认真看的!大家一起进步,一起学习!
问题内容我想在 go 中的行中使用 next 但我在 rows.next 中收到警告 它说 next 未定义(类型 *"database/sql".rows 没有字段或方法 next)
func FetchViewDO() (shipment_admin.ShipmentViewDetailDOGroup, error) {
var obj ShipmentDOBaseModel
var objg ShipmentDOGroup
var arrobj []ShipmentDOBaseModel
var res shipment_admin.ShipmentViewDetailDOGroup
var db *sql.DB
con := db
sqlStatement := `SELECT s.status_id,sdog.*,sdo.shipment_id,sdo.external_id,sdo.client_code
FROM shipment_delivery_order sdo
LEFT JOIN shipment_delivery_order_group sdog ON sdog.shipment_child_id = sdo.shipment_id
LEFT JOIN shipment s ON s.shipment_id = sdo.shipment_id`
rows, err := con.Query(sqlStatement)
defer rows.Close()
if err != nil {
return res, err
}
for rows.NEXT() {
err = rows.Scan(&objg.ShipmentParentID, &objg.CreatedAt, &objg.ShipmentChildID)
if err != nil {
return res, err
}
}
res.Status = http.StatusOK
res.Message = "Success"
res.Data = arrobj
return res, nil
}
正确答案
没有名为 NEXT 的方法,但有一个名为 Next 的方法,我认为这是您问题的答案,请记住 Go 区分大小写
今天带大家了解了的相关知识,希望对你有所帮助;关于Golang的技术知识我们会一点点深入介绍,欢迎大家关注编程网公众号,一起学习编程~