Skip to content

Commit

Permalink
v1.10.5
Browse files Browse the repository at this point in the history
  • Loading branch information
stfnmllr committed Aug 14, 2024
1 parent 29da4d1 commit 6d4dc4d
Show file tree
Hide file tree
Showing 17 changed files with 135 additions and 33 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
- name: Setup go
uses: actions/setup-go@v5
with:
go-version: '1.22'
go-version: '1.23'

- name: Vet
run: |
Expand All @@ -30,7 +30,7 @@ jobs:
matrix:
goos: [linux]
goarch: [amd64, arm, arm64, s390x]
go: ['1.22.6', '1.21.13']
go: ['1.23.0', '1.22.6', '1.21.13']
fail-fast: false

name: Go ${{ matrix.go }} ${{ matrix.goos }} ${{ matrix.goarch }} build
Expand Down Expand Up @@ -71,7 +71,7 @@ jobs:
runs-on: macos-latest
strategy:
matrix:
go: ['1.22.6', '1.21.13']
go: ['1.23.0', '1.22.6', '1.21.13']
fail-fast: false

name: Go ${{ matrix.go }} macOS
Expand Down Expand Up @@ -104,7 +104,7 @@ jobs:
runs-on: windows-latest
strategy:
matrix:
go: ['1.22.6', '1.21.13']
go: ['1.23.0', '1.22.6', '1.21.13']
fail-fast: false

name: Go ${{ matrix.go }} Windows
Expand Down
8 changes: 4 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ all:
go test ./...
go test ./... -race
@echo execute tests on older supported go versions
GOTOOLCHAIN=go1.22.6 go1.22.6 test ./...
GOTOOLCHAIN=go1.22.6 go1.22.6 test ./... -race
GOTOOLCHAIN=go1.21.13 go1.21.13 test ./...
GOTOOLCHAIN=go1.21.13 go1.21.13 test ./... -race
@echo execute tests on future supported go versions
GOTOOLCHAIN=go1.23rc2 go1.23rc2 test ./...
GOTOOLCHAIN=go1.23rc2 go1.23rc2 test ./... -race
#see fsfe reuse tool (https://git.fsfe.org/reuse/tool)
#on linux: if pipx uses outdated packages, delete ~/.local/pipx/cache entries
@echo "reuse (license) check"
Expand Down Expand Up @@ -45,7 +45,7 @@ tools:

#install additional go versions
go:
go install golang.org/dl/go1.22.6@latest
go1.22.6 download
go install golang.org/dl/go1.21.13@latest
go1.21.13 download
go install golang.org/dl/go1.23rc2@latest
go1.23rc2 download
3 changes: 3 additions & 0 deletions RELEASENOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ Release Notes

## v1.10.0

#### v1.10.5
- fixed bug in converting integer arguments to HANA boolean type

#### v1.10.4
- fixed bug (panic) in go-hdb/driver/stmt.go function execCall on calling stored procedures with table output parameters without providing arguments (args)

Expand Down
4 changes: 2 additions & 2 deletions cmd/bulkbench/benchmark_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ func Benchmark(b *testing.B) {

f := func(b *testing.B, sequential bool, batchCount, batchSize int) {
ds := make([]time.Duration, b.N)
var avg, max time.Duration
min := maxDuration
var avg, max time.Duration //nolint: predeclared
min := maxDuration //nolint: predeclared

for i := 0; i < b.N; i++ {
tr := ts.execute(sequential, batchCount, batchSize, drop)
Expand Down
6 changes: 4 additions & 2 deletions driver/connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,10 @@ var (
)

// connection hook for testing.
// use unexported var to avoid key collisions.
var connHookCtxKey struct{}
// use unexported type to avoid key collisions.
type connHookCtxKeyType struct{}

var connHookCtxKey connHookCtxKeyType

// ...connection hook operations.
const (
Expand Down
2 changes: 1 addition & 1 deletion driver/datatype_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,7 @@ func maxValue(prec int) *big.Rat {
}

func minValue(prec int) *big.Rat {
max := maxValue(prec)
max := maxValue(prec) //nolint: predeclared
return max.Neg(max)
}

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.10.4"
const DriverVersion = "1.10.5"

// DriverName is the driver name to use with sql.Open for hdb databases.
const DriverName = "hdb"
Expand Down
4 changes: 2 additions & 2 deletions driver/dsn.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,10 @@ func parameterNotSupportedError(k string) error {
func invalidNumberOfParametersError(k string, act, exp int) error { //nolint:unparam
return &ParseError{s: fmt.Sprintf("invalid number of parameters for %s %d - expected %d", k, act, exp)}
}
func invalidNumberOfParametersRangeError(k string, act, min, max int) error {
func invalidNumberOfParametersRangeError(k string, act, min, max int) error { //nolint: predeclared
return &ParseError{s: fmt.Sprintf("invalid number of parameters for %s %d - expected %d - %d", k, act, min, max)}
}
func invalidNumberOfParametersMinError(k string, act, min int) error {
func invalidNumberOfParametersMinError(k string, act, min int) error { //nolint: predeclared
return &ParseError{s: fmt.Sprintf("invalid number of parameters for %s %d - expected at least %d", k, act, min)}
}
func parseError(k, v string) error {
Expand Down
30 changes: 27 additions & 3 deletions driver/internal/protocol/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,34 @@ Conversion routines hdb parameters
*/

func convertBool(v any) (any, error) {
// check needs to be done on each type individually as if combining types in one case
// the v type stays on any and the comparison v != 0 would always be true.
switch v := v.(type) {
case bool:
return v, nil
case int, int8, int16, int32, int64, uint, uint8, uint16, uint32, uint64, float32, float64:
case int:
return v != 0, nil
case int8:
return v != 0, nil
case int16:
return v != 0, nil
case int32:
return v != 0, nil
case int64:
return v != 0, nil
case uint:
return v != 0, nil
case uint8:
return v != 0, nil
case uint16:
return v != 0, nil
case uint32:
return v != 0, nil
case uint64:
return v != 0, nil
case float32:
return v != 0, nil
case float64:
return v != 0, nil
case string:
return strconv.ParseBool(v)
Expand Down Expand Up @@ -88,7 +112,7 @@ var (
i64One = int64(1)
)

func convertInteger(v any, min, max int64) (any, error) { //nolint: gocyclo
func convertInteger(v any, min, max int64) (any, error) { //nolint: gocyclo, predeclared
switch v := v.(type) {
case bool:
if v {
Expand Down Expand Up @@ -256,7 +280,7 @@ var (
f64One = float64(1.0)
)

func convertFloat(v any, max float64) (any, error) { //nolint: gocyclo
func convertFloat(v any, max float64) (any, error) { //nolint: gocyclo, predeclared
switch v := v.(type) {
case float32:
f64 := float64(v)
Expand Down
69 changes: 69 additions & 0 deletions driver/internal/protocol/convert_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,74 @@ import (
"time"
)

func assertEqualBool(t *testing.T, v any, r bool) {
cv, err := convertField(tcBoolean, v, nil)
if err != nil {
t.Fatal(err)
}

rv := reflect.ValueOf(cv)
switch rv.Kind() {
case reflect.Bool:
if rv.Bool() != r {
t.Fatalf("assert equal bool failed %v - %t expected", cv, r)
}
default:
t.Fatalf("invalid type %[1]T %[1]v", cv)
}
}

func testConvertBool(t *testing.T) {
type testCustomBool bool

// bool data types

assertEqualBool(t, true, true)
assertEqualBool(t, false, false)

assertEqualBool(t, uint(0), false)
assertEqualBool(t, uint8(0), false)
assertEqualBool(t, uint16(0), false)
assertEqualBool(t, uint32(0), false)
assertEqualBool(t, uint64(0), false)

assertEqualBool(t, int(0), false)
assertEqualBool(t, int8(0), false)
assertEqualBool(t, int16(0), false)
assertEqualBool(t, int32(0), false)
assertEqualBool(t, int64(0), false)

assertEqualBool(t, uint(1), true)
assertEqualBool(t, uint8(1), true)
assertEqualBool(t, uint16(1), true)
assertEqualBool(t, uint32(1), true)
assertEqualBool(t, uint64(1), true)

assertEqualBool(t, int(1), true)
assertEqualBool(t, int8(1), true)
assertEqualBool(t, int16(1), true)
assertEqualBool(t, int32(1), true)
assertEqualBool(t, int64(1), true)

assertEqualBool(t, float32(0), false)
assertEqualBool(t, float64(0), false)

assertEqualBool(t, float32(1), true)
assertEqualBool(t, float64(1), true)

// custom integer data type
assertEqualBool(t, testCustomBool(false), false)
assertEqualBool(t, testCustomBool(true), true)

// boolean reference
b := false
assertEqualBool(t, &b, false)

// boolean as string
assertEqualBool(t, "false", false)
assertEqualBool(t, "true", true)
}

func assertEqualInt(t *testing.T, tc typeCode, v any, r int64) { //nolint:unparam
cv, err := convertField(tc, v, nil)
if err != nil {
Expand Down Expand Up @@ -198,6 +266,7 @@ func TestConverter(t *testing.T) {
name string
fct func(t *testing.T)
}{
{"convertBool", testConvertBool},
{"convertInteger", testConvertInteger},
{"convertFloat", testConvertFloat},
{"convertTime", testConvertTime},
Expand Down
4 changes: 2 additions & 2 deletions driver/internal/protocol/encoding/decimal.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,8 +212,8 @@ func convertRatToFixed(r *big.Rat, m *big.Int, prec, scale int) byte {
}
}

max := exp10(prec)
min := new(big.Int).Neg(max)
max := exp10(prec) //nolint: predeclared
min := new(big.Int).Neg(max) //nolint: predeclared

if m.Cmp(min) <= 0 || m.Cmp(max) >= 0 {
df |= dfOverflow
Expand Down
6 changes: 3 additions & 3 deletions driver/internal/protocol/encoding/decode.go
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ func (d *Decoder) decodeTime() (int, int, int, int, bool) {
hour := d.Byte()
null := (hour & 0x80) == 0 // null value
hour &= 0x7f
min := d.Int8()
min := d.Int8() //nolint: predeclared
msec := d.Uint16()

sec := msec / 1000
Expand All @@ -424,7 +424,7 @@ func (d *Decoder) decodeTime() (int, int, int, int, bool) {
// TimeField decodes a time field.
func (d *Decoder) TimeField() (any, error) {
// time read gives only seconds (cut), no milliseconds
hour, min, sec, nsec, null := d.decodeTime()
hour, min, sec, nsec, null := d.decodeTime() //nolint: predeclared
if null {
return nil, nil
}
Expand All @@ -434,7 +434,7 @@ func (d *Decoder) TimeField() (any, error) {
// TimestampField decodes a timestamp field.
func (d *Decoder) TimestampField() (any, error) {
year, month, day, dateNull := d.decodeDate()
hour, min, sec, nsec, timeNull := d.decodeTime()
hour, min, sec, nsec, timeNull := d.decodeTime() //nolint: predeclared
if dateNull || timeNull {
return nil, nil
}
Expand Down
2 changes: 1 addition & 1 deletion driver/internal/protocol/levenshtein/levenshtein.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func Distance(a, b string, caseSensitive bool) int {

// MinString returns the string attribute determined by fn out of x with the minimal Lewenshtein distance to s.
func MinString[S ~[]E, E any](x S, fn func(a E) string, s string, caseSensitive bool) (rv string) {
min := math.MaxInt
min := math.MaxInt //nolint: predeclared
for _, e := range x {
xs := fn(e)
if d := Distance(xs, s, caseSensitive); d < min {
Expand Down
6 changes: 4 additions & 2 deletions driver/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,10 @@ type StmtMetadata interface {
ColumnTypes() []ColumnType
}

// use unexported var to avoid key collisions.
var stmtMetadataCtxKey struct{}
// use unexported type to avoid key collisions.
type stmtMetadataCtxKeyType struct{}

var stmtMetadataCtxKey stmtMetadataCtxKeyType

// WithStmtMetadata can be used to add a statement metadata reference to the context used for a Prepare call.
// The Prepare call will set the stmtMetadata reference on successful preparation.
Expand Down
6 changes: 4 additions & 2 deletions driver/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,10 @@ func (u *SessionUser) clone() *SessionUser {
return &SessionUser{Username: u.Username, Password: u.Password}
}

// use unexported var to avoid key collisions.
var switchUserCtxKey struct{}
// use unexported type to avoid key collisions.
type switchUserCtxKeyType struct{}

var switchUserCtxKey switchUserCtxKeyType

// WithUserSwitch can be used to switch a user on a new or an existing connection
// (see https://help.sap.com/docs/hana-cloud-database/sap-hana-cloud-sap-hana-database-sql-reference-guide/connect-statement-session-management).
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module github.com/SAP/go-hdb

go 1.21

toolchain go1.22.6
toolchain go1.23.0

require (
github.com/prometheus/client_golang v1.19.1
Expand All @@ -17,6 +17,6 @@ require (
github.com/prometheus/client_model v0.6.1 // indirect
github.com/prometheus/common v0.55.0 // indirect
github.com/prometheus/procfs v0.15.1 // indirect
golang.org/x/sys v0.23.0 // indirect
golang.org/x/sys v0.24.0 // indirect
google.golang.org/protobuf v1.34.2 // indirect
)
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ github.com/prometheus/procfs v0.15.1 h1:YagwOFzUgYfKKHX6Dr+sHT7km/hxC76UB0leargg
github.com/prometheus/procfs v0.15.1/go.mod h1:fB45yRUv8NstnjriLhBQLuOUt+WW4BsoGhij/e3PBqk=
golang.org/x/crypto v0.26.0 h1:RrRspgV4mU+YwB4FYnuBoKsUapNIL5cohGAmSH3azsw=
golang.org/x/crypto v0.26.0/go.mod h1:GY7jblb9wI+FOo5y8/S2oY4zWP07AkOJ4+jxCqdqn54=
golang.org/x/sys v0.23.0 h1:YfKFowiIMvtgl1UERQoTPPToxltDeZfbj4H7dVUCwmM=
golang.org/x/sys v0.23.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.24.0 h1:Twjiwq9dn6R1fQcyiK+wQyHWfaz/BJB+YIpzU/Cv3Xg=
golang.org/x/sys v0.24.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/text v0.17.0 h1:XtiM5bkSOt+ewxlOE/aE/AKEHibwj/6gvWMl9Rsh0Qc=
golang.org/x/text v0.17.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY=
google.golang.org/protobuf v1.34.2 h1:6xV6lTsCfpGD21XK49h7MhtcApnLqkfYgPcdHftf6hg=
Expand Down

0 comments on commit 6d4dc4d

Please sign in to comment.