调用Query函数获取pgsql中的多行数据失败,一行数据都没有读到,debug之后看到返回的*sql.rows类型的变量中提示如下,
数据库中有十一列数据,如下所示
这是我的代码:
func Acenroll(w http.ResponseWriter, r *http.Request) {
sqlStr := `SELECT * FROM acinfo ` //sql语句
info, e := db.Query(sqlStr) //查询数据库中的数据
if e != nil {
panic(e.Error())
}
defer info.Close()
var activityinfo []string
//debug的时候发现,这个for循环被跳过了
for info.Next() {
var (
acname string
bgdate pgtype.Date
bgtime time.Time
edate pgtype.Date
etime time.Time
acplace string
accontext string
acpeople float64
mg string
phone string
quest string
)
info.Scan(&acname, &bgdate, &bgtime, &edate, &etime, &acplace, &accontext, &acpeople, &mg, &phone, &quest)
activityinfo = append(activityinfo, fmt.Sprintf(`{ "ActivityName": %s,BeginDate: %v,BeginTime: %v,EndDate: %v,
EndTime: %v,
ActivityPlace: %s,
ActivityContext: %s,
ActivityPeople: %f,
Manager: %s,
PhoneNumber:%s,
Quest: %s,}`, acname, bgdate, bgtime, edate, etime, acplace, accontext, acpeople, mg, phone, quest))
}
backmsg = []byte(fmt.Sprintf(`[%s]`, strings.Join(activityinfo, ",")))
resp(w)
}