-1
我有以下代碼:是否有可能從Golang中的sql.Rows中獲取SQL查詢字符串?
selectPart := "id, user_id, date, time, minutes, details, created_at, updated_at, project_id"
sqlQuery := fmt.Sprintf("SELECT %s FROM time_entries WHERE user_id = $1 AND date >= $2 and date <= $3", selectPart)
var rows *sql.Rows
var err error
if project == nil {
rows, err = DB.Query(sqlQuery, user.ID, formatDate(from), formatDate(to))
} else {
rows, err = DB.Query(sqlQuery + " AND project_id = $4", user.ID, formatDate(from), formatDate(to), project.ID)
}
結果行結構是空的。我想這是因爲數據的插值是錯誤的。我正在使用PostgreSQL。我能以某種方式從rows
實例中獲取SQL字符串嗎?
這看起來很像[XY問題](http://xyproblem.info/)。你究竟在做什麼? – Flimzy