odbc

package module
v1.0.10 Latest Latest
Warning

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

Go to latest
Published: Mar 3, 2021 License: BSD-3-Clause Imports: 14 Imported by: 0

README

odbc driver written in go. Implements database driver interface as used by standard database/sql package. It calls into odbc dll on Windows, and uses cgo (unixODBC) everywhere else.

To get started using odbc, have a look at the wiki pages.

Documentation

Overview

Package odbc implements database/sql driver to access data via odbc interface.

Index

Constants

This section is empty.

Variables

View Source
var ErrTXAlreadyStarted = errors.New("already in a transaction")
View Source
var ErrTXCompleted = errors.New("transaction already completed")

Functions

func IsError

func IsError(ret api.SQLRETURN) bool

func NewError

func NewError(apiName string, handle interface{}) error

func ToHandleAndType

func ToHandleAndType(handle interface{}) (h api.SQLHANDLE, ht api.SQLSMALLINT, err error)

Types

type BaseColumn

type BaseColumn struct {
	SQLType api.SQLSMALLINT
	CType   api.SQLSMALLINT
	// contains filtered or unexported fields
}

BaseColumn implements common column functionality.

func (*BaseColumn) Name

func (c *BaseColumn) Name() string

func (*BaseColumn) Value

func (c *BaseColumn) Value(buf []byte) (driver.Value, error)

type BindableColumn

type BindableColumn struct {
	*BaseColumn
	IsBound         bool
	IsVariableWidth bool
	Size            int
	Len             BufferLen
	Buffer          []byte
}

BindableColumn allows access to columns that can have their buffers bound. Once bound at start, they are written to by odbc driver every time it fetches new row. This saves on syscall and, perhaps, some buffer copying. BindableColumn can be left unbound, then it behaves like NonBindableColumn when user reads data from it.

func NewBindableColumn

func NewBindableColumn(b *BaseColumn, ctype api.SQLSMALLINT, bufSize int) *BindableColumn

func (*BindableColumn) Bind

func (c *BindableColumn) Bind(h api.SQLHSTMT, idx int) (bool, error)

func (*BindableColumn) Value

func (c *BindableColumn) Value(h api.SQLHSTMT, idx int) (driver.Value, error)

type BufferLen

type BufferLen api.SQLLEN

func (*BufferLen) Bind

func (l *BufferLen) Bind(h api.SQLHSTMT, idx int, ctype api.SQLSMALLINT, buf []byte) api.SQLRETURN

func (*BufferLen) GetData

func (l *BufferLen) GetData(h api.SQLHSTMT, idx int, ctype api.SQLSMALLINT, buf []byte) api.SQLRETURN

func (*BufferLen) IsNull

func (l *BufferLen) IsNull() bool

type Column

type Column interface {
	Name() string
	Bind(h api.SQLHSTMT, idx int) (bool, error)
	Value(h api.SQLHSTMT, idx int) (driver.Value, error)
}

Column provides access to row columns.

func NewColumn

func NewColumn(h api.SQLHSTMT, idx int) (Column, error)

func NewVariableWidthColumn

func NewVariableWidthColumn(b *BaseColumn, ctype api.SQLSMALLINT, colWidth api.SQLULEN) (Column, error)

type Conn

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

func (*Conn) Begin

func (c *Conn) Begin() (driver.Tx, error)

implement driver.Conn

func (*Conn) BeginTx added in v1.0.6

func (c *Conn) BeginTx(ctx context.Context, opts driver.TxOptions) (tx driver.Tx, err error)

implement driver.ConnBeginTx

func (*Conn) Close

func (c *Conn) Close() (err error)

implement driver.Conn

func (*Conn) Exec added in v1.0.6

func (c *Conn) Exec(query string, args []driver.Value) (driver.Result, error)

implement driver.Execer

func (*Conn) ExecContext

func (c *Conn) ExecContext(ctx context.Context, query string, args []driver.NamedValue) (result driver.Result, err error)

implement driver.ExecerContext

func (*Conn) Ping added in v1.0.6

func (c *Conn) Ping(ctx context.Context) error

implement driver.Pinger

func (*Conn) Prepare

func (c *Conn) Prepare(query string) (driver.Stmt, error)

implement driver.Conn

func (*Conn) PrepareContext

func (c *Conn) PrepareContext(ctx context.Context, query string) (driver.Stmt, error)

implement driver.ConnPrepareContext

func (*Conn) Query added in v1.0.6

func (c *Conn) Query(query string, args []driver.Value) (driver.Rows, error)

implement driver.Queryer

func (*Conn) QueryContext

func (c *Conn) QueryContext(ctx context.Context, query string, args []driver.NamedValue) (rows driver.Rows, err error)

implement driver.QueryerContext

func (*Conn) ResetSession added in v1.0.6

func (c *Conn) ResetSession(ctx context.Context) error

implement driver.SessionResetter

type DiagRecord

type DiagRecord struct {
	State       string
	NativeError int
	Message     string
}

func (*DiagRecord) String

func (r *DiagRecord) String() string

type Driver

type Driver struct {
	Stats
	// contains filtered or unexported fields
}

func (*Driver) Close

func (d *Driver) Close() error

TODO(ninthclowd): this is not part of the driver.Driver interface and will never be called by a consumer

func (*Driver) Open

func (d *Driver) Open(name string) (driver.Conn, error)

implement driver.Driver

func (*Driver) OpenConnector added in v1.0.6

func (d *Driver) OpenConnector(name string) (driver.Connector, error)

implement driver.DriverContext

type Error

type Error struct {
	APIName string
	Diag    []DiagRecord
}

func (*Error) Error

func (e *Error) Error() string

type NonBindableColumn

type NonBindableColumn struct {
	*BaseColumn
}

NonBindableColumn provide access to columns, that can't be bound. These are of character or binary type, and, usually, there is no limit for their width.

func (*NonBindableColumn) Bind

func (c *NonBindableColumn) Bind(h api.SQLHSTMT, idx int) (bool, error)

func (*NonBindableColumn) Value

func (c *NonBindableColumn) Value(h api.SQLHSTMT, idx int) (driver.Value, error)

type Parameter

type Parameter struct {
	SQLType api.SQLSMALLINT
	Decimal api.SQLSMALLINT
	Size    api.SQLULEN

	// Following fields store data used later by SQLExecute.
	// The fields keep data alive and away from gc.
	Data             interface{}
	StrLen_or_IndPtr api.SQLLEN
	// contains filtered or unexported fields
}

func ExtractParameters

func ExtractParameters(h api.SQLHSTMT) ([]Parameter, error)

func (*Parameter) BindValue

func (p *Parameter) BindValue(h api.SQLHSTMT, idx int, v driver.Value, conn *Conn) error

func (*Parameter) StoreStrLen_or_IndPtr

func (p *Parameter) StoreStrLen_or_IndPtr(v api.SQLLEN) *api.SQLLEN

StoreStrLen_or_IndPtr stores v into StrLen_or_IndPtr field of p and returns address of that field.

type Result

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

func (*Result) LastInsertId

func (r *Result) LastInsertId() (int64, error)

implement driver.Result

func (*Result) RowsAffected

func (r *Result) RowsAffected() (int64, error)

implement driver.Result

type Rows

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

func (*Rows) Close

func (r *Rows) Close() error

implement driver.Rows

func (*Rows) Columns

func (r *Rows) Columns() []string

implement driver.Rows

func (*Rows) HasNextResultSet

func (r *Rows) HasNextResultSet() bool

implement driver.RowsNextResultSet

func (*Rows) Next

func (r *Rows) Next(dest []driver.Value) error

implement driver.Rows

func (*Rows) NextResultSet

func (r *Rows) NextResultSet() error

implement driver.RowsNextResultSet

type Stats

type Stats struct {
	EnvCount  *atomic.Int32
	ConnCount *atomic.Int32
	StmtCount *atomic.Int32
}

type Stmt

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

func (*Stmt) Close

func (s *Stmt) Close() error

implement driver.Stmt Close closes the statement.

As of Go 1.1, a Stmt will not be closed if it's in use by any queries.

func (*Stmt) Exec

func (s *Stmt) Exec(args []driver.Value) (driver.Result, error)

implement driver.Stmt - per documentation, not supposed to be used by multiple goroutines

func (*Stmt) ExecContext

func (s *Stmt) ExecContext(ctx context.Context, args []driver.NamedValue) (driver.Result, error)

implement driver.StmtExecContext

func (*Stmt) NumInput

func (s *Stmt) NumInput() int

implement driver.Stmt

func (*Stmt) Query

func (s *Stmt) Query(args []driver.Value) (driver.Rows, error)

implement driver.Stmt - per documentation, not supposed to be used by multiple goroutines

func (*Stmt) QueryContext

func (s *Stmt) QueryContext(ctx context.Context, args []driver.NamedValue) (driver.Rows, error)

implement driver.StmtQueryContext

type Tx

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

func (*Tx) Commit

func (tx *Tx) Commit() error

implement driver.Tx

func (*Tx) Rollback

func (tx *Tx) Rollback() error

implement driver.Tx

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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