Skip to content

Commit

Permalink
v1.8.5
Browse files Browse the repository at this point in the history
  • Loading branch information
stfnmllr committed Feb 14, 2024
1 parent 2a0ae35 commit c2434b2
Show file tree
Hide file tree
Showing 11 changed files with 190 additions and 249 deletions.
2 changes: 1 addition & 1 deletion RELEASENOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Release Notes

### Minor revisions

#### v1.8.4
#### v1.8.4 - v1.8.5
- source code cleanups
- performance improvements

Expand Down
100 changes: 38 additions & 62 deletions driver/connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -719,12 +719,10 @@ func (c *conn) dbConnectInfo(ctx context.Context, databaseName string) (*DBConne
return nil, err
}

if err := c.pr.IterateParts(ctx, func(kind p.PartKind, attrs p.PartAttributes, read func(part p.Part) error) error {
var err error
if err := c.pr.IterateParts(ctx, func(kind p.PartKind, attrs p.PartAttributes, read func(part p.Part)) {
if kind == p.PkDBConnectInfo {
err = read(ci)
read(ci)
}
return err
}); err != nil {
return nil, err
}
Expand Down Expand Up @@ -758,12 +756,10 @@ func (c *conn) authenticate(ctx context.Context, authHnd *p.AuthHnd, attrs *conn
if err != nil {
return 0, nil, err
}
if err := c.pr.IterateParts(ctx, func(kind p.PartKind, attrs p.PartAttributes, read func(part p.Part) error) error {
var err error
if err := c.pr.IterateParts(ctx, func(kind p.PartKind, attrs p.PartAttributes, read func(part p.Part)) {
if kind == p.PkAuthentication {
err = read(initReply)
read(initReply)
}
return err
}); err != nil {
return 0, nil, err
}
Expand Down Expand Up @@ -798,17 +794,15 @@ func (c *conn) authenticate(ctx context.Context, authHnd *p.AuthHnd, attrs *conn

ti := new(p.TopologyInformation)

if err := c.pr.IterateParts(ctx, func(kind p.PartKind, attrs p.PartAttributes, read func(part p.Part) error) error {
var err error
if err := c.pr.IterateParts(ctx, func(kind p.PartKind, attrs p.PartAttributes, read func(part p.Part)) {
switch kind {
case p.PkAuthentication:
err = read(finalReply)
read(finalReply)
case p.PkConnectOptions:
err = read(co)
read(co)
case p.PkTopologyInformation:
err = read(ti)
read(ti)
}
return err
}); err != nil {
return 0, nil, err
}
Expand All @@ -829,22 +823,20 @@ func (c *conn) queryDirect(ctx context.Context, query string, commit bool) (driv
meta := &p.ResultMetadata{FieldTypeCtx: c.fieldTypeCtx}
resSet := &p.Resultset{}

if err := c.pr.IterateParts(ctx, func(kind p.PartKind, attrs p.PartAttributes, read func(part p.Part) error) error {
var err error
if err := c.pr.IterateParts(ctx, func(kind p.PartKind, attrs p.PartAttributes, read func(part p.Part)) {
switch kind {
case p.PkResultMetadata:
err = read(meta)
read(meta)
qr.fields = meta.ResultFields
case p.PkResultsetID:
err = read((*p.ResultsetID)(&qr.rsID))
read((*p.ResultsetID)(&qr.rsID))
case p.PkResultset:
resSet.ResultFields = qr.fields
err = read(resSet)
read(resSet)
qr.fieldValues = resSet.FieldValues
qr.decodeErrors = resSet.DecodeErrors
qr.attrs = attrs
}
return err
}); err != nil {
return nil, err
}
Expand All @@ -863,13 +855,11 @@ func (c *conn) execDirect(ctx context.Context, query string, commit bool) (drive

rows := &p.RowsAffected{}
var numRow int64
if err := c.pr.IterateParts(ctx, func(kind p.PartKind, attrs p.PartAttributes, read func(part p.Part) error) error {
var err error
if err := c.pr.IterateParts(ctx, func(kind p.PartKind, attrs p.PartAttributes, read func(part p.Part)) {
if kind == p.PkRowsAffected {
err = read(rows)
read(rows)
numRow = rows.Total()
}
return err
}); err != nil {
return nil, err
}
Expand All @@ -890,19 +880,17 @@ func (c *conn) prepare(ctx context.Context, query string) (*prepareResult, error
resMeta := &p.ResultMetadata{FieldTypeCtx: c.fieldTypeCtx}
prmMeta := &p.ParameterMetadata{FieldTypeCtx: c.fieldTypeCtx}

if err := c.pr.IterateParts(ctx, func(kind p.PartKind, attrs p.PartAttributes, read func(part p.Part) error) error {
var err error
if err := c.pr.IterateParts(ctx, func(kind p.PartKind, attrs p.PartAttributes, read func(part p.Part)) {
switch kind {
case p.PkStatementID:
err = read((*p.StatementID)(&pr.stmtID))
read((*p.StatementID)(&pr.stmtID))
case p.PkResultMetadata:
err = read(resMeta)
read(resMeta)
pr.resultFields = resMeta.ResultFields
case p.PkParameterMetadata:
err = read(prmMeta)
read(prmMeta)
pr.parameterFields = prmMeta.ParameterFields
}
return err
}); err != nil {
return nil, err
}
Expand All @@ -929,19 +917,17 @@ func (c *conn) query(ctx context.Context, pr *prepareResult, nvargs []driver.Nam
qr := &queryResult{conn: c, fields: pr.resultFields}
resSet := &p.Resultset{}

if err := c.pr.IterateParts(ctx, func(kind p.PartKind, attrs p.PartAttributes, read func(part p.Part) error) error {
var err error
if err := c.pr.IterateParts(ctx, func(kind p.PartKind, attrs p.PartAttributes, read func(part p.Part)) {
switch kind {
case p.PkResultsetID:
err = read((*p.ResultsetID)(&qr.rsID))
read((*p.ResultsetID)(&qr.rsID))
case p.PkResultset:
resSet.ResultFields = qr.fields
err = read(resSet)
read(resSet)
qr.fieldValues = resSet.FieldValues
qr.decodeErrors = resSet.DecodeErrors
qr.attrs = attrs
}
return err
}); err != nil {
return nil, err
}
Expand All @@ -965,17 +951,15 @@ func (c *conn) exec(ctx context.Context, pr *prepareResult, nvargs []driver.Name
lobReply := &p.WriteLobReply{}
var rowsAffected int64

if err := c.pr.IterateParts(ctx, func(kind p.PartKind, attrs p.PartAttributes, read func(part p.Part) error) error {
var err error
if err := c.pr.IterateParts(ctx, func(kind p.PartKind, attrs p.PartAttributes, read func(part p.Part)) {
switch kind {
case p.PkRowsAffected:
err = read(rows)
read(rows)
rowsAffected = rows.Total()
case p.PkWriteLobReply:
err = read(lobReply)
read(lobReply)
ids = lobReply.IDs
}
return err
}); err != nil {
return nil, err
}
Expand Down Expand Up @@ -1016,15 +1000,14 @@ func (c *conn) execCall(ctx context.Context, outputFields []*p.ParameterField) (
var numRow int64
tableRowIdx := 0

if err := c.pr.IterateParts(ctx, func(kind p.PartKind, attrs p.PartAttributes, read func(part p.Part) error) error {
var err error
if err := c.pr.IterateParts(ctx, func(kind p.PartKind, attrs p.PartAttributes, read func(part p.Part)) {
switch kind {
case p.PkRowsAffected:
err = read(rows)
read(rows)
numRow = rows.Total()
case p.PkOutputParameters:
outPrms.OutputFields = cr.outputFields
err = read(outPrms)
read(outPrms)
cr.fieldValues = outPrms.FieldValues
cr.decodeErrors = outPrms.DecodeErrors
case p.PkResultMetadata:
Expand All @@ -1039,21 +1022,20 @@ func (c *conn) execCall(ctx context.Context, outputFields []*p.ParameterField) (
cr.outputFields = append(cr.outputFields, p.NewTableRowsParameterField(tableRowIdx))
cr.fieldValues = append(cr.fieldValues, qr)
tableRowIdx++
err = read(meta)
read(meta)
qr.fields = meta.ResultFields
case p.PkResultset:
resSet.ResultFields = qr.fields
err = read(resSet)
read(resSet)
qr.fieldValues = resSet.FieldValues
qr.decodeErrors = resSet.DecodeErrors
qr.attrs = attrs
case p.PkResultsetID:
err = read((*p.ResultsetID)(&qr.rsID))
read((*p.ResultsetID)(&qr.rsID))
case p.PkWriteLobReply:
err = read(lobReply)
read(lobReply)
ids = lobReply.IDs
}
return err
}); err != nil {
return nil, nil, 0, err
}
Expand All @@ -1069,15 +1051,13 @@ func (c *conn) fetchNext(ctx context.Context, qr *queryResult) error {

resSet := &p.Resultset{ResultFields: qr.fields, FieldValues: qr.fieldValues} // reuse field values

return c.pr.IterateParts(ctx, func(kind p.PartKind, attrs p.PartAttributes, read func(part p.Part) error) error {
var err error
return c.pr.IterateParts(ctx, func(kind p.PartKind, attrs p.PartAttributes, read func(part p.Part)) {
if kind == p.PkResultset {
err = read(resSet)
read(resSet)
qr.fieldValues = resSet.FieldValues
qr.decodeErrors = resSet.DecodeErrors
qr.attrs = attrs
}
return err
})
}

Expand Down Expand Up @@ -1212,12 +1192,10 @@ func (c *conn) _decodeLob(descr *p.LobOutDescr, wr io.Writer, countChars func(b
return err
}

if err := c.pr.IterateParts(ctx, func(kind p.PartKind, attrs p.PartAttributes, read func(part p.Part) error) error {
var err error
if err := c.pr.IterateParts(ctx, func(kind p.PartKind, attrs p.PartAttributes, read func(part p.Part)) {
if kind == p.PkReadLobReply {
err = read(lobReply)
read(lobReply)
}
return err
}); err != nil {
return err
}
Expand Down Expand Up @@ -1294,19 +1272,17 @@ func (c *conn) encodeLobs(cr *callResult, ids []p.LocatorID, inPrmFields []*p.Pa
lobReply := &p.WriteLobReply{}
outPrms := &p.OutputParameters{}

if err := c.pr.IterateParts(ctx, func(kind p.PartKind, attrs p.PartAttributes, read func(part p.Part) error) error {
var err error
if err := c.pr.IterateParts(ctx, func(kind p.PartKind, attrs p.PartAttributes, read func(part p.Part)) {
switch kind {
case p.PkOutputParameters:
outPrms.OutputFields = cr.outputFields
err = read(outPrms)
read(outPrms)
cr.fieldValues = outPrms.FieldValues
cr.decodeErrors = outPrms.DecodeErrors
case p.PkWriteLobReply:
err = read(lobReply)
read(lobReply)
ids = lobReply.IDs
}
return err
}); err != nil {
return err
}
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.8.4"
const DriverVersion = "1.8.5"

// DriverName is the driver name to use with sql.Open for hdb databases.
const DriverName = "hdb"
Expand Down
2 changes: 1 addition & 1 deletion driver/internal/protocol/auth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"github.com/SAP/go-hdb/driver/unicode/cesu8"
)

func authEncodeStep(t *testing.T, part WritablePart) []byte {
func authEncodeStep(t *testing.T, part writablePart) []byte {
buf := bytes.Buffer{}
enc := encoding.NewEncoder(&buf, cesu8.DefaultEncoder)

Expand Down
3 changes: 0 additions & 3 deletions driver/internal/protocol/encoding/decode.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,6 @@ func NewDecoder(rd io.Reader, decoder func() transform.Transformer) *Decoder {
}
}

// ResetCnt resets the byte read counter.
func (d *Decoder) ResetCnt() { d.cnt = 0 }

// Cnt returns the value of the byte read counter.
func (d *Decoder) Cnt() int { return d.cnt }

Expand Down
4 changes: 2 additions & 2 deletions driver/internal/protocol/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ import (
// ErrorLevel send from database server.
type errorLevel int8

var errorLevelStrs = []string{"Warning", "Error", "FatalError"}
var errorLevelStrs = [...]string{"Warning", "Error", "FatalError"}

func (e errorLevel) String() string {
if int(e) >= len(errorLevelStrs) {
if int(e) < 0 || int(e) >= len(errorLevelStrs) {
return ""
}
return errorLevelStrs[e]
Expand Down
4 changes: 2 additions & 2 deletions driver/internal/protocol/headers.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,8 +206,8 @@ const (
)

var (
paList = []PartAttributes{paLastPacket, paNextPacket, paFirstPacket, paRowNotFound, paResultsetClosed}
paListText = []string{"lastPacket", "nextPacket", "firstPacket", "rowNotFound", "resultsetClosed"}
paList = [...]PartAttributes{paLastPacket, paNextPacket, paFirstPacket, paRowNotFound, paResultsetClosed}
paListText = [...]string{"lastPacket", "nextPacket", "firstPacket", "rowNotFound", "resultsetClosed"}
)

func (k PartAttributes) String() string {
Expand Down
37 changes: 20 additions & 17 deletions driver/internal/protocol/parameter.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,26 +42,29 @@ type ParameterMode int8

// ParameterMode constants.
const (
PmIn ParameterMode = 0x01
pmIn ParameterMode = 0x01
pmInout ParameterMode = 0x02
PmOut ParameterMode = 0x04
pmOut ParameterMode = 0x04
)

var parameterModeText = []string{
PmIn: "in",
pmInout: "inout",
PmOut: "out",
}
const (
pmInText = "in"
pmInoutText = "inout"
pmOutText = "out"
)

func (k ParameterMode) String() string {
t := make([]string, 0, len(parameterModeText))

for mode, text := range parameterModeText {
if (k & ParameterMode(mode)) != 0 {
t = append(t, text)
}
var s []string
if k&pmIn != 0 {
s = append(s, pmInText)
}
if k&pmInout != 0 {
s = append(s, pmInoutText)
}
return fmt.Sprintf("%v", t)
if k&pmOut != 0 {
s = append(s, pmOutText)
}
return fmt.Sprintf("%v", s)
}

// ParameterField contains database field attributes for parameters.
Expand All @@ -78,7 +81,7 @@ type ParameterField struct {

// NewTableRowsParameterField returns a ParameterField representing table rows.
func NewTableRowsParameterField(idx int) *ParameterField {
return &ParameterField{ofs: idx, tc: TcTableRows, mode: PmOut}
return &ParameterField{ofs: idx, tc: TcTableRows, mode: pmOut}
}

func (f *ParameterField) fieldName() string {
Expand Down Expand Up @@ -147,10 +150,10 @@ func (f *ParameterField) TypePrecisionScale() (int64, int64, bool) {
func (f *ParameterField) Nullable() bool { return f.parameterOptions == poOptional }

// In returns true if the parameter field is an input field.
func (f *ParameterField) In() bool { return f.mode == pmInout || f.mode == PmIn }
func (f *ParameterField) In() bool { return f.mode == pmInout || f.mode == pmIn }

// Out returns true if the parameter field is an output field.
func (f *ParameterField) Out() bool { return f.mode == pmInout || f.mode == PmOut }
func (f *ParameterField) Out() bool { return f.mode == pmInout || f.mode == pmOut }

// InOut returns true if the parameter field is an in,- output field.
func (f *ParameterField) InOut() bool { return f.mode == pmInout }
Expand Down
Loading

0 comments on commit c2434b2

Please sign in to comment.