Skip to content

Commit

Permalink
v1.8.23
Browse files Browse the repository at this point in the history
  • Loading branch information
stfnmllr committed May 7, 2024
1 parent 0f3cc51 commit cdcfaf9
Show file tree
Hide file tree
Showing 21 changed files with 196 additions and 224 deletions.
3 changes: 2 additions & 1 deletion .golangci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ linters:
- funlen
- gocognit
- gofumpt
- goerr113
- err113
- depguard
- wrapcheck
- cyclop
Expand All @@ -99,6 +99,7 @@ linters:
- noctx
- execinquery
- rowserrcheck
- mnd
#enable-all: false
#enable:
# - ...
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.22
#### v1.8.22 - v1.8.23
- updated dependencies
- source code cleanups

Expand Down
38 changes: 15 additions & 23 deletions driver/connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -302,17 +302,9 @@ func newConn(ctx context.Context, host string, metrics *metrics, attrs *connAttr
enc := encoding.NewEncoder(rw.Writer, attrs._cesu8Encoder)
dec := encoding.NewDecoder(rw.Reader, attrs._cesu8Decoder)

c := &conn{
attrs: attrs,
metrics: metrics,
dbConn: dbConn,
sqlTrace: sqlTrace.Load(),
logger: logger,
dec: dec,
pw: p.NewWriter(rw.Writer, enc, protTrace, logger, attrs._cesu8Encoder, attrs._sessionVariables), // write upstream
pr: p.NewDBReader(dec, protTrace, logger), // read downstream
sessionID: defaultSessionID,
}
c := &conn{attrs: attrs, metrics: metrics, dbConn: dbConn, sqlTrace: sqlTrace.Load(), logger: logger, dec: dec, sessionID: defaultSessionID}
c.pw = p.NewWriter(rw.Writer, enc, protTrace, logger, attrs._cesu8Encoder, attrs._sessionVariables) // write upstream
c.pr = p.NewDBReader(dec, c.readLob, protTrace, logger) // read downstream

if err := c.pw.WriteProlog(ctx); err != nil {
dbConn.close()
Expand Down Expand Up @@ -713,7 +705,7 @@ 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)) {
if err := c.pr.IterateParts(ctx, func(kind p.PartKind, attrs p.PartAttributes, read func(part p.DecodePart)) {
if kind == p.PkDBConnectInfo {
read(ci)
}
Expand Down Expand Up @@ -750,7 +742,7 @@ 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)) {
if err := c.pr.IterateParts(ctx, func(kind p.PartKind, attrs p.PartAttributes, read func(part p.DecodePart)) {
if kind == p.PkAuthentication {
read(initReply)
}
Expand Down Expand Up @@ -788,7 +780,7 @@ 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)) {
if err := c.pr.IterateParts(ctx, func(kind p.PartKind, attrs p.PartAttributes, read func(part p.DecodePart)) {
switch kind {
case p.PkAuthentication:
read(finalReply)
Expand Down Expand Up @@ -817,7 +809,7 @@ func (c *conn) queryDirect(ctx context.Context, query string, commit bool) (driv
meta := &p.ResultMetadata{}
resSet := &p.Resultset{}

if err := c.pr.IterateParts(ctx, func(kind p.PartKind, attrs p.PartAttributes, read func(part p.Part)) {
if err := c.pr.IterateParts(ctx, func(kind p.PartKind, attrs p.PartAttributes, read func(part p.DecodePart)) {
switch kind {
case p.PkResultMetadata:
read(meta)
Expand Down Expand Up @@ -849,7 +841,7 @@ 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)) {
if err := c.pr.IterateParts(ctx, func(kind p.PartKind, attrs p.PartAttributes, read func(part p.DecodePart)) {
if kind == p.PkRowsAffected {
read(rows)
numRow = rows.Total()
Expand All @@ -874,7 +866,7 @@ func (c *conn) prepare(ctx context.Context, query string) (*prepareResult, error
resMeta := &p.ResultMetadata{}
prmMeta := &p.ParameterMetadata{}

if err := c.pr.IterateParts(ctx, func(kind p.PartKind, attrs p.PartAttributes, read func(part p.Part)) {
if err := c.pr.IterateParts(ctx, func(kind p.PartKind, attrs p.PartAttributes, read func(part p.DecodePart)) {
switch kind {
case p.PkStatementID:
read((*p.StatementID)(&pr.stmtID))
Expand Down Expand Up @@ -911,7 +903,7 @@ 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)) {
if err := c.pr.IterateParts(ctx, func(kind p.PartKind, attrs p.PartAttributes, read func(part p.DecodePart)) {
switch kind {
case p.PkResultsetID:
read((*p.ResultsetID)(&qr.rsID))
Expand Down Expand Up @@ -945,7 +937,7 @@ 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)) {
if err := c.pr.IterateParts(ctx, func(kind p.PartKind, attrs p.PartAttributes, read func(part p.DecodePart)) {
switch kind {
case p.PkRowsAffected:
read(rows)
Expand Down Expand Up @@ -994,7 +986,7 @@ 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)) {
if err := c.pr.IterateParts(ctx, func(kind p.PartKind, attrs p.PartAttributes, read func(part p.DecodePart)) {
switch kind {
case p.PkRowsAffected:
read(rows)
Expand Down Expand Up @@ -1045,7 +1037,7 @@ 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)) {
return c.pr.IterateParts(ctx, func(kind p.PartKind, attrs p.PartAttributes, read func(part p.DecodePart)) {
if kind == p.PkResultset {
read(resSet)
qr.fieldValues = resSet.FieldValues
Expand Down Expand Up @@ -1126,7 +1118,7 @@ func (c *conn) readLob(lobRequest *p.ReadLobRequest, lobReply *p.ReadLobReply) e
return err
}

if err := c.pr.IterateParts(ctx, func(kind p.PartKind, attrs p.PartAttributes, read func(part p.Part)) {
if err := c.pr.IterateParts(ctx, func(kind p.PartKind, attrs p.PartAttributes, read func(part p.DecodePart)) {
if kind == p.PkReadLobReply {
read(lobReply)
}
Expand Down Expand Up @@ -1206,7 +1198,7 @@ func (c *conn) writeLobs(cr *callResult, ids []p.LocatorID, inPrmFields []*p.Par
lobReply := &p.WriteLobReply{}
outPrms := &p.OutputParameters{}

if err := c.pr.IterateParts(ctx, func(kind p.PartKind, attrs p.PartAttributes, read func(part p.Part)) {
if err := c.pr.IterateParts(ctx, func(kind p.PartKind, attrs p.PartAttributes, read func(part p.DecodePart)) {
switch kind {
case p.PkOutputParameters:
outPrms.OutputFields = cr.outputFields
Expand Down
8 changes: 4 additions & 4 deletions driver/internal/protocol/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ type AuthInitRequest struct {

func (r *AuthInitRequest) String() string { return r.prms.String() }
func (r *AuthInitRequest) size() int { return r.prms.Size() }
func (r *AuthInitRequest) decode(dec *encoding.Decoder) error {
func (r *AuthInitRequest) decode(dec *encoding.Decoder, prms *decodePrms) error {
return r.prms.Decode(dec)
}
func (r *AuthInitRequest) encode(enc *encoding.Encoder) error { return r.prms.Encode(enc) }
Expand All @@ -96,7 +96,7 @@ type AuthInitReply struct {
}

func (r *AuthInitReply) String() string { return r.authHnd.String() }
func (r *AuthInitReply) decode(dec *encoding.Decoder) error {
func (r *AuthInitReply) decode(dec *encoding.Decoder, prms *decodePrms) error {
if r.authHnd == nil {
return nil
}
Expand Down Expand Up @@ -124,7 +124,7 @@ type AuthFinalRequest struct {

func (r *AuthFinalRequest) String() string { return r.prms.String() }
func (r *AuthFinalRequest) size() int { return r.prms.Size() }
func (r *AuthFinalRequest) decode(dec *encoding.Decoder) error {
func (r *AuthFinalRequest) decode(dec *encoding.Decoder, prms *decodePrms) error {
return nil
// panic("not implemented yet")
}
Expand All @@ -136,7 +136,7 @@ type AuthFinalReply struct {
}

func (r *AuthFinalReply) String() string { return r.method.String() }
func (r *AuthFinalReply) decode(dec *encoding.Decoder) error {
func (r *AuthFinalReply) decode(dec *encoding.Decoder, prms *decodePrms) error {
if r.method == nil {
return nil
}
Expand Down
6 changes: 3 additions & 3 deletions 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 encodePart) []byte {
buf := bytes.Buffer{}
enc := encoding.NewEncoder(&buf, cesu8.DefaultEncoder)

Expand All @@ -20,10 +20,10 @@ func authEncodeStep(t *testing.T, part writablePart) []byte {
return buf.Bytes()
}

func authDecodeStep(t *testing.T, part defPart, data []byte) {
func authDecodeStep(t *testing.T, part DecodePart, data []byte) {
dec := encoding.NewDecoder(bytes.NewBuffer(data), cesu8.DefaultDecoder)

if err := part.decode(dec); err != nil {
if err := part.decode(dec, nil); err != nil {
t.Fatal(err)
}
}
Expand Down
6 changes: 3 additions & 3 deletions driver/internal/protocol/decode.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"github.com/SAP/go-hdb/driver/internal/protocol/encoding"
)

func decodeResult(tc typeCode, d *encoding.Decoder, scale int) (any, error) { //nolint: gocyclo
func decodeResult(tc typeCode, d *encoding.Decoder, readFn lobReadFn, scale int) (any, error) { //nolint: gocyclo
switch tc {
case tcBoolean:
return d.BooleanField()
Expand Down Expand Up @@ -66,13 +66,13 @@ func decodeResult(tc typeCode, d *encoding.Decoder, scale int) (any, error) { //
return d.HexField()
case tcBlob, tcClob, tcLocator, tcBintext:
descr := new(lobOutBytesDescr)
if descr.decode(d) {
if descr.decode(d, readFn) {
return nil, nil
}
return descr, nil
case tcText, tcNclob, tcNlocator:
descr := newLobOutCharsDescr(d.Transformer())
if descr.decode(d) {
if descr.decode(d, readFn) {
return nil, nil
}
return descr, nil
Expand Down
6 changes: 3 additions & 3 deletions driver/internal/protocol/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,11 +152,11 @@ func (e *HdbErrors) setStmtNo(idx, no int) {
}
}

func (e *HdbErrors) decodeNumArg(dec *encoding.Decoder, numArg int) error {
func (e *HdbErrors) decode(dec *encoding.Decoder, prms *decodePrms) error {
e.onlyWarnings = true
e.errs = nil

for i := 0; i < numArg; i++ {
for i := 0; i < prms.numArg; i++ {
err := new(HdbError)
e.errs = append(e.errs, err)

Expand Down Expand Up @@ -187,7 +187,7 @@ func (e *HdbErrors) decodeNumArg(dec *encoding.Decoder, numArg int) error {
e.onlyWarnings = false
}

if numArg == 1 {
if prms.numArg == 1 {
// Error (protocol error?):
// if only one error (numArg == 1): s.ph.bufferLength is one byte greater than data to be read
// if more than one error: s.ph.bufferlength matches read bytes + padding
Expand Down
4 changes: 2 additions & 2 deletions driver/internal/protocol/keyvaluesparts.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ func (c clientInfo) size() int {

func (c clientInfo) numArg() int { return len(c) }

func (c *clientInfo) decodeNumArg(dec *encoding.Decoder, numArg int) error {
func (c *clientInfo) decode(dec *encoding.Decoder, prms *decodePrms) error {
*c = clientInfo{} // no reuse of maps - create new one

for i := 0; i < numArg; i++ {
for i := 0; i < prms.numArg; i++ {
k, err := dec.Cesu8Field()
if err != nil {
return err
Expand Down
51 changes: 24 additions & 27 deletions driver/internal/protocol/lob.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,16 +75,9 @@ type LobScanner interface {
Scan(w io.Writer) error
}

// LobReadFnSetter is the interface wrapping the setDecoder method for Lob reading.
type LobReadFnSetter interface {
SetLobReadFn(fn func(lobRequest *ReadLobRequest, lobReply *ReadLobReply) error)
}

var (
_ LobScanner = (*lobOutBytesDescr)(nil)
_ LobReadFnSetter = (*lobOutBytesDescr)(nil)
_ LobScanner = (*lobOutCharsDescr)(nil)
_ LobReadFnSetter = (*lobOutCharsDescr)(nil)
_ LobScanner = (*lobOutBytesDescr)(nil)
_ LobScanner = (*lobOutCharsDescr)(nil)
)

// LobInDescr represents a lob input descriptor.
Expand Down Expand Up @@ -133,9 +126,14 @@ func (d *LobInDescr) writeFirst(enc *encoding.Encoder) { enc.Bytes(d.buf.Bytes()
// LocatorID represents a locotor id.
type LocatorID uint64 // byte[locatorIdSize]

type lobReadFn func(lobRequest *ReadLobRequest, lobReply *ReadLobReply) error

// lobOutDescr represents a lob output descriptor.
type lobOutDescr struct {
readFn func(lobRequest *ReadLobRequest, lobReply *ReadLobReply) error
/*
readFn is set by decode if additional data packages need to be read (not last data)
*/
readFn lobReadFn
/*
HDB does not return lob type code but undefined only
--> ltc is always ltcUndefined
Expand All @@ -153,12 +151,7 @@ func (d *lobOutDescr) String() string {
return fmt.Sprintf("typecode %s options %s numChar %d numByte %d id %d bytes %v", d.ltc, d.opt, d.numChar, d.numByte, d.id, d.b)
}

// SetConnReader implements the LobConnReaderSetter interface.
func (d *lobOutDescr) SetLobReadFn(fn func(lobRequest *ReadLobRequest, lobReply *ReadLobReply) error) {
d.readFn = fn
}

func (d *lobOutDescr) decode(dec *encoding.Decoder) bool {
func (d *lobOutDescr) decode(dec *encoding.Decoder, readFn lobReadFn) bool {
d.ltc = lobTypecode(dec.Int8())
d.opt = lobOptions(dec.Int8())
if d.opt.isNull() {
Expand All @@ -171,6 +164,10 @@ func (d *lobOutDescr) decode(dec *encoding.Decoder) bool {
size := int(dec.Int32())
d.b = make([]byte, size)
dec.Bytes(d.b)
// if not last data -> set readFn for scan
if !d.opt.isLastData() {
d.readFn = readFn
}
return false
}

Expand Down Expand Up @@ -200,7 +197,7 @@ func (d *lobOutBytesDescr) scan(wr io.Writer) error {
if _, err := wr.Write(d.b); err != nil {
return err
}
if d.opt.isLastData() {
if d.readFn == nil {
return nil
}
lobRequest := &ReadLobRequest{ofs: int64(len(d.b)), id: d.id}
Expand Down Expand Up @@ -256,7 +253,7 @@ func (d *lobOutCharsDescr) scan(wr io.Writer) error {
if _, err := wr.Write(d.b[:size]); err != nil {
return err
}
if d.opt.isLastData() {
if d.readFn == nil {
return nil
}
lobRequest := &ReadLobRequest{ofs: int64(numChar), id: d.id}
Expand Down Expand Up @@ -345,9 +342,9 @@ func (r *WriteLobRequest) size() int {
func (r *WriteLobRequest) numArg() int { return len(r.Descrs) }

// sniffer.
func (r *WriteLobRequest) decodeNumArg(dec *encoding.Decoder, numArg int) error {
r.Descrs = make([]*WriteLobDescr, numArg)
for i := 0; i < numArg; i++ {
func (r *WriteLobRequest) decode(dec *encoding.Decoder, prms *decodePrms) error {
r.Descrs = make([]*WriteLobDescr, prms.numArg)
for i := 0; i < prms.numArg; i++ {
r.Descrs[i] = &WriteLobDescr{}
if err := r.Descrs[i].decode(dec); err != nil {
return err
Expand All @@ -374,10 +371,10 @@ type WriteLobReply struct {

func (r *WriteLobReply) String() string { return fmt.Sprintf("ids %v", r.IDs) }

func (r *WriteLobReply) decodeNumArg(dec *encoding.Decoder, numArg int) error {
r.IDs = resizeSlice(r.IDs, numArg)
func (r *WriteLobReply) decode(dec *encoding.Decoder, prms *decodePrms) error {
r.IDs = resizeSlice(r.IDs, prms.numArg)

for i := 0; i < numArg; i++ {
for i := 0; i < prms.numArg; i++ {
r.IDs[i] = LocatorID(dec.Uint64())
}
return dec.Error()
Expand Down Expand Up @@ -412,7 +409,7 @@ func (r *ReadLobRequest) AddOfs(n int) { r.ofs += int64(n) }
func (r *ReadLobRequest) SetChunkSize(size int) { r.chunkSize = int32(size) }

// sniffer.
func (r *ReadLobRequest) decode(dec *encoding.Decoder) error {
func (r *ReadLobRequest) decode(dec *encoding.Decoder, prms *decodePrms) error {
r.id = LocatorID(dec.Uint64())
r.ofs = dec.Int64()
r.chunkSize = dec.Int32()
Expand Down Expand Up @@ -445,8 +442,8 @@ func (r *ReadLobReply) String() string {
// IsLastData returns true in case of last data package read, false otherwise.
func (r *ReadLobReply) IsLastData() bool { return r.opt.isLastData() }

func (r *ReadLobReply) decodeNumArg(dec *encoding.Decoder, numArg int) error {
if numArg != 1 {
func (r *ReadLobReply) decode(dec *encoding.Decoder, prms *decodePrms) error {
if prms.numArg != 1 {
panic("numArg == 1 expected")
}
id := LocatorID(dec.Uint64())
Expand Down
Loading

0 comments on commit cdcfaf9

Please sign in to comment.