Documentation ¶
Overview ¶
Package ase contains code of the cgo-ase driver for the database/sql package of Go (golang) to provide access to SAP ASE instances.
By using cgo this code is also enabled to call C code and to link against shared object. Thus, it is a shim to satisfy the databse/sql/driver-interface.
Index ¶
- Constants
- Variables
- func NewConnector(info *Info) (driver.Connector, error)
- func SetCallbackTarget(target *os.File)
- type ASEType
- type ClientMessage
- type Command
- type Connection
- func (conn *Connection) Begin() (driver.Tx, error)
- func (conn *Connection) BeginTx(ctx context.Context, opts driver.TxOptions) (driver.Tx, error)
- func (conn *Connection) CheckNamedValue(nv *driver.NamedValue) error
- func (conn *Connection) Close() error
- func (conn *Connection) Exec(query string, args []driver.Value) (driver.Result, error)
- func (conn *Connection) ExecContext(ctx context.Context, query string, args []driver.NamedValue) (driver.Result, error)
- func (conn *Connection) GenericExec(ctx context.Context, query string, args []driver.NamedValue) (driver.Rows, driver.Result, error)
- func (conn *Connection) NewCommand(ctx context.Context, query string) (*Command, error)
- func (conn *Connection) Ping(ctx context.Context) error
- func (conn *Connection) Prepare(query string) (driver.Stmt, error)
- func (conn *Connection) PrepareContext(ctx context.Context, query string) (driver.Stmt, error)
- func (conn *Connection) Query(query string, args []driver.Value) (driver.Rows, error)
- func (conn *Connection) QueryContext(ctx context.Context, query string, args []driver.NamedValue) (driver.Rows, error)
- type Info
- type Message
- type MessageHandler
- type MessageRecorder
- type Result
- type Rows
- func (rows *Rows) Close() error
- func (rows *Rows) ColumnTypeDatabaseTypeName(index int) string
- func (rows *Rows) ColumnTypeLength(index int) (int64, bool)
- func (rows *Rows) ColumnTypeMaxLength(index int) int64
- func (rows *Rows) ColumnTypeNullable(index int) (bool, bool)
- func (rows *Rows) ColumnTypePrecisionScale(index int) (int64, int64, bool)
- func (rows *Rows) ColumnTypeScanType(index int) reflect.Type
- func (rows *Rows) Columns() []string
- func (rows *Rows) Next(dest []driver.Value) error
- type ServerMessage
Constants ¶
const DriverName = "ase"
DriverName is the driver name to use with sql.Open for ase databases.
Variables ¶
var ( // GlobalServerMessageBroker sends server messages to all registered // handlers. GlobalServerMessageBroker = newMessageBroker() // GlobalClientMessageBroker sends client messages to all registered // handlers. GlobalClientMessageBroker = newMessageBroker() )
Functions ¶
func NewConnector ¶
NewConnector returns a new connector with the passed configuration.
func SetCallbackTarget ¶
SetCallbackTarget sets the os.File target the callback functions for client and server messages will write to.
Types ¶
type ASEType ¶
type ASEType byte
ASEType is the byte-representation of an ASE-datatype.
const ( BIGDATETIME ASEType = 35 BIGINT ASEType = 30 BIGTIME ASEType = 36 BINARY ASEType = 1 BIT ASEType = 11 BLOB ASEType = 26 BOUNDARY ASEType = 22 CHAR ASEType = 0 DATE ASEType = 27 DATETIME ASEType = 12 DATETIME4 ASEType = 13 DECIMAL ASEType = 17 FLOAT ASEType = 10 IMAGE ASEType = 5 IMAGELOCATOR ASEType = 38 INT ASEType = 8 LONG ASEType = 20 LONGBINARY ASEType = 3 LONGCHAR ASEType = 2 MONEY ASEType = 14 MONEY4 ASEType = 15 NUMERIC ASEType = 16 REAL ASEType = 9 SENSITIVITY ASEType = 21 SMALLINT ASEType = 7 TEXT ASEType = 4 TEXTLOCATOR ASEType = 37 TIME ASEType = 28 TINYINT ASEType = 6 UBIGINT ASEType = 33 UINT ASEType = 32 UNICHAR ASEType = 25 UNITEXT ASEType = 29 UNITEXTLOCATOR ASEType = 39 USER ASEType = 100 USHORT ASEType = 24 USMALLINT ASEType = 31 VARBINARY ASEType = 19 VARCHAR ASEType = 18 VOID ASEType = 23 XML ASEType = 34 )
func (ASEType) ToDataType ¶
ToDataType returns the equivalent asetypes.DataType for an ASEType.
type ClientMessage ¶
type ClientMessage struct { Severity int64 MsgNumber uint64 Text string OSNumber int64 OSString string Status int64 SQLState string }
ClientMessage is a message generated by Client-Library.
func (ClientMessage) Content ¶
func (msg ClientMessage) Content() string
Content returns the message-content of a client-message.
func (ClientMessage) MessageNumber ¶
func (msg ClientMessage) MessageNumber() uint64
MessageNumber returns the message-number of a client-message.
func (ClientMessage) MessageSeverity ¶
func (msg ClientMessage) MessageSeverity() int64
MessageSeverity returns the message-severity of a client-message.
type Command ¶
type Command struct {
// contains filtered or unexported fields
}
Command contains the C.command and indicates if that command is dynamic.
func (*Command) ConsumeResponse ¶
ConsumeResponse is a wrapper around .Response that guarantees that all results have been read.
func (*Command) Response ¶
Response reads a single response from the command structure and handles it.
When no more results are available this method returns io.EOF.
The third return value is a CS_INT, which may be the CS_RETCODE of ct_results when the command failed or finished or the result type if the result set requires further processing.
type Connection ¶
type Connection struct {
// contains filtered or unexported fields
}
Connection implements the driver.Conn interface.
func NewConnection ¶
func NewConnection(driverCtx *csContext, info *Info) (*Connection, error)
NewConnection allocates a new connection based on the options in the dsn.
If driverCtx is nil a new csContext will be initialized.
func (*Connection) Begin ¶
func (conn *Connection) Begin() (driver.Tx, error)
Begin implements the driver.Conn interface.
func (*Connection) CheckNamedValue ¶
func (conn *Connection) CheckNamedValue(nv *driver.NamedValue) error
CheckNamedValue implements the driver.NamedValueChecker interface.
func (*Connection) Close ¶
func (conn *Connection) Close() error
Close implements the driver.Conn interface. It closes and deallocates a connection.
func (*Connection) ExecContext ¶
func (conn *Connection) ExecContext(ctx context.Context, query string, args []driver.NamedValue) (driver.Result, error)
ExecContext implements the driver.ExecerContext interface.
func (*Connection) GenericExec ¶
func (conn *Connection) GenericExec(ctx context.Context, query string, args []driver.NamedValue) (driver.Rows, driver.Result, error)
GenericExec is the central method through which SQL statements are sent to ASE.
func (*Connection) NewCommand ¶
NewCommand creates a new command.
func (*Connection) Ping ¶
func (conn *Connection) Ping(ctx context.Context) error
Ping implements the driver.Pinger interface.
func (*Connection) Prepare ¶
func (conn *Connection) Prepare(query string) (driver.Stmt, error)
Prepare implements the driver.Conn interface.
func (*Connection) PrepareContext ¶
PrepareContext implements the driver.ConnPrepareContext interface.
func (*Connection) QueryContext ¶
func (conn *Connection) QueryContext(ctx context.Context, query string, args []driver.NamedValue) (driver.Rows, error)
QueryContext implements the driver.QueryerContext interface.
type Info ¶
type Info struct { dsn.Info AppName string `json:"appname" doc:"Application Name to transmit to ASE"` Userstorekey string `json:"key" multiref:"userstorekey" doc:"Key of userstore data to use for login"` TLSHostname string `json:"tls-hostname" doc:"Expected server TLS hostname to pass to C driver"` LogClientMsgs bool `json:"log-client-msgs" doc:"Log client messages"` LogServerMsgs bool `json:"log-server-msgs" doc:"Log server messages"` }
func NewInfoWithEnv ¶
NewInfoWithEnv is a convenience function returning an Info with values filled from the environment with the prefix 'ASE'.
type MessageHandler ¶
type MessageHandler func(Message)
MessageHandler describes the signature of a handler for server- and client messages.
type MessageRecorder ¶
type MessageRecorder struct { Messages []string // contains filtered or unexported fields }
MessageRecorder can be utilized to record non-SQL responses from the server.
See the example examples/recorder on how to utilize the MessageRecorder.
func NewMessageRecorder ¶
func NewMessageRecorder() *MessageRecorder
NewMessageRecorder returns an initialized MessageRecorder.
func (*MessageRecorder) HandleMessage ¶
func (rec *MessageRecorder) HandleMessage(msg Message)
HandleMessage implements the MessageHandler interface.
func (*MessageRecorder) Reset ¶
func (rec *MessageRecorder) Reset()
Reset prepares the MessageRecorder to record a new message.
func (*MessageRecorder) Text ¶
func (rec *MessageRecorder) Text() []string
Text returns the received messages.
type Result ¶
type Result struct {
// contains filtered or unexported fields
}
Result implements the driver.Result interface.
func (Result) LastInsertId ¶
LastInsertId implements the driver.Result interface.
func (Result) RowsAffected ¶
RowsAffected implements the driver.Result interface.
type Rows ¶
type Rows struct {
// contains filtered or unexported fields
}
Rows implements the driver.Rows interface.
func (*Rows) ColumnTypeDatabaseTypeName ¶
ColumnTypeDatabaseTypeName implements the driver.RowsColumnTypeDatabaseTypeName interface.
func (*Rows) ColumnTypeLength ¶
ColumnTypeLength implements the driver.RowsColumnTypeLength interface.
func (*Rows) ColumnTypeMaxLength ¶
ColumnTypeMaxLength returns the maximum length of the column-datatype.
func (*Rows) ColumnTypeNullable ¶
ColumnTypeNullable implements the driver.RowsColumnTypeNullable interface.
func (*Rows) ColumnTypePrecisionScale ¶
ColumnTypePrecisionScale implements the driver.RowsColumnTypePrecisionScale interface.
func (*Rows) ColumnTypeScanType ¶
ColumnTypeScanType returns the datatype of the column.
type ServerMessage ¶
type ServerMessage struct { MsgNumber uint64 State int64 Severity int64 Text string Server string Proc string Line int64 SQLState string }
ServerMessage is a message sent from the ASE server to the client.
func (ServerMessage) Content ¶
func (msg ServerMessage) Content() string
Content returns the message-content of a server-message.
func (ServerMessage) MessageNumber ¶
func (msg ServerMessage) MessageNumber() uint64
MessageNumber returns the message-number of a server-message.
func (ServerMessage) MessageSeverity ¶
func (msg ServerMessage) MessageSeverity() int64
MessageSeverity returns the message-severity of a server-message.
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
cmd
|
|
examples
|
|
genericexec
This example shows how to utilize the GenericExecer interface if both driver.Rows and driver.Result of a statement are required.
|
This example shows how to utilize the GenericExecer interface if both driver.Rows and driver.Result of a statement are required. |
recorder
This example shows how the cgo.MessageRecorder can be used to process messages from the TDS server.
|
This example shows how the cgo.MessageRecorder can be used to process messages from the TDS server. |
recorder2
This example shows how a custom recorder can be implemented to process messages from the TDS server.
|
This example shows how a custom recorder can be implemented to process messages from the TDS server. |
simple
This example shows a simple interaction with a TDS server using the database/sql interface and the cgo-based driver.
|
This example shows a simple interaction with a TDS server using the database/sql interface and the cgo-based driver. |
simple2
This example shows a simple interaction with a TDS server using the database/sql interface, prepared statements and the cgo-based driver.
|
This example shows a simple interaction with a TDS server using the database/sql interface, prepared statements and the cgo-based driver. |