Skip to content

Commit

Permalink
Merge pull request jmoiron#514 from bretep/master
Browse files Browse the repository at this point in the history
Fix batch INSERT when using ON CONFLICT
  • Loading branch information
jmoiron authored Apr 26, 2019
2 parents 1d3423c + c96cee4 commit 1ae93ed
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions named.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,21 +210,21 @@ func bindStruct(bindType int, query string, arg interface{}, m *reflectx.Mapper)
return bound, arglist, nil
}

var (
EndBracketsReg = regexp.MustCompile(`\([^()]*\)\s*$`)
)
var valueBracketReg = regexp.MustCompile(`\([^(]*\?+[^)]*\)`)

func fixBound(bound string, loop int) string {
endBrackets := EndBracketsReg.FindString(bound)
if endBrackets == "" {
loc := valueBracketReg.FindStringIndex(bound)
if len(loc) != 2 {
return bound
}
var buffer bytes.Buffer
buffer.WriteString(bound)

buffer.WriteString(bound[0:loc[1]])
for i := 0; i < loop-1; i++ {
buffer.WriteString(",")
buffer.WriteString(endBrackets)
buffer.WriteString(bound[loc[0]:loc[1]])
}
buffer.WriteString(bound[loc[1]:])
return buffer.String()
}

Expand Down

0 comments on commit 1ae93ed

Please sign in to comment.