Skip to content

Commit

Permalink
v1.12.11
Browse files Browse the repository at this point in the history
  • Loading branch information
stfnmllr committed Jan 28, 2025
1 parent 2184a3e commit 738b4e1
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 10 deletions.
3 changes: 3 additions & 0 deletions RELEASENOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ Release Notes

### Minor revisions

#### v1.12.11
- go1.24 preparation

#### v1.12.10
- updated dependencies

Expand Down
92 changes: 84 additions & 8 deletions driver/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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
}
}
Expand Down
2 changes: 1 addition & 1 deletion driver/datatypenull_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//go:build !unit && go1.22
//go:build !unit

package driver

Expand Down
2 changes: 1 addition & 1 deletion driver/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 738b4e1

Please sign in to comment.