From a1d5e64734233358bc4e0a54beddc18509071a95 Mon Sep 17 00:00:00 2001 From: Jason Moiron Date: Thu, 28 Jan 2021 16:15:50 -0500 Subject: [PATCH] allow trailing spaces in bulk inseriton via named queries, fix #690 --- named.go | 2 +- named_test.go | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/named.go b/named.go index 276ed568..2a96e8ed 100644 --- a/named.go +++ b/named.go @@ -224,7 +224,7 @@ func bindStruct(bindType int, query string, arg interface{}, m *reflectx.Mapper) return bound, arglist, nil } -var valueBracketReg = regexp.MustCompile(`\([^(]*.[^(]\)$`) +var valueBracketReg = regexp.MustCompile(`\([^(]*.[^(]\)\s*$`) func fixBound(bound string, loop int) string { loc := valueBracketReg.FindStringIndex(bound) diff --git a/named_test.go b/named_test.go index 24b725b2..0cb4088b 100644 --- a/named_test.go +++ b/named_test.go @@ -202,7 +202,7 @@ func TestNamedQueries(t *testing.T) { {FirstName: "Ngani", LastName: "Laumape", Email: "nlaumape@ab.co.nz"}, } - insert := fmt.Sprintf("INSERT INTO person (first_name, last_name, email, added_at) VALUES (:first_name, :last_name, :email, %v)", now) + insert := fmt.Sprintf("INSERT INTO person (first_name, last_name, email, added_at) VALUES (:first_name, :last_name, :email, %v)\n", now) _, err = db.NamedExec(insert, sls) test.Error(err) @@ -214,7 +214,7 @@ func TestNamedQueries(t *testing.T) { } _, err = db.NamedExec(`INSERT INTO person (first_name, last_name, email) - VALUES (:first_name, :last_name, :email)`, slsMap) + VALUES (:first_name, :last_name, :email) `, slsMap) test.Error(err) type A map[string]interface{} @@ -226,7 +226,7 @@ func TestNamedQueries(t *testing.T) { } _, err = db.NamedExec(`INSERT INTO person (first_name, last_name, email) - VALUES (:first_name, :last_name, :email)`, typedMap) + VALUES (:first_name, :last_name, :email) `, typedMap) test.Error(err) for _, p := range sls {