duanke0178 2017-11-19 08:38
浏览 73
已采纳

如何在sqlx中增加字段值

In a Go app, using sqlx package and mysql database, I want to update table user and increment its posts field by 1:

err = shared.Dbmap.Exec("UPDATE user SET posts=posts+1 WHERE id=?", userId)
if err != nil {
    log.Println(err)
    return
}

However at compile time I get:

multiple-value shared.Dbmap.DB.Exec() in single-value context

I looked at the docs and could not see relevant examples.

How can I fix it?

  • 写回答

1条回答 默认 最新

  • drn1008 2017-11-19 08:44
    关注

    This is how to read the message multiple-value shared.Dbmap.DB.Exec() in single-value context:

    • shared.Dbmap.DB.Exec() has multiple values
    • You are trying to use it in a single-value context

    In your code you have err = shared.Dbmap.Exec(...).

    On the left side of the assignment there is a single value, on the right side there are multiple.

    Looking at the docs, the Exec(...) function returns 2 values, but you assign it to one value.

    Write like this:

    _, err = shared.Dbmap.Exec("UPDATE user SET posts=posts+1 WHERE id=?", userId)
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度