-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #718 from abraithwaite/alan/fix-named-batch
NamedExec Bulk Insert Fix
- Loading branch information
Showing
2 changed files
with
87 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -224,21 +224,28 @@ func bindStruct(bindType int, query string, arg interface{}, m *reflectx.Mapper) | |
return bound, arglist, nil | ||
} | ||
|
||
var valueBracketReg = regexp.MustCompile(`\([^(]*.[^(]\)\s*$`) | ||
var valueBracketReg = regexp.MustCompile(`VALUES\s+(\([^(]*.[^(]\))`) | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
jmoiron
Author
Owner
|
||
|
||
func fixBound(bound string, loop int) string { | ||
loc := valueBracketReg.FindStringIndex(bound) | ||
if len(loc) != 2 { | ||
loc := valueBracketReg.FindAllStringSubmatchIndex(bound, -1) | ||
// Either no VALUES () found or more than one found?? | ||
if len(loc) != 1 { | ||
return bound | ||
} | ||
// defensive guard. loc should be len 4 representing the starting and | ||
// ending index for the whole regex match and the starting + ending | ||
// index for the single inside group | ||
if len(loc[0]) != 4 { | ||
return bound | ||
} | ||
var buffer bytes.Buffer | ||
|
||
buffer.WriteString(bound[0:loc[1]]) | ||
buffer.WriteString(bound[0:loc[0][1]]) | ||
for i := 0; i < loop-1; i++ { | ||
buffer.WriteString(",") | ||
buffer.WriteString(bound[loc[0]:loc[1]]) | ||
buffer.WriteString(bound[loc[0][2]:loc[0][3]]) | ||
} | ||
buffer.WriteString(bound[loc[1]:]) | ||
buffer.WriteString(bound[loc[0][1]:]) | ||
return buffer.String() | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This regularization is too strict, this leads to the failure of all the following cases: