From 9a5a859c98d950016377348d2b8600dc0929e438 Mon Sep 17 00:00:00 2001 From: Simon Vieille Date: Tue, 19 Mar 2024 16:41:39 +0100 Subject: [PATCH] fix query builder and named params --- app/app.go | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/app/app.go b/app/app.go index a8adf16..8db93b9 100644 --- a/app/app.go +++ b/app/app.go @@ -136,16 +136,19 @@ func (a *App) DoAction(c config.SchemaConfigAction, globalColumns map[string]str for _, row := range rows { updates := []string{} pkeys := []string{} + values := make(map[int]string) pCounter := 1 for col, value := range row { - if value.IsUpdated { + if value.IsUpdated && !value.IsVirtual { + values[pCounter] = value.Value updates = append(updates, fmt.Sprintf("%s=:p%s", col, strconv.Itoa(pCounter))) pCounter = pCounter + 1 } } for _, col := range c.PrimaryKey { + values[pCounter] = row[col].Value pkeys = append(pkeys, fmt.Sprintf("%s=:p%s", col, strconv.Itoa(pCounter))) pCounter = pCounter + 1 } @@ -161,16 +164,8 @@ func (a *App) DoAction(c config.SchemaConfigAction, globalColumns map[string]str stmt := nq.NewNamedParameterQuery(sql) pCounter = 1 - for _, value := range row { - if value.IsUpdated { - stmt.SetValue(fmt.Sprintf("p%s", strconv.Itoa(pCounter)), value.Value) - pCounter = pCounter + 1 - } - } - - for _, col := range c.PrimaryKey { - stmt.SetValue(fmt.Sprintf("p%s", strconv.Itoa(pCounter)), row[col].Value) - pCounter = pCounter + 1 + for i, value := range values { + stmt.SetValue(fmt.Sprintf("p%s", strconv.Itoa(i)), value) } a.Db.QueryRow(stmt.GetParsedQuery(), (stmt.GetParsedParameters())...).Scan(&scan)