mysql 데이터베이스에서 쿼리를 실행하는 func를 만들었습니다. 이 패키지 "github.com/go-sql-driver/mysql"을 사용합니다.
그러나 이것을 실행하면 :
...
err := database.ExecuteSql("INSERT INTO xxx(field1, field2, field3) VALUES(?, ?, ?)", "field1", 123, time.Now())
...
func ExecuteSql(cmd string, , args ...interface{}) error {
ctx := context.Background()
_, err := db.ExecContext(ctx, cmd, args)
ctx.Done()
...
}
"sql : converting argument $ 1 type : unsupported type [] interface {}, a slice of interface"를 반환합니다.
다음과 같은 방법을 실행할 때 :
_, err := db.ExecContext(ctx, cmd, args)
당신은 통과 args
하나로서 []interface{}
인수입니다. .NET Core가 아닌 경우 슬라이스는 ExecContext
메서드의 인수로 지원되지 않습니다 []byte
.
unpack 연산자를 args
다음 과 함께 사용해야합니다 .
_, err := db.ExecContext(ctx, cmd, args...)
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다