下面代码中 因为数据也不算太大2W多条,但是rows.Next() 竟然执行了1分多钟,我换回C#10来秒,这让我很不理解,有大神能提点下吗?不胜感激
func queryLineInfo() string {
loginfo(log_info, log_project, "数据查询开始!")
rows, err = QuerySql(sqlstr)
loginfo(log_info, log_project, "数据查询结束!")
if err != nil {
rows.Close()
//fmt.Println("数据库查询失败", err)
get_lineinfo.Rescode = "0000"
get_lineinfo.Resmsg = "数据库查询失败!"
}
var databuff []get_lineinfo_buff
loginfo(log_info, log_project, "数据组织开始!")
for rows.Next() {
var buff get_lineinfo_buff
err = rows.Scan(&buff.LineNo, &buff.LineName, &buff.Station_id, &buff.Station_Order, &buff.Station_Name, &buff.IsUpDown, &buff.Status, &buff.Price, &buff.StartTime, &buff.EndTime)
if err != nil {
rows.Close()
loginfo(log_error, log_project, "rows.Scan失败:"+err.Error())
get_lineinfo.Rescode = "0002"
get_lineinfo.Resmsg = "数据解析失败!"
} else {
get_lineinfo.Rescode = "0001"
get_lineinfo.Resmsg = "数据获取成功!"
databuff = append(databuff, buff)
}
}
rows.Close()
get_lineinfo.Data = databuff
loginfo(log_info, log_project, "JSON转换开始!")
if jsonstr, err = json.Marshal(get_lineinfo); err != nil {
fmt.Println("Json", err)
}
loginfo(log_info, log_project, "JSON转换结束!")
return string(jsonstr)
}