| 243 | } |
| 244 | |
| 245 | func fixBound(bound string, loop int) string { |
| 246 | loc := valuesReg.FindStringIndex(bound) |
| 247 | // defensive guard when "VALUES (...)" not found |
| 248 | if len(loc) < 2 { |
| 249 | return bound |
| 250 | } |
| 251 | |
| 252 | openingBracketIndex := loc[1] - 1 |
| 253 | index := findMatchingClosingBracketIndex(bound[openingBracketIndex:]) |
| 254 | // defensive guard. must have closing bracket |
| 255 | if index == 0 { |
| 256 | return bound |
| 257 | } |
| 258 | closingBracketIndex := openingBracketIndex + index + 1 |
| 259 | |
| 260 | var buffer bytes.Buffer |
| 261 | |
| 262 | buffer.WriteString(bound[0:closingBracketIndex]) |
| 263 | for i := 0; i < loop-1; i++ { |
| 264 | buffer.WriteString(",") |
| 265 | buffer.WriteString(bound[openingBracketIndex:closingBracketIndex]) |
| 266 | } |
| 267 | buffer.WriteString(bound[closingBracketIndex:]) |
| 268 | return buffer.String() |
| 269 | } |
| 270 | |
| 271 | // bindArray binds a named parameter query with fields from an array or slice of |
| 272 | // structs argument. |