Skip to content

Commit 874a5d4

Browse files
committed
add more tolerance to fixBound regexp
1 parent 1723f86 commit 874a5d4

2 files changed

Lines changed: 14 additions & 1 deletion

File tree

named.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,9 +224,10 @@ func bindStruct(bindType int, query string, arg interface{}, m *reflectx.Mapper)
224224
return bound, arglist, nil
225225
}
226226

227-
var valueBracketReg = regexp.MustCompile(`VALUES\s+(\([^(]*.[^(]\))`)
227+
var valueBracketReg = regexp.MustCompile(`(?i)VALUES\s*(\([^(]*.[^(]\))`)
228228

229229
func fixBound(bound string, loop int) string {
230+
230231
loc := valueBracketReg.FindAllStringSubmatchIndex(bound, -1)
231232
// Either no VALUES () found or more than one found??
232233
if len(loc) != 1 {

named_test.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,18 @@ func TestFixBounds(t *testing.T) {
342342
expect: `INSERT INTO foo (a,b,c,d) VALUES (:name, :age, :first, :last) VALUES (:name, :age, :first, :last)`,
343343
loop: 2,
344344
},
345+
{
346+
name: `nospace`,
347+
query: `INSERT INTO foo (a,b) VALUES(:a, :b)`,
348+
expect: `INSERT INTO foo (a,b) VALUES(:a, :b),(:a, :b)`,
349+
loop: 2,
350+
},
351+
{
352+
name: `lowercase`,
353+
query: `INSERT INTO foo (a,b) values(:a, :b)`,
354+
expect: `INSERT INTO foo (a,b) values(:a, :b),(:a, :b)`,
355+
loop: 2,
356+
},
345357
}
346358

347359
for _, tc := range table {

0 commit comments

Comments
 (0)