Skip to content

Commit

Permalink
Merge pull request #98 from Fiery-Fenix/master
Browse files Browse the repository at this point in the history
Fix parameters interpolation with empty params
  • Loading branch information
DoubleDi committed Jul 2, 2020
2 parents 433b4a0 + abcb88b commit e482166
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion conn.go
Expand Up @@ -286,7 +286,7 @@ func (c *conn) buildRequest(ctx context.Context, query string, params []driver.V
method string
err error
)
if params != nil {
if params != nil && len(params) > 0 {
if query, err = interpolateParams(query, params); err != nil {
return nil, err
}
Expand Down
13 changes: 13 additions & 0 deletions conn_test.go
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"database/sql"
"database/sql/driver"
"io/ioutil"
"net/http"
"testing"
"time"
Expand Down Expand Up @@ -367,6 +368,18 @@ func (s *connSuite) TestBuildRequestWithQueryIdAndQuotaKey() {
}
}
}
func (s *connSuite) TestBuildRequestParamsInterpolation() {
query := `INSERT INTO test (str) VALUES ("Question?")`
cn := newConn(NewConfig())
req, err := cn.buildRequest(context.Background(), query, make([]driver.Value, 0), false)
if s.NoError(err) {
body, e := ioutil.ReadAll(req.Body)
if s.NoError(e) {
s.Equal(query, string(body))
}
}
}

func TestConn(t *testing.T) {
suite.Run(t, new(connSuite))
}

0 comments on commit e482166

Please sign in to comment.