Skip to content

Commit

Permalink
sql/mysql: ensure parseTime is always set (#1135)
Browse files Browse the repository at this point in the history
  • Loading branch information
masseelch authored Sep 8, 2022
1 parent 7767c1b commit d5e4fdd
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
4 changes: 3 additions & 1 deletion sql/mysql/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,9 @@ type parser struct{}

// ParseURL implements the sqlclient.URLParser interface.
func (parser) ParseURL(u *url.URL) *sqlclient.URL {
u.Query().Set("parseTime", "true")
v := u.Query()
v.Set("parseTime", "true")
u.RawQuery = v.Encode()
return &sqlclient.URL{URL: u, DSN: dsn(u), Schema: strings.TrimPrefix(u.Path, "/")}
}

Expand Down
8 changes: 8 additions & 0 deletions sql/mysql/driver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ package mysql
import (
"context"
"database/sql"
"net/url"
"testing"
"time"

Expand All @@ -18,6 +19,13 @@ import (
"github.com/stretchr/testify/require"
)

func TestParser_ParseURLParseTime(t *testing.T) {
u, err := url.Parse("mysql://user:pass@localhost:3306/my_db?foo=bar")
require.NoError(t, err)
ac := parser{}.ParseURL(u)
require.Equal(t, "true", ac.Query().Get("parseTime"))
}

func TestDriver_LockAcquired(t *testing.T) {
db, m, err := sqlmock.New()
require.NoError(t, err)
Expand Down

0 comments on commit d5e4fdd

Please sign in to comment.