Fix NULL values returned as driver.Value
fiorix opened this issue · 0 comments
fiorix commented
The current typeConverter.ConvertValue
function always return the default value for types, as opposed to nil, which causes types such as sql.Null*
to always have Valid=true
even when the value returned by the query is NULL.
e.g.
// ConvertValue implements the driver.ValueConverter interface.
func (c *typeConverter) ConvertValue(v interface{}) (driver.Value, error) {
switch c.parsedType[0] {
case "boolean":
vv, err := scanNullBool(v)
return vv.Bool, err
The last line causes the returned sql.NullBool
to always be valid. In order to fix, we have to:
if !vv.Valid { return nil, err }
Our integration tests for type conversion should test this. I found this by accident.