Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/go/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Golang Gorm db.raw与用于更新SQL查询的CloudSQL不工作?_Go_Google Cloud Sql_Go Gorm - Fatal编程技术网

Golang Gorm db.raw与用于更新SQL查询的CloudSQL不工作?

Golang Gorm db.raw与用于更新SQL查询的CloudSQL不工作?,go,google-cloud-sql,go-gorm,Go,Google Cloud Sql,Go Gorm,我有一个SQL查询,它在隔离状态下可以很好地处理2行数据 update chores set life_status ='Processing' where life_status = 'Active' and chore_type ='Shared' and money_assigned > 0 但是当我在golang中尝试gorm的执行变量语句时 err := h.db.Raw("update chores set life_status ='Processing' where li

我有一个SQL查询,它在隔离状态下可以很好地处理2行数据

update chores set life_status ='Processing' where life_status = 'Active' and chore_type ='Shared' and money_assigned > 0
但是当我在golang中尝试gorm的执行变量语句时

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


这些update语句都不会影响基础数据库中的任何更改。Gorm使用功能中是否缺少某些功能?

请尝试
h.db.Exec
而不是
h.db.Raw

谢谢!它起作用了。。。也许原始SQL执行在go gormI中有这样的限制。我简单地看了一下代码,Raw()不会立即执行任何东西。您必须对返回的句柄调用其他方法。因为这回答了您的问题,您介意将其标记为接受的答案@amandepmidha吗?我还发现它可以解决类似的问题。
numRecsToProcess := h.db.Raw("update chores set life_status ='Processing' where life_status = 'Active' and chore_type ='Shared' and money_assigned > ? ", 0).RowsAffected