Skip to content

Commit

Permalink
Merge c766087 into 7cb83a2
Browse files Browse the repository at this point in the history
  • Loading branch information
azaikin authored May 29, 2018
2 parents 7cb83a2 + c766087 commit 8082a06
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 8 deletions.
16 changes: 10 additions & 6 deletions conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,21 +211,25 @@ func (c *conn) doRequest(ctx context.Context, req *http.Request) ([]byte, error)

func (c *conn) buildRequest(query string, params []driver.Value, readonly bool) (*http.Request, error) {
var (
method string
err error
req *http.Request
err error
)
if params != nil {
if query, err = interpolateParams(query, params); err != nil {
return nil, err
}
}
c.log("query: ", query)
if readonly {
method = http.MethodGet
u := *c.url
q := u.Query()
q.Set("query", query)
u.RawQuery = q.Encode()
req, err = http.NewRequest(http.MethodGet, u.String(), nil)
} else {
method = http.MethodPost
req, err = http.NewRequest(http.MethodPost, c.url.String(), strings.NewReader(query))
}
c.log("query: ", query)
req, err := http.NewRequest(method, c.url.String(), strings.NewReader(query))

// http.Transport ignores url.User argument, handle it here
if err == nil && c.user != nil {
p, _ := c.user.Password()
Expand Down
2 changes: 1 addition & 1 deletion conn_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ func (s *connSuite) TestBuildRequestReadonlyWithAuth() {
s.Equal("user", user)
s.Equal("password", password)
s.Equal(http.MethodGet, req.Method)
s.Equal(cn.url.String(), req.URL.String())
s.Equal(cn.url.String() + "&query=SELECT+1", req.URL.String())
s.Nil(req.URL.User)
}
}
Expand Down
2 changes: 1 addition & 1 deletion errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ var (
ErrNoRowsAffected = errors.New("no RowsAffected available")
)

var errorRe = regexp.MustCompile(`Code: (\d+),.+DB::Exception: (.+),.*`)
var errorRe = regexp.MustCompile(`(?s)Code: (\d+),.+DB::Exception: (.+),.*`)

// Error contains parsed information about server error
type Error struct {
Expand Down

0 comments on commit 8082a06

Please sign in to comment.