Skip to content

Commit b816f3d

Browse files
randomjunkjulienschmidt
authored andcommitted
Fix Valuers by returning driver.ErrSkip if couldn't convert type internally (#709)
Fixes #708
1 parent 78d399c commit b816f3d

File tree

3 files changed

+36
-1
lines changed

3 files changed

+36
-1
lines changed

AUTHORS

+1
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ Zhenye Xie <xiezhenye at gmail.com>
7171
# Organizations
7272

7373
Barracuda Networks, Inc.
74+
Counting Ltd.
7475
Google Inc.
7576
Keybase Inc.
7677
Pivotal Inc.

connection_go18.go

+5-1
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,10 @@ func (mc *mysqlConn) startWatcher() {
197197
}
198198

199199
func (mc *mysqlConn) CheckNamedValue(nv *driver.NamedValue) (err error) {
200-
nv.Value, err = converter{}.ConvertValue(nv.Value)
200+
value, err := converter{}.ConvertValue(nv.Value)
201+
if err != nil {
202+
return driver.ErrSkip
203+
}
204+
nv.Value = value
201205
return
202206
}

driver_test.go

+30
Original file line numberDiff line numberDiff line change
@@ -499,6 +499,36 @@ func TestString(t *testing.T) {
499499
})
500500
}
501501

502+
type testValuer struct {
503+
value string
504+
}
505+
506+
func (tv testValuer) Value() (driver.Value, error) {
507+
return tv.value, nil
508+
}
509+
510+
func TestValuer(t *testing.T) {
511+
runTests(t, dsn, func(dbt *DBTest) {
512+
in := testValuer{"a_value"}
513+
var out string
514+
var rows *sql.Rows
515+
516+
dbt.mustExec("CREATE TABLE test (value VARCHAR(255)) CHARACTER SET utf8")
517+
dbt.mustExec("INSERT INTO test VALUES (?)", in)
518+
rows = dbt.mustQuery("SELECT value FROM test")
519+
if rows.Next() {
520+
rows.Scan(&out)
521+
if in.value != out {
522+
dbt.Errorf("Valuer: %v != %s", in, out)
523+
}
524+
} else {
525+
dbt.Errorf("Valuer: no data")
526+
}
527+
528+
dbt.mustExec("DROP TABLE IF EXISTS test")
529+
})
530+
}
531+
502532
type timeTests struct {
503533
dbtype string
504534
tlayout string

0 commit comments

Comments
 (0)