protocol

package
v0.107.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 5, 2022 License: Apache-2.0 Imports: 37 Imported by: 0

Documentation

Overview

Package protocol implements the hdb command network protocol.

http://help.sap.com/hana/SAP_HANA_SQL_Command_Network_Protocol_Reference_en.pdf

Index

Constants

View Source
const (
	DfvLevel0 int = 0 // base data format
	DfvLevel1 int = 1 // eval types support all data types
	DfvLevel2 int = 2 // reserved, broken, do not use
	DfvLevel3 int = 3 // additional types Longdate, Secondate, Daydate, Secondtime supported for NGAP
	DfvLevel4 int = 4 // generic support for new date/time types
	DfvLevel5 int = 5 // spatial types in ODBC on request
	DfvLevel6 int = 6 // BINTEXT
	DfvLevel7 int = 7 // with boolean support
	DfvLevel8 int = 8 // with FIXED8/12/16 support
)

Data format version values.

View Source
const MaxNumArg = math.MaxInt32

MaxNumArg is the maximum number of arguments allowed to send in a part.

Variables

View Source
var ClientID string

ClientID holds the client ID of the driver's process and is set during go-hdb initialization to driver.clientID value.

View Source
var DriverVersion string

DriverVersion holds the version of the driver and is set during go-hdb initialization to driver.DriverVersion value.

View Source
var ErrDecimalOutOfRange = errors.New("decimal out of range error")

ErrDecimalOutOfRange means that a big.Rat exceeds the size of hdb decimal fields.

View Source
var ErrFloatOutOfRange = errors.New("float out of range error")

ErrFloatOutOfRange means that a float exceeds the size of the hdb float field.

View Source
var ErrIntegerOutOfRange = errors.New("integer out of range error")

ErrIntegerOutOfRange means that an integer exceeds the size of the hdb integer field.

View Source
var ErrUint64OutOfRange = errors.New("uint64 values with high bit set are not supported")

ErrUint64OutOfRange means that a uint64 exceeds the size of a int64.

View Source
var QueryResultCache = newQueryResultCache()

QueryResultCache is a query result cache supporting reading procedure (call) table parameter via separate query (legacy mode).

Functions

func IsSupportedDfv added in v0.107.0

func IsSupportedDfv(dfv int) bool

IsSupportedDfv returns true if the data format version dfv is supported by the driver, false otherwise.

func RegisterScanType

func RegisterScanType(dt DataType, scanType reflect.Type) bool

RegisterScanType registers driver owned datatype scantypes (e.g. Decimal, Lob).

func SupportedDfvs added in v0.107.0

func SupportedDfvs(defaultOnly bool) []int

SupportedDfvs returns a slice of data format versions supported by the driver. If parameter defaultOnly is set only the default dfv is returned, otherwise all supported dfv values are returned.

Types

type Auth added in v0.107.0

type Auth struct {
	// contains filtered or unexported fields
}

Auth holds the client authentication methods dependant on the driver.Connector attributes.

func NewAuth added in v0.107.0

func NewAuth(logonname string) *Auth

NewAuth creates a new Auth instance.

func (*Auth) AddBasic added in v0.107.0

func (a *Auth) AddBasic(username, password string)

AddBasic adds basic authentication methods.

func (*Auth) AddJWT added in v0.107.0

func (a *Auth) AddJWT(token string)

AddJWT adds JWT authentication method.

func (*Auth) AddSessionCookie added in v0.107.0

func (a *Auth) AddSessionCookie(cookie []byte, clientID string)

AddSessionCookie adds session cookie authentication method.

func (*Auth) AddX509 added in v0.107.0

func (a *Auth) AddX509(cert, key []byte)

AddX509 adds X509 authentication method.

func (*Auth) Method added in v0.107.0

func (a *Auth) Method() interface{}

Method returns the selected authentication method.

func (*Auth) String added in v0.107.0

func (a *Auth) String() string

type AuthCertKeySetter added in v0.107.0

type AuthCertKeySetter interface {
	SetCertKey(cert, key []byte)
}

AuthCertKeySetter is implemented by authentication methods supporting certificate and key updates.

type AuthCookieGetter added in v0.107.0

type AuthCookieGetter interface {
	Cookie() (logonname string, cookie []byte)
}

AuthCookieGetter is implemented by authentication methods supporting cookies to reconnect.

type AuthFailedError added in v0.107.0

type AuthFailedError struct {
	// contains filtered or unexported fields
}

A AuthFailedError is returned if the last authorization step would fail with a hdb error 10 (authorization failed).

func (*AuthFailedError) Error added in v0.107.0

func (e *AuthFailedError) Error() string

func (*AuthFailedError) MethodType added in v0.107.0

func (e *AuthFailedError) MethodType() string

MethodType returns the authentication method type.

func (*AuthFailedError) Unwrap added in v0.107.0

func (e *AuthFailedError) Unwrap() error

Unwrap returns the nested error.

type AuthPasswordSetter added in v0.107.0

type AuthPasswordSetter interface {
	SetPassword(string)
}

AuthPasswordSetter is implemented by authentication methods supporting password updates.

type AuthTokenSetter added in v0.107.0

type AuthTokenSetter interface {
	SetToken(string)
}

AuthTokenSetter is implemented by authentication methods supporting token updates.

type ConvertError

type ConvertError struct {
	// contains filtered or unexported fields
}

A ConvertError is returned by conversion methods if a go datatype to hdb datatype conversion fails.

func (*ConvertError) Error

func (e *ConvertError) Error() string

func (*ConvertError) Unwrap

func (e *ConvertError) Unwrap() error

Unwrap returns the nested error.

type DataType

type DataType byte

DataType is the type definition for data types supported by this package.

const (
	DtUnknown DataType = iota // unknown data type
	DtBoolean
	DtTinyint
	DtSmallint
	DtInteger
	DtBigint
	DtReal
	DtDouble
	DtDecimal
	DtTime
	DtString
	DtBytes
	DtLob
	DtRows
)

Data type constants.

func (DataType) ScanType

func (dt DataType) ScanType() reflect.Type

ScanType return the scan type (reflect.Type) of the corresponding data type.

func (DataType) String

func (i DataType) String() string

type OnCloser

type OnCloser interface {
	OnClose() func()
	SetOnClose(func())
}

OnCloser defines getter and setter for a function which should be called when closing.

type ParameterField

type ParameterField struct {
	// contains filtered or unexported fields
}

ParameterField contains database field attributes for parameters.

func (*ParameterField) Convert

func (f *ParameterField) Convert(s *Session, v interface{}) (interface{}, error)

Convert returns the result of the fieldType conversion.

func (*ParameterField) In

func (f *ParameterField) In() bool

In returns true if the parameter field is an input field.

func (*ParameterField) Out

func (f *ParameterField) Out() bool

Out returns true if the parameter field is an output field.

func (*ParameterField) String

func (f *ParameterField) String() string

type PrepareResult

type PrepareResult struct {
	// contains filtered or unexported fields
}

A PrepareResult represents the result of a prepare statement.

func (*PrepareResult) Check

func (pr *PrepareResult) Check(qd *QueryDescr) error

Check checks consistency of the prepare result.

func (*PrepareResult) IsProcedureCall

func (pr *PrepareResult) IsProcedureCall() bool

IsProcedureCall returns true if the statement is a call statement.

func (*PrepareResult) NumField

func (pr *PrepareResult) NumField() int

NumField returns the number of parameter fields in a database statement.

func (*PrepareResult) NumInputField

func (pr *PrepareResult) NumInputField() int

NumInputField returns the number of input fields in a database statement.

func (*PrepareResult) ParameterField

func (pr *PrepareResult) ParameterField(idx int) *ParameterField

ParameterField returns the parameter field at index idx.

func (*PrepareResult) Session added in v0.105.1

func (pr *PrepareResult) Session() *Session

Session returns the session the prepare result belongs to.

func (*PrepareResult) StmtID

func (pr *PrepareResult) StmtID() uint64

StmtID returns the statement id.

type QueryDescr

type QueryDescr struct {
	// contains filtered or unexported fields
}

QueryDescr represents a query descriptor of a database statement.

func NewQueryDescr

func NewQueryDescr(query string, sc *scanner.Scanner) (*QueryDescr, error)

NewQueryDescr returns a new QueryDescr instance.

func (*QueryDescr) ID

func (d *QueryDescr) ID() uint64

ID return the query id of a query descriptor (legacy mode: call table output parameters).

func (*QueryDescr) IsBulk

func (d *QueryDescr) IsBulk() bool

IsBulk returns true if the query is a bulk statement..

func (*QueryDescr) Kind

func (d *QueryDescr) Kind() QueryKind

Kind return the query kind of a query descriptor.

func (*QueryDescr) Query

func (d *QueryDescr) Query() string

Query return the query statement of a query descriptor.

func (*QueryDescr) String

func (d *QueryDescr) String() string

type QueryKind

type QueryKind int

QueryKind is the query type of a database statement.

const (
	QkUnknown QueryKind = iota
	QkCall
	QkSelect
	QkInsert
	QkUpdate
	QkUpsert
	QkCreate
	QkDrop
	QkSet
	QkID
)

Query kind constants.

func (QueryKind) String

func (k QueryKind) String() string

type ReadProvider

type ReadProvider interface {
	Reader() io.Reader
}

ReadProvider is the interface wrapping the Reader which provides an io.Reader.

type Session

type Session struct {
	// contains filtered or unexported fields
}

Session represents a HDB session.

func NewSession

func NewSession(ctx context.Context, rw *bufio.ReadWriter, attrs *SessionAttrs, auth *Auth) (*Session, error)

NewSession creates a new database session.

func (*Session) CloseResultsetID

func (s *Session) CloseResultsetID(id uint64) error

CloseResultsetID releases the hdb resultset handle.

func (*Session) Commit

func (s *Session) Commit() error

Commit executes a database commit.

func (*Session) DBConnectInfo added in v0.105.2

func (s *Session) DBConnectInfo(databaseName string) (*hdb.DBConnectInfo, error)

DBConnectInfo provided hdb connection information.

func (*Session) DatabaseName added in v0.105.2

func (s *Session) DatabaseName() string

DatabaseName returns the database name.

func (*Session) Disconnect

func (s *Session) Disconnect() error

Disconnect disconnects the session.

func (*Session) DropStatementID

func (s *Session) DropStatementID(id uint64) error

DropStatementID releases the hdb statement handle.

func (*Session) Exec

func (s *Session) Exec(pr *PrepareResult, nvargs []driver.NamedValue, commit bool) (driver.Result, error)

Exec executes a sql statement.

Bulk insert containing LOBs:

  • Precondition: .Sending more than one row with partial LOB data.
  • Observations: .In hdb version 1 and 2 'piecewise' LOB writing does work. .Same does not work in case of geo fields which are LOBs en,- decoded as well. .In hana version 4 'piecewise' LOB writing seems not to work anymore at all.
  • Server implementation (not documented): .'piecewise' LOB writing is only suppoerted for the last row of a 'bulk insert'.
  • Current implementation: One server call in case of
  • 'non bulk' execs or
  • 'bulk' execs without LOBs else potential several server calls (split into packages). Package invariant:
  • For all packages except the last one, the last row contains 'incomplete' LOB data ('piecewise' writing)

func (*Session) ExecCall

func (s *Session) ExecCall(pr *PrepareResult, nvargs []driver.NamedValue) (driver.Result, error)

ExecCall executes a stored procecure (by Exec).

func (*Session) ExecDirect

func (s *Session) ExecDirect(query string, commit bool) (driver.Result, error)

ExecDirect executes a sql statement without statement parameters.

func (*Session) HDBVersion

func (s *Session) HDBVersion() *hdb.Version

HDBVersion returns the hdb server version.

func (*Session) Prepare

func (s *Session) Prepare(query string) (*PrepareResult, error)

Prepare prepares a sql statement.

func (*Session) Query

func (s *Session) Query(pr *PrepareResult, nvargs []driver.NamedValue, commit bool) (driver.Rows, error)

Query executes a query.

func (*Session) QueryCall

func (s *Session) QueryCall(pr *PrepareResult, nvargs []driver.NamedValue) (driver.Rows, error)

QueryCall executes a stored procecure (by Query).

func (*Session) QueryDirect

func (s *Session) QueryDirect(query string, commit bool) (driver.Rows, error)

QueryDirect executes a query without query parameters.

func (*Session) Rollback

func (s *Session) Rollback() error

Rollback executes a database rollback.

func (*Session) SessionID

func (s *Session) SessionID() int64

SessionID returns the session id of the hdb connection.

type SessionAttrs added in v0.107.0

type SessionAttrs struct {
	// contains filtered or unexported fields
}

SessionAttrs represents the session relevant driver connector attributes.

func NewSessionAttrs added in v0.107.0

func NewSessionAttrs() *SessionAttrs

NewSessionAttrs returns a new SessionAttrs instance.

func (*SessionAttrs) ApplicationName added in v0.107.0

func (a *SessionAttrs) ApplicationName() string

ApplicationName returns the application name attribute.

func (*SessionAttrs) CESU8Decoder added in v0.107.0

func (a *SessionAttrs) CESU8Decoder() func() transform.Transformer

CESU8Decoder returns the CESU-8 decoder of the connector.

func (*SessionAttrs) CESU8Encoder added in v0.107.0

func (a *SessionAttrs) CESU8Encoder() func() transform.Transformer

CESU8Encoder returns the CESU-8 encoder of the connector.

func (*SessionAttrs) Clone added in v0.107.0

func (a *SessionAttrs) Clone() *SessionAttrs

Clone returns a clone of a SessionAttrs.

func (*SessionAttrs) Dfv added in v0.107.0

func (a *SessionAttrs) Dfv() int

Dfv returns the client data format version attribute.

func (*SessionAttrs) FetchSize added in v0.107.0

func (a *SessionAttrs) FetchSize() int

FetchSize returns the fetch size attribute.

func (*SessionAttrs) Legacy added in v0.107.0

func (a *SessionAttrs) Legacy() bool

Legacy returns the legacy attribute.

func (*SessionAttrs) LobChunkSize added in v0.107.0

func (a *SessionAttrs) LobChunkSize() int

LobChunkSize returns the lob chunk size attribute.

func (*SessionAttrs) Locale added in v0.107.0

func (a *SessionAttrs) Locale() string

Locale returns the locale attribute.

func (*SessionAttrs) SessionVariables added in v0.107.0

func (a *SessionAttrs) SessionVariables() map[string]string

SessionVariables returns the session variables attribute.

func (*SessionAttrs) SetApplicationName added in v0.107.0

func (a *SessionAttrs) SetApplicationName(name string)

SetApplicationName sets the application name attribute.

func (*SessionAttrs) SetCESU8Decoder added in v0.107.0

func (a *SessionAttrs) SetCESU8Decoder(cesu8Decoder func() transform.Transformer)

SetCESU8Decoder sets the CESU-8 decoder of the connector.

func (*SessionAttrs) SetCESU8Encoder added in v0.107.0

func (a *SessionAttrs) SetCESU8Encoder(cesu8Encoder func() transform.Transformer)

SetCESU8Encoder sets the CESU-8 encoder of the connector.

func (*SessionAttrs) SetDfv added in v0.107.0

func (a *SessionAttrs) SetDfv(dfv int)

SetDfv sets the client data format version attribute.

func (*SessionAttrs) SetFetchSize added in v0.107.0

func (a *SessionAttrs) SetFetchSize(fetchSize int)

SetFetchSize sets the fetch size attribute.

func (*SessionAttrs) SetLegacy added in v0.107.0

func (a *SessionAttrs) SetLegacy(b bool)

SetLegacy sets the connector legacy attribute.

func (*SessionAttrs) SetLobChunkSize added in v0.107.0

func (a *SessionAttrs) SetLobChunkSize(lobChunkSize int)

SetLobChunkSize sets the lob chunk size attribute.

func (*SessionAttrs) SetLocale added in v0.107.0

func (a *SessionAttrs) SetLocale(locale string)

SetLocale sets the locale attribute.

func (*SessionAttrs) SetSessionVariables added in v0.107.0

func (a *SessionAttrs) SetSessionVariables(sessionVariables map[string]string)

SetSessionVariables sets the session varibles attribute.

type Sniffer

type Sniffer struct {
	// contains filtered or unexported fields
}

A Sniffer is a simple proxy for logging hdb protocol requests and responses.

func NewSniffer

func NewSniffer(conn net.Conn, dbConn net.Conn) *Sniffer

NewSniffer creates a new sniffer instance. The conn parameter is the net.Conn connection, where the Sniffer is listening for hdb protocol calls. The dbAddr is the hdb host port address in "host:port" format.

func (*Sniffer) Do

func (s *Sniffer) Do() error

Do starts the protocol request and response logging.

type WriterSetter

type WriterSetter interface{ SetWriter(w io.Writer) error }

WriterSetter is the interface wrapping the SetWriter method (Lob handling).

Directories

Path Synopsis
Package encoding implements hdb field type en,- and decodings.
Package encoding implements hdb field type en,- and decodings.
Package scanner implements a HANA SQL query scanner.
Package scanner implements a HANA SQL query scanner.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL