在Golang的SQL中,将多个值的.Exec()用于单个值的上下文中。

huangapple go评论86阅读模式
英文:

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(...)

huangapple
  • 本文由 发表于 2014年10月4日 00:17:29
  • 转载请务必保留本文链接:https://go.coder-hub.com/26182802.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定