forked from deblan/database-anonymizer
fix query builder and named params
This commit is contained in:
parent
338d50c79f
commit
9a5a859c98
1 changed files with 6 additions and 11 deletions
17
app/app.go
17
app/app.go
|
|
@ -136,16 +136,19 @@ func (a *App) DoAction(c config.SchemaConfigAction, globalColumns map[string]str
|
||||||
for _, row := range rows {
|
for _, row := range rows {
|
||||||
updates := []string{}
|
updates := []string{}
|
||||||
pkeys := []string{}
|
pkeys := []string{}
|
||||||
|
values := make(map[int]string)
|
||||||
pCounter := 1
|
pCounter := 1
|
||||||
|
|
||||||
for col, value := range row {
|
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)))
|
updates = append(updates, fmt.Sprintf("%s=:p%s", col, strconv.Itoa(pCounter)))
|
||||||
pCounter = pCounter + 1
|
pCounter = pCounter + 1
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, col := range c.PrimaryKey {
|
for _, col := range c.PrimaryKey {
|
||||||
|
values[pCounter] = row[col].Value
|
||||||
pkeys = append(pkeys, fmt.Sprintf("%s=:p%s", col, strconv.Itoa(pCounter)))
|
pkeys = append(pkeys, fmt.Sprintf("%s=:p%s", col, strconv.Itoa(pCounter)))
|
||||||
pCounter = pCounter + 1
|
pCounter = pCounter + 1
|
||||||
}
|
}
|
||||||
|
|
@ -161,16 +164,8 @@ func (a *App) DoAction(c config.SchemaConfigAction, globalColumns map[string]str
|
||||||
stmt := nq.NewNamedParameterQuery(sql)
|
stmt := nq.NewNamedParameterQuery(sql)
|
||||||
pCounter = 1
|
pCounter = 1
|
||||||
|
|
||||||
for _, value := range row {
|
for i, value := range values {
|
||||||
if value.IsUpdated {
|
stmt.SetValue(fmt.Sprintf("p%s", strconv.Itoa(i)), value)
|
||||||
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
|
|
||||||
}
|
}
|
||||||
|
|
||||||
a.Db.QueryRow(stmt.GetParsedQuery(), (stmt.GetParsedParameters())...).Scan(&scan)
|
a.Db.QueryRow(stmt.GetParsedQuery(), (stmt.GetParsedParameters())...).Scan(&scan)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue