diff --git a/RELEASENOTES.md b/RELEASENOTES.md index 67acfe8..65b630f 100644 --- a/RELEASENOTES.md +++ b/RELEASENOTES.md @@ -5,6 +5,9 @@ Release Notes ### Minor revisions +#### v1.12.11 +- go1.24 preparation + #### v1.12.10 - updated dependencies diff --git a/driver/convert.go b/driver/convert.go index e2b9f21..5d79594 100644 --- a/driver/convert.go +++ b/driver/convert.go @@ -24,15 +24,92 @@ func reorderNVArgs(pos int, name string, nvargs []driver.NamedValue) { } } -// This function is take from the database/sql package. -// The Elem() test is not needed bacause the function is only -// called for values implementing the driver.Valuer interface. -func callValuerValue(vr driver.Valuer) (v driver.Value, err error) { - if rv := reflect.ValueOf(vr); rv.Kind() == reflect.Pointer && rv.IsNil() { +func valuerValue(v driver.Valuer) (driver.Value, error) { + // This is taken from the database/sql package. + // The Elem() test is not needed bacause the function is only + // called for values implementing the driver.Valuer interface. + if rv := reflect.ValueOf(v); rv.Kind() == reflect.Pointer && rv.IsNil() { // && rv.Type().Elem().Implements(valuerReflectType) { return nil, nil } - return vr.Value() + /* + func (n Null[T]) Value() (driver.Value, error) { + if !n.Valid { + return nil, nil + } + return n.V, nil + } + */ + // changes in sql.Null Value handling + // <= go1.23 + + // >= 1.24 + /* + func (n Null[T]) Value() (driver.Value, error) { + if !n.Valid { + return nil, nil + } + v := any(n.V) + // See issue 69728. + if valuer, ok := v.(driver.Valuer); ok { + val, err := callValuerValue(valuer) + if err != nil { + return val, err + } + v = val + } + // See issue 69837. + return driver.DefaultParameterConverter.ConvertValue(v) + } + */ + // As sql.Null Value is now calling the default converter this totally breaks + // the generic usage on custom data types. + // Therefore we do need to handle custom types ourselves. + + switch v := v.(type) { + case sql.Null[Decimal]: + if !v.Valid { + return nil, nil + } + return v.V, nil + case sql.Null[*Decimal]: + if !v.Valid { + return nil, nil + } + return v.V, nil + case *sql.Null[Decimal]: + if !v.Valid { + return nil, nil + } + return v.V, nil + case *sql.Null[*Decimal]: + if !v.Valid { + return nil, nil + } + return v.V, nil + case sql.Null[Lob]: + if !v.Valid { + return nil, nil + } + return v.V, nil + case sql.Null[*Lob]: + if !v.Valid { + return nil, nil + } + return v.V, nil + case *sql.Null[Lob]: + if !v.Valid { + return nil, nil + } + return v.V, nil + case *sql.Null[*Lob]: + if !v.Valid { + return nil, nil + } + return v.V, nil + default: + return v.Value() + } } func convertArg(field *p.ParameterField, arg any, cesu8Encoder transform.Transformer) (any, error) { @@ -44,8 +121,7 @@ func convertArg(field *p.ParameterField, arg any, cesu8Encoder transform.Transfo break } var err error - arg, err = callValuerValue(valuer) - if err != nil { + if arg, err = valuerValue(valuer); err != nil { return nil, err } } diff --git a/driver/datatypenull_test.go b/driver/datatypenull_test.go index 446d2a8..3824837 100644 --- a/driver/datatypenull_test.go +++ b/driver/datatypenull_test.go @@ -1,4 +1,4 @@ -//go:build !unit && go1.22 +//go:build !unit package driver diff --git a/driver/driver.go b/driver/driver.go index 860cb3c..43b734b 100644 --- a/driver/driver.go +++ b/driver/driver.go @@ -10,7 +10,7 @@ import ( ) // DriverVersion is the version number of the hdb driver. -const DriverVersion = "1.12.10" +const DriverVersion = "1.12.11" // DriverName is the driver name to use with sql.Open for hdb databases. const DriverName = "hdb"