Skip to content

Commit

Permalink
release 0.111.2
Browse files Browse the repository at this point in the history
  • Loading branch information
stfnmllr committed Nov 25, 2022
1 parent da68327 commit 5d843fd
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 23 deletions.
4 changes: 4 additions & 0 deletions RELEASENOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ Release Notes

## Release 0.111

Release 0.111.2 (upgrade urgency: no need for upgrade)

- Some source code cleanups

Release 0.111.1 (upgrade urgency: low)

- Some minor fixes and source code cleanups
Expand Down
8 changes: 4 additions & 4 deletions driver/connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -1867,14 +1867,14 @@ func (c *conn) _disconnect() error {
// read lob reply
// - seems like readLobreply returns only a result for one lob - even if more then one is requested
// --> read single lobs
func (c *conn) decodeLobs(descr *p.LobOutDescr, wr io.Writer) error {
func (c *conn) decodeLob(descr *p.LobOutDescr, wr io.Writer) error {
defer c.addSQLTimeValue(time.Now(), sqlTimeFetchLob)

var err error

if descr.IsCharBased {
wrcl := transform.NewWriter(wr, c._cesu8Decoder()) // CESU8 transformer
err = c._decodeLobs(descr, wrcl, func(b []byte) (int64, error) {
err = c._decodeLob(descr, wrcl, func(b []byte) (int64, error) {
// Caution: hdb counts 4 byte utf-8 encodings (cesu-8 6 bytes) as 2 (3 byte) chars
numChars := int64(0)
for len(b) > 0 {
Expand All @@ -1891,7 +1891,7 @@ func (c *conn) decodeLobs(descr *p.LobOutDescr, wr io.Writer) error {
return numChars, nil
})
} else {
err = c._decodeLobs(descr, wr, func(b []byte) (int64, error) { return int64(len(b)), nil })
err = c._decodeLob(descr, wr, func(b []byte) (int64, error) { return int64(len(b)), nil })
}

if pw, ok := wr.(*io.PipeWriter); ok { // if the writer is a pipe-end -> close at the end
Expand All @@ -1904,7 +1904,7 @@ func (c *conn) decodeLobs(descr *p.LobOutDescr, wr io.Writer) error {
return err
}

func (c *conn) _decodeLobs(descr *p.LobOutDescr, wr io.Writer, countChars func(b []byte) (int64, error)) error {
func (c *conn) _decodeLob(descr *p.LobOutDescr, wr io.Writer, countChars func(b []byte) (int64, error)) error {
lobChunkSize := int64(c._lobChunkSize)

chunkSize := func(numChar, ofs int64) int32 {
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 = "0.111.1"
const DriverVersion = "0.111.2"

// DriverName is the driver name to use with sql.Open for hdb databases.
const DriverName = "hdb"
Expand Down
28 changes: 16 additions & 12 deletions driver/internal/protocol/lob.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,16 +61,18 @@ const (
// }
// func (f lobFlags) encode(enc *encoding.Encoder) error { enc.Bool(bool(f)); return nil }

// WriterSetter is the interface wrapping the SetWriter method (Lob handling).
type WriterSetter interface{ SetWriter(w io.Writer) error }
// LobScanner is the interface wrapping the Scan method for Lob reading.
type LobScanner interface {
Scan(w io.Writer) error
}

// LobsDecoderSetter is the interface wrapping the setLobsdecoder method (lob handling).
type LobsDecoderSetter interface {
SetLobsDecoder(fn func(descr *LobOutDescr, wr io.Writer) error)
// LobDecoderSetter is the interface wrapping the setDecoder method for Lob reading.
type LobDecoderSetter interface {
SetDecoder(fn func(descr *LobOutDescr, wr io.Writer) error)
}

var _ WriterSetter = (*LobOutDescr)(nil)
var _ LobsDecoderSetter = (*LobOutDescr)(nil)
var _ LobScanner = (*LobOutDescr)(nil)
var _ LobDecoderSetter = (*LobOutDescr)(nil)

// LobInDescr represents a lob input descriptor.
type LobInDescr struct {
Expand Down Expand Up @@ -128,7 +130,7 @@ func (d *LobInDescr) writeFirst(enc *encoding.Encoder) {

// LobOutDescr represents a lob output descriptor.
type LobOutDescr struct {
fnLD func(descr *LobOutDescr, wr io.Writer) error
decoder func(descr *LobOutDescr, wr io.Writer) error
IsCharBased bool
/*
HDB does not return lob type code but undefined only
Expand All @@ -147,11 +149,13 @@ 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)
}

// SetLobsDecoder sets the function to decode lobs.
func (d *LobOutDescr) SetLobsDecoder(fn func(descr *LobOutDescr, wr io.Writer) error) { d.fnLD = fn }
// SetDecoder implements the LobDecoderSetter interface.
func (d *LobOutDescr) SetDecoder(decoder func(descr *LobOutDescr, wr io.Writer) error) {
d.decoder = decoder
}

// SetWriter implements the WriterSetter interface.
func (d *LobOutDescr) SetWriter(wr io.Writer) error { return d.fnLD(d, wr) }
// Scan implements the LobScanner interface.
func (d *LobOutDescr) Scan(wr io.Writer) error { return d.decoder(d, wr) }

/*
write lobs:
Expand Down
4 changes: 2 additions & 2 deletions driver/lob.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,12 @@ func (l *Lob) Scan(src any) error {
return fmt.Errorf("lob error: initial writer %[1]T %[1]v", l)
}

ws, ok := src.(p.WriterSetter)
scanner, ok := src.(p.LobScanner)
if !ok {
return fmt.Errorf("lob: invalid scan type %T", src)
}

if err := ws.SetWriter(l.wr); err != nil {
if err := scanner.Scan(l.wr); err != nil {
return err
}
return nil
Expand Down
8 changes: 4 additions & 4 deletions driver/result.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,8 @@ func (qr *queryResult) Next(dest []driver.Value) error {
qr.pos++

for _, v := range dest {
if v, ok := v.(p.LobsDecoderSetter); ok {
v.SetLobsDecoder(qr.conn.decodeLobs)
if v, ok := v.(p.LobDecoderSetter); ok {
v.SetDecoder(qr.conn.decodeLob)
}
}
return err
Expand Down Expand Up @@ -261,8 +261,8 @@ func (cr *callResult) Next(dest []driver.Value) error {
err := cr.decodeErrors.RowError(0)
cr.eof = true
for _, v := range dest {
if v, ok := v.(p.LobsDecoderSetter); ok {
v.SetLobsDecoder(cr.conn.decodeLobs)
if v, ok := v.(p.LobDecoderSetter); ok {
v.SetDecoder(cr.conn.decodeLob)
}
}
return err
Expand Down

0 comments on commit 5d843fd

Please sign in to comment.