Skip to content

Commit

Permalink
allow trailing spaces in bulk inseriton via named queries, fix #690
Browse files Browse the repository at this point in the history
  • Loading branch information
jmoiron committed Jan 28, 2021
1 parent 75a7ebf commit a1d5e64
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion named.go
Original file line number Diff line number Diff line change
Expand Up @@ -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*$`)

This comment has been minimized.

Copy link
@aarengee

aarengee Mar 2, 2021

Need to account for space , ; and other things people might want to do like ON CONFLICT etc.

Sorry for a lot of places I am posting this. Comment here

#667 (comment)

This comment has been minimized.

Copy link
@matthisk

matthisk Mar 3, 2021

Ran into the same issue, my ON CONFLICT ... bulk update queries broke in 1.3.1.


func fixBound(bound string, loop int) string {
loc := valueBracketReg.FindStringIndex(bound)
Expand Down
6 changes: 3 additions & 3 deletions named_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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{}
Expand All @@ -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 {
Expand Down

0 comments on commit a1d5e64

Please sign in to comment.