Building dynamic update with SET? #272
-
An UPDATE statement is of the form:
But how would I add to this SET statement dynamically? I tried:
but this seems to overwrite the previous SET statement, i.e query, args := stmt.Sql() shows only 1 set statement (the latest) instead of 2 I also tried:
But I get:
FYI this is using the sqlite driver. I haven't tried with any other database. |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 3 replies
-
I did some further testing, to see if I could combine using a model with a set statement, but when I do so, there's a comma missing in the generated set statement, like this:
And it generated this:
|
Beta Was this translation helpful? Give feedback.
-
I found a workaround:
Would appreciate if anyone has any feedback on a better way of doing this |
Beta Was this translation helpful? Give feedback.
-
The recommended way is to use columnList := ColumnList{TestTable.TestColumn1}
modelValue := model.TestTable{TestColumn1:1}
stmt := TestTable.UPDATE(columnList).
MODEL(modelValue).
WHERE(...)
|
Beta Was this translation helpful? Give feedback.
-
In that case, you'll have to use your workaround. SET(TestTable.TestCol2.SET(TestTable.TestCol2.ADD(Int(2)))) |
Beta Was this translation helpful? Give feedback.
In that case, you'll have to use your workaround.
Also, there is no need for
SELECT
in your column assignment: