我需要使用Go获得4列。当我在MySQL中运行查询时,我会得到所有4列,但是当我尝试使用Go进行操作时,我只会得到3列。转到代码为:
get() returned more than one Ledger1 -- it returned 2!
当我用Go运行它时,我会看到以下列:id,艺术家和图片。我无法找到song_name列。
当我在MySQL中运行它时,我得到:
{
"responseId": "a89123c6-42e5-45fa-ab2d-153a9d7e3692",
"queryResult": {
"queryText": "I need to make an appointment at 3 PM today.",
"parameters": {
"time": "",
"date": ""
},
"allRequiredParamsPresent": true,
"fulfillmentMessages": [
{
"text": {
"text": [
""
]
}
}
],
"intent": {
"name": "projects/newagent-b231a/agent/intents/f6477cf2-cd73-4dc3-a8bd-614d45998754",
"displayName": "Make Appointment"
},
"intentDetectionConfidence": 1,
"diagnosticInfo": {
"webhook_latency_ms": 142
},
"languageCode": "zh-tw"
},
"webhookStatus": {
"code": 13,
"message": "Webhook call failed. Error: 500 Internal Server Error"
}
}
答案 0 :(得分:0)
我不知道如何以及为什么,但是这段代码有效:
type song struct {
Id int64
Artist string
Name string
Picture string
}
type data struct {
Songs []song
}
// Open database
db, err := sql.Open(sqlServer, sqlData)
checkErr(err)
rows, err := db.Query("SELECT s.id, s.song_name, a.name, al.picture as artistName FROM music_songs s JOIN music_albums al ON s.album_id = al.id JOIN music_artists a ON a.id = s.artist_id WHERE s.artist_id = ? ORDER BY s.id ASC, al.id ASC", ar)
checkErr(err)
var id int64
var songName string
var artistName string
var albumPicture string
var songs []song
for rows.Next() {
err = rows.Scan(&id, &songName, &artistName, &albumPicture)
songs = append(songs, song{id, songName, artistName, albumPicture})
}