Skip to content

Commit

Permalink
Add arguments count check to execParamsAndPreparedPrefix
Browse files Browse the repository at this point in the history
  • Loading branch information
malstoun committed Jan 4, 2020
1 parent 9cb58fc commit 8dc8431
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
4 changes: 4 additions & 0 deletions conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -501,6 +501,10 @@ func (c *Conn) execSimpleProtocol(ctx context.Context, sql string, arguments []i
}

func (c *Conn) execParamsAndPreparedPrefix(sd *pgconn.StatementDescription, arguments []interface{}) error {
if len(sd.ParamOIDs) != len(arguments) {
return errors.Errorf("expected %d arguments, got %d", len(sd.ParamOIDs), len(arguments))
}

c.eqb.Reset()

args, err := convertDriverValuers(arguments)
Expand Down
6 changes: 6 additions & 0 deletions conn_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,12 @@ func TestExecFailureWithArguments(t *testing.T) {
t.Fatal("Expected SQL syntax error")
}
assert.False(t, pgconn.SafeToRetry(err))

_, err = conn.Exec(context.Background(), "select $1::varchar(1);", "1", "2")
if err == nil {
t.Fatal("Expected pgx arguments count error", err)
}
assert.Equal(t, "expected 1 arguments, got 2", err.Error())
}

func TestExecContextWithoutCancelation(t *testing.T) {
Expand Down

0 comments on commit 8dc8431

Please sign in to comment.