Skip to content

Fix Valuers by returning driver.ErrSkip if couldn't convert type internally #709

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 16, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ Zhenye Xie <xiezhenye at gmail.com>
# Organizations

Barracuda Networks, Inc.
Counting Ltd.
Google Inc.
Keybase Inc.
Pivotal Inc.
Expand Down
6 changes: 5 additions & 1 deletion connection_go18.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,10 @@ func (mc *mysqlConn) startWatcher() {
}

func (mc *mysqlConn) CheckNamedValue(nv *driver.NamedValue) (err error) {
nv.Value, err = converter{}.ConvertValue(nv.Value)
value, err := converter{}.ConvertValue(nv.Value)
if err != nil {
return driver.ErrSkip
}
nv.Value = value
return
}
30 changes: 30 additions & 0 deletions driver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -499,6 +499,36 @@ func TestString(t *testing.T) {
})
}

type testValuer struct {
value string
}

func (tv testValuer) Value() (driver.Value, error) {
return tv.value, nil
}

func TestValuer(t *testing.T) {
runTests(t, dsn, func(dbt *DBTest) {
in := testValuer{"a_value"}
var out string
var rows *sql.Rows

dbt.mustExec("CREATE TABLE test (value VARCHAR(255)) CHARACTER SET utf8")
dbt.mustExec("INSERT INTO test VALUES (?)", in)
rows = dbt.mustQuery("SELECT value FROM test")
if rows.Next() {
rows.Scan(&out)
if in.value != out {
dbt.Errorf("Valuer: %v != %s", in, out)
}
} else {
dbt.Errorf("Valuer: no data")
}

dbt.mustExec("DROP TABLE IF EXISTS test")
})
}

type timeTests struct {
dbtype string
tlayout string
Expand Down