英文:
multiple-value .Exec() in single-value context with Golang sql
问题
我正在尝试使用golang和标准的SQL驱动程序在SQLite3数据库中更新单行中的多个值,但在调试时遇到了以下错误:
command-line-arguments
./server.go:169: 在单值上下文中使用多值 updateStatement.Exec()
相关的代码如下(省略了不相关的代码):
SQL语句:
const (
rsvpSubmit = "UPDATE rsvp SET Name = ?, Rsvp = ?, Guests = ?, Meal0 = ?, Meal1 = ?, Comments = ?, ModifiedAt = ? WHERE email = ?"
)
var (
updateStatement *sql.Stmt
)
errr := updateStatement.Exec(
r.FormValue("name"),
r.FormValue("rsvp"),
r.FormValue("guests"),
r.FormValue("meal0"),
r.FormValue("meal1"),
r.FormValue("comments"),
time.Now(),
cookie.Value)
数据库具有以下列(结构体复制了这些列):
type User struct {
Id int
Email string
Name sql.NullString
Rsvp sql.NullInt64
Guests sql.NullInt64
Meal0 sql.NullString
Meal1 sql.NullString
Comments sql.NullString
ModifiedAt sql.NullString
}
非常感谢您的帮助!
英文:
I am trying to update multiple values in a single row in an SQLite3 database using golang and the standard sql driver but am having trouble debugging the following error:
command-line-arguments
./server.go:169: multiple-value updateStatement.Exec() in single-value context
The relevant code is as follows (irrelevant code has been omitted):
SQL Statement:
const (
rsvpSubmit = "UPDATE rsvp SET Name = ?, Rsvp = ?, Guests = ?, Meal0 = ?, Meal1 = ?, Comments = ?, ModifiedAt = ? WHERE email = ?"
)
var (
updateStatement *sql.Stmt
)
errr := updateStatement.Exec(
r.FormValue("name"),
r.FormValue("rsvp"),
r.FormValue("guests"),
r.FormValue("meal0"),
r.FormValue("meal1"),
r.FormValue("comments"),
time.Now(),
cookie.Value)
The database has the following columns (which the struct replicates):
type User struct {
Id int
Email string
Name sql.NullString
Rsvp sql.NullInt64
Guests sql.NullInt64
Meal0 sql.NullString
Meal1 sql.NullString
Comments sql.NullString
ModifiedAt sql.NullString
}
Any help is greatly appreciated!
答案1
得分: 4
Stmt.Exec
的定义如下:
func (s *Stmt) Exec(args ...interface{}) (Result, error)
如果你不关心结果,可以使用 _, err := updateStatement.Exec(...)
。
英文:
Stmt.Exec
is defined as:
func (s *Stmt) Exec(args ...interface{}) (Result, error)
if you don't care about the result then you can use _, err := updateStatement.Exec(...)
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论