Skip to content

database/sql: different handling of underlying types in DefaultParameterConverter #15174

Closed
@AlekSi

Description

@AlekSi

After e405c29 (#11489) DefaultParameterConverter documentation says:

// DefaultParameterConverter returns its argument directly if
// IsValue(arg). Otherwise, if the argument implements Valuer, its
// Value method is used to return a Value. As a fallback, the provided
// argument's underlying type is used to convert it to a Value:
// underlying integer types are converted to int64, floats to float64,
// and strings to []byte. If the argument is a nil pointer,
// ConvertValue returns a nil Value. If the argument is a non-nil
// pointer, it is dereferenced and ConvertValue is called
// recursively. Other types are an error.

Underlying integers are really converted to int64, but underlying strings are not in fact converted – there is no code for this.

Testcase: https://github.com/AlekSi/go-sql-bugs/blob/master/issue15174_test.go
Test output: https://travis-ci.org/AlekSi/go-sql-bugs/builds/121408329 (see 1.6 and tip)

I propose to do what documentation says and convert the underlying string to []byte, it will help with custom string-like types with constants (enums).
Also, can we do the same thing for bools?

/cc @bradfitz

Metadata

Metadata

Assignees

No one assigned

    Labels

    FrozenDueToAgeNeedsFixThe path to resolution is known, but the work has not been done.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions