dongshuzui0335
2016-08-31 01:51
浏览 364
已采纳

使用CloudSQL进行更新的SQL语言的Golang Gorm db.raw无法正常工作?

I have this SQL query, which in isolation works fine with 2 rows affected absolutely fine

update chores set life_status ='Processing' where life_status = 'Active' and chore_type ='Shared' and money_assigned > 0

But when I try gorm's execution variant statements in golang i.e.

err := h.db.Raw("update chores set life_status ='Processing' where life_status = 'Active' and chore_type ='Shared' and money_assigned > ? ", 0).Error

OR

numRecsToProcess := h.db.Raw("update chores set life_status ='Processing' where life_status = 'Active' and chore_type ='Shared' and money_assigned > ? ", 0).RowsAffected

None of these update statements are affecting any change in underlying DB. Is there something I am missing from Gorm usage functionality ?

  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • dtgj8529 2016-08-31 07:02
    已采纳

    Try h.db.Exec instead of h.db.Raw.

    打赏 评论

相关推荐 更多相似问题