From 8919bafb3af724de4021854ac374fde7f1911f7f Mon Sep 17 00:00:00 2001 From: Gibheer Date: Thu, 5 Sep 2024 19:14:20 +0200 Subject: fix broken SQL update This fixes a bug in the generation of the SQL query, that was introduced in 49dac92034f352698429ee1d78d4bfb070006693. There were two issues with the generation: 1. the check ids were sometimes not added to the arguments 2. the whereVals were not extracted as arguments This lead to all arguments being treated as one, which caused all sorts of errors in the frontend. By extracting all whereVals and always building it with the check ids first the update starts working correctly again. Found-By: Parsa Yousefi --- cmd/monfront/main.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'cmd/monfront') diff --git a/cmd/monfront/main.go b/cmd/monfront/main.go index 68138fc..f8d8ee7 100644 --- a/cmd/monfront/main.go +++ b/cmd/monfront/main.go @@ -366,14 +366,14 @@ func checkAction(con *Context) { } sql := "update " + setTable + " set " + setClause + " where " + whereColumn + " = any($1::bigint[])" + whereVals = append([]any{pq.Array(&checks)}, whereVals...) if len(whereFields) > 0 { - whereVals = append([]any{pq.Array(&checks)}, whereVals...) for i, column := range whereFields { sql = sql + " and " + column + fmt.Sprintf(" = $%d", i+1) } } - _, err := DB.Exec(sql, whereVals) + _, err := DB.Exec(sql, whereVals...) if err != nil { con.w.WriteHeader(http.StatusInternalServerError) fmt.Fprintf(con.w, "could not store changes") -- cgit v1.2.3-70-g09d2