From 874a5d4c14788a7ade895f913e4ae947a6354922 Mon Sep 17 00:00:00 2001 From: Jason Moiron Date: Wed, 7 Apr 2021 23:38:04 -0400 Subject: [PATCH] add more tolerance to fixBound regexp --- named.go | 3 ++- named_test.go | 12 ++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/named.go b/named.go index 11a68e0c..1f416121 100644 --- a/named.go +++ b/named.go @@ -224,9 +224,10 @@ func bindStruct(bindType int, query string, arg interface{}, m *reflectx.Mapper) return bound, arglist, nil } -var valueBracketReg = regexp.MustCompile(`VALUES\s+(\([^(]*.[^(]\))`) +var valueBracketReg = regexp.MustCompile(`(?i)VALUES\s*(\([^(]*.[^(]\))`) func fixBound(bound string, loop int) string { + loc := valueBracketReg.FindAllStringSubmatchIndex(bound, -1) // Either no VALUES () found or more than one found?? if len(loc) != 1 { diff --git a/named_test.go b/named_test.go index f5545d51..70bc4484 100644 --- a/named_test.go +++ b/named_test.go @@ -342,6 +342,18 @@ func TestFixBounds(t *testing.T) { expect: `INSERT INTO foo (a,b,c,d) VALUES (:name, :age, :first, :last) VALUES (:name, :age, :first, :last)`, loop: 2, }, + { + name: `nospace`, + query: `INSERT INTO foo (a,b) VALUES(:a, :b)`, + expect: `INSERT INTO foo (a,b) VALUES(:a, :b),(:a, :b)`, + loop: 2, + }, + { + name: `lowercase`, + query: `INSERT INTO foo (a,b) values(:a, :b)`, + expect: `INSERT INTO foo (a,b) values(:a, :b),(:a, :b)`, + loop: 2, + }, } for _, tc := range table {