MCPcopy
hub / github.com/jmoiron/sqlx / fixBound

Function fixBound

named.go:245–269  ·  view source on GitHub ↗
(bound string, loop int)

Source from the content-addressed store, hash-verified

243}
244
245func 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.

Callers 2

TestFixBoundsFunction · 0.85
bindArrayFunction · 0.85

Calls 2

StringMethod · 0.80

Tested by 1

TestFixBoundsFunction · 0.68