第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

使用 execContext golang 插入時(shí)出錯(cuò)

使用 execContext golang 插入時(shí)出錯(cuò)

Go
慕絲7291255 2022-11-28 17:13:01
我有處理將新數(shù)據(jù)插入數(shù)據(jù)庫 mysql 的代碼,我已經(jīng)放置了正確的上下文、查詢語句和值參數(shù)。但是當(dāng)我嘗試執(zhí)行查詢時(shí),出現(xiàn)了這樣的錯(cuò)誤sql: expected 1 arguments, got 6這是我的司機(jī)"github.com/go-sql-driver/mysql"這是我的數(shù)據(jù)庫連接語句connResult, err := sql.Open("mysql", os.Getenv("MY_SQL_URL"))這是我的代碼func (pr productRepo) AddProduct(c *gin.Context, req product.AddProduct) *model.RepoResponse {    var negotiate int8    ctx, cancel := context.WithTimeout(c, 10*time.Second)    identity := library.Identity(c)    currentTime := library.Time().CurrentDateTimeDbFormat()    defer cancel()    id := uuid.New()    if req.Negotiate {        negotiate = 1    }    statement := "INSERT INTO product (id_product, user, field, judul, negosiasi, createdAt) VALUES ('?', '?', '?', '?', ?, '?')"    result, errInsert := pr.conn.ExecContext(ctx, statement, id, identity.GetUserID(), req.Field, req.Title, negotiate, currentTime)    if errInsert != nil {        fmt.Println(errInsert)        return &model.RepoResponse{Success: false, Msg: "Failed to add product"}    }    inserted, errRows := result.RowsAffected()    if errRows != nil {        fmt.Println(errRows)        return &model.RepoResponse{Success: false, Msg: "Failed to add product"}    } else if inserted == 0 {        fmt.Println("Inserted value ", inserted)        return &model.RepoResponse{Success: false, Msg: "Failed to add product"}    }    return &model.RepoResponse{Success: true, Data: id}}我的代碼有問題還是我的驅(qū)動(dòng)程序有問題?謝謝
查看完整描述

1 回答

?
繁華開滿天機(jī)

TA貢獻(xiàn)1816條經(jīng)驗(yàn) 獲得超4個(gè)贊

嘗試將問號(hào)放在沒有撇號(hào)的語句中:

statement := "INSERT INTO product (id_product, user, field, judul, negosiasi, createdAt) VALUES (?, ?, ?, ?, ?, ?)"

如您所見,在您的代碼中只有一個(gè)?沒有撇號(hào),因此驅(qū)動(dòng)程序需要一個(gè) arg 而不是六個(gè)


查看完整回答
反對(duì) 回復(fù) 2022-11-28
  • 1 回答
  • 0 關(guān)注
  • 177 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)