Documentation ¶
Overview ¶
Package goracle is a database/sql/driver for Oracle DB.
The connection string for the sql.Open("goracle", connString) call can be the simple
loin/password@sid [AS SYSDBA|AS SYSOPER]
type (with sid being the sexp returned by tnsping), or in the form of
ora://login:password@sid/? \ sysdba=0& \ sysoper=0& \ poolMinSessions=1& \ poolMaxSessions=1000& \ poolIncrement=1& \ connectionClass=POOLED
These are the defaults. Many advocate that a static session pool (min=max, incr=0) is better, with 1-10 sessions per CPU thread. See http://docs.oracle.com/cd/E82638_01/JJUCP/optimizing-real-world-performance.htm#JJUCP-GUID-BC09F045-5D80-4AF5-93F5-FEF0531E0E1D
If you specify connectionClass, that'll reuse the same session pool without the connectionClass, but will specify it on each session acquire. Thus you can cluster the session pool with classes, or ose POOLED for DRCP.
Index ¶
- Constants
- Variables
- func CallbackSubscr(ctx unsafe.Pointer, message *C.dpiSubscrMessage)
- func ContextWithLog(ctx context.Context, logF func(...interface{}) error) context.Context
- func ContextWithTraceTag(ctx context.Context, tt TraceTag) context.Context
- func EnableDbmsOutput(ctx context.Context, conn Execer) error
- func MapToSlice(qry string, metParam func(string) interface{}) (string, []interface{})
- func NamedToOrdered(qry string, namedParams map[string]interface{}) (string, []interface{})
- func ReadDbmsOutput(ctx context.Context, w io.Writer, conn preparer) error
- type Column
- type CompileError
- type Conn
- type ConnectionParams
- type Data
- func (d *Data) Get() interface{}
- func (d *Data) GetBool() bool
- func (d *Data) GetBytes() []byte
- func (d *Data) GetFloat32() float32
- func (d *Data) GetFloat64() float64
- func (d *Data) GetInt64() int64
- func (d *Data) GetIntervalDS() time.Duration
- func (d *Data) GetIntervalYM() IntervalYM
- func (d *Data) GetLob() *Lob
- func (d *Data) GetObject() *Object
- func (d *Data) GetStmt() driver.Stmt
- func (d *Data) GetTime() time.Time
- func (d *Data) GetUint64() uint64
- func (d *Data) IsNull() bool
- func (d *Data) SetBool(b bool)
- func (d *Data) SetBytes(b []byte)
- func (d *Data) SetFloat32(f float32)
- func (d *Data) SetFloat64(f float64)
- func (d *Data) SetInt64(i int64)
- func (d *Data) SetIntervalDS(dur time.Duration)
- func (d *Data) SetIntervalYM(ym IntervalYM)
- func (d *Data) SetObject(o *Object)
- func (d *Data) SetStmt(s *statement)
- func (d *Data) SetTime(t time.Time)
- func (d *Data) SetUint64(u uint64)
- type DataTypeInfo
- type DirectLob
- type Event
- type EventType
- type Execer
- type IntervalYM
- type Lob
- type Number
- func (n Number) MarshalJSON() ([]byte, error)
- func (n Number) MarshalText() ([]byte, error)
- func (n *Number) Scan(v interface{}) error
- func (n Number) String() string
- func (n *Number) UnmarshalJSON(p []byte) error
- func (n *Number) UnmarshalText(p []byte) error
- func (n Number) Value() (driver.Value, error)
- type Object
- type ObjectAttribute
- type ObjectCollection
- func (O *ObjectCollection) Append(data *Data) error
- func (d ObjectCollection) ClientVersion() (VersionInfo, error)
- func (O *ObjectCollection) Delete(i int) error
- func (O *ObjectCollection) First() (int, error)
- func (O *ObjectCollection) Get(data *Data, i int) error
- func (O *ObjectCollection) Last() (int, error)
- func (O *ObjectCollection) Len() (int, error)
- func (O *ObjectCollection) Next(i int) (int, error)
- func (d ObjectCollection) Open(connString string) (driver.Conn, error)
- func (O *ObjectCollection) Set(i int, data *Data) error
- func (O *ObjectCollection) Trim(n int) error
- type ObjectCollectionInfo
- type ObjectInfo
- type ObjectType
- type Operation
- type Option
- type OraErr
- type QueryColumn
- type QueryEvent
- type RowEvent
- type Subscription
- func (c Subscription) Begin() (driver.Tx, error)deprecated
- func (c Subscription) BeginTx(ctx context.Context, opts driver.TxOptions) (driver.Tx, error)
- func (c Subscription) Break() error
- func (s *Subscription) Close() error
- func (c Subscription) Commit() error
- func (c Subscription) GetObjectType(name string) (*ObjectType, error)
- func (c Subscription) NewSubscription(name string, cb func(Event)) (*Subscription, error)
- func (c Subscription) Ping(ctx context.Context) error
- func (c Subscription) Prepare(query string) (driver.Stmt, error)
- func (c Subscription) PrepareContext(ctx context.Context, query string) (driver.Stmt, error)
- func (s *Subscription) Register(qry string, params ...interface{}) error
- func (c Subscription) Rollback() error
- func (c Subscription) ServerVersion() (VersionInfo, error)
- type TableEvent
- type TraceTag
- type VersionInfo
Constants ¶
const ( // DefaultFetchRowCount is the number of prefetched rows by default (if not changed through FetchRowCount statement option). DefaultFetchRowCount = 1 << 8 // DefaultArraySize is the length of the maximum PL/SQL array by default (if not changed through ArraySize statement option). DefaultArraySize = 1 << 10 )
const ( // DpiMajorVersion is the wanted major version of the underlying ODPI-C library. DpiMajorVersion = C.DPI_MAJOR_VERSION // DpiMinorVersion is the wanted minor version of the underlying ODPI-C library. DpiMinorVersion = C.DPI_MINOR_VERSION // DriverName is set on the connection to be seen in the DB DriverName = "gopkg.in/goracle.v2 : " + Version // DefaultPoolMinSessions specifies the default value for minSessions for pool creation. DefaultPoolMinSessions = 1 // DefaultPoolMaxSessions specifies the default value for maxSessions for pool creation. DefaultPoolMaxSessions = 1000 // DefaultPoolIncrement specifies the default value for increment for pool creation. DefaultPoolIncrement = 1 // DefaultConnectionClass is the defailt connectionClass DefaultConnectionClass = "GORACLE" )
const ( EvtStartup = EventType(C.DPI_EVENT_STARTUP) EvtShutdown = EventType(C.DPI_EVENT_SHUTDOWN) EvtShutdownAny = EventType(C.DPI_EVENT_SHUTDOWN_ANY) EvtDropDB = EventType(C.DPI_EVENT_DROP_DB) EvtDereg = EventType(C.DPI_EVENT_DEREG) EvtObjChange = EventType(C.DPI_EVENT_OBJCHANGE) EvtQueryChange = EventType(C.DPI_EVENT_QUERYCHANGE) )
Events that can be watched.
const ( // OpAll Indicates that notifications should be sent for all operations on the table or query. OpAll = Operation(C.DPI_OPCODE_ALL_OPS) // OpAllRows Indicates that all rows have been changed in the table or query (or too many rows were changed or row information was not requested). OpAllRows = Operation(C.DPI_OPCODE_ALL_ROWS) // OpInsert Indicates that an insert operation has taken place in the table or query. OpInsert = Operation(C.DPI_OPCODE_INSERT) // OpUpdate Indicates that an update operation has taken place in the table or query. OpUpdate = Operation(C.DPI_OPCODE_UPDATE) // OpDelete Indicates that a delete operation has taken place in the table or query. OpDelete = Operation(C.DPI_OPCODE_DELETE) // OpAlter Indicates that the registered table or query has been altered. OpAlter = Operation(C.DPI_OPCODE_ALTER) // OpDrop Indicates that the registered table or query has been dropped. OpDrop = Operation(C.DPI_OPCODE_DROP) // OpUnknown An unknown operation has taken place. OpUnknown = Operation(C.DPI_OPCODE_UNKNOWN) )
const Version = "v2.1.14"
Version of this driver
Variables ¶
var ( // Int64 for converting to-from int64. Int64 = intType{} // Float64 for converting to-from float64. Float64 = floatType{} // Num for converting to-from Number (string) Num = numType{} )
var ErrNotCollection = errors.New("not collection")
ErrNotCollection is returned when the Object is not a collection.
var ErrNotExist = errors.New("not exist")
ErrNotExist is returned when the collection's requested element does not exist.
var Log func(...interface{}) error
Log function. By default, it's nil, and thus logs nothing. If you want to change this, change it to a github.com/go-kit/kit/log.Swapper.Log or analog to be race-free.
Functions ¶
func CallbackSubscr ¶
func CallbackSubscr(ctx unsafe.Pointer, message *C.dpiSubscrMessage)
CallbackSubscr is the callback for C code on subscription event.
func ContextWithLog ¶
ContextWithLog returns a context with the given log function.
func ContextWithTraceTag ¶
ContextWithTraceTag returns a context with the specified TraceTag, which will be set on the session used.
func EnableDbmsOutput ¶
EnableDbmsOutput enables DBMS_OUTPUT buffering on the given connection. This is required if you want to retrieve the output with ReadDbmsOutput later.
func MapToSlice ¶
MapToSlice modifies query for map (:paramname) to :%d placeholders + slice of params.
Calls metParam for each parameter met, and returns the slice of their results.
func NamedToOrdered ¶
NamedToOrdered converts the query from named params (:paramname) to :%d placeholders + slice of params, copying the params verbatim.
Types ¶
type Column ¶
type Column struct { Name string OracleType C.dpiOracleTypeNum NativeType C.dpiNativeTypeNum Size C.uint32_t Precision C.int16_t Scale C.int8_t Nullable bool ObjectType *C.dpiObjectType }
Column holds the info from a column.
type CompileError ¶
type CompileError struct {
Owner, Name, Type string
Line, Position, Code int64
Text string
Warning bool
}
CompileError represents a compile-time error as in user_errors view.
func GetCompileErrors ¶
func GetCompileErrors(queryer queryer, all bool) ([]CompileError, error)
GetCompileErrors returns the slice of the errors in user_errors.
If all is false, only errors are returned; otherwise, warnings, too.
func (CompileError) Error ¶
func (ce CompileError) Error() string
type Conn ¶
type Conn interface { driver.Conn driver.Pinger Break() error BeginTx(ctx context.Context, opts driver.TxOptions) (driver.Tx, error) PrepareContext(ctx context.Context, query string) (driver.Stmt, error) Commit() error Rollback() error ServerVersion() (VersionInfo, error) GetObjectType(name string) (*ObjectType, error) NewSubscription(string, func(Event)) (*Subscription, error) }
func DriverConn ¶
DriverConn returns the *goracle.conn of the databas/sql.Conn
type ConnectionParams ¶
type ConnectionParams struct {
Username, Password, SID, ConnClass string
IsSysDBA, IsSysOper bool
MinSessions, MaxSessions, PoolIncrement int
}
ConnectionParams holds the params for a connection (pool). You can use ConnectionParams{...}.String() as a connection string in sql.Open.
func ParseConnString ¶
func ParseConnString(connString string) (ConnectionParams, error)
ParseConnString parses the given connection string into a struct.
func (ConnectionParams) String ¶
func (P ConnectionParams) String() string
func (ConnectionParams) StringNoClass ¶
func (P ConnectionParams) StringNoClass() string
StringNoClass returns the string representation of ConnectionParams, without class info.
type Data ¶
type Data struct { NativeTypeNum C.dpiNativeTypeNum // contains filtered or unexported fields }
Data holds the data to/from Oracle.
func (*Data) GetFloat32 ¶
GetFloat32 gets float32 from the data.
func (*Data) GetFloat64 ¶
GetFloat64 gets float64 from the data.
func (*Data) GetIntervalDS ¶
GetIntervalDS gets duration as interval date-seconds from data.
func (*Data) GetIntervalYM ¶
func (d *Data) GetIntervalYM() IntervalYM
GetIntervalYM gets IntervalYM from the data.
func (*Data) SetIntervalDS ¶
SetIntervalDS sets the duration as interval date-seconds to data.
func (*Data) SetIntervalYM ¶
func (d *Data) SetIntervalYM(ym IntervalYM)
SetIntervalYM sets IntervalYM to the data.
type DataTypeInfo ¶
type DataTypeInfo struct { OracleTypeNum C.dpiOracleTypeNum NativeTypeNum C.dpiNativeTypeNum ObjectType *ObjectType DBSize, ClientSizeInBytes, CharSize int Precision int16 Scale int8 FsPrecision uint8 }
DataTypeInfo holds type info for a Data.
type DirectLob ¶
type DirectLob struct {
// contains filtered or unexported fields
}
DirectLob holds a Lob and allows direct (Read/WriteAt, not streaming Read/Write) operations on it.
type Event ¶
type Event struct { Err error Type EventType DB string Tables []TableEvent Queries []QueryEvent }
Event for a subscription.
type IntervalYM ¶
type IntervalYM struct {
Years, Months int
}
IntervalYM holds Years and Months as interval.
type Number ¶
type Number string
Number as string
func (Number) MarshalJSON ¶
func (Number) MarshalText ¶
func (*Number) UnmarshalJSON ¶
func (*Number) UnmarshalText ¶
type Object ¶
type Object struct { *ObjectType // contains filtered or unexported fields }
Object represents a dpiObject.
func (Object) ClientVersion ¶
func (d Object) ClientVersion() (VersionInfo, error)
func (*Object) GetAttribute ¶
GetAttribute gets the i-th attribute into data.
type ObjectAttribute ¶
type ObjectAttribute struct { Name string DataTypeInfo // contains filtered or unexported fields }
ObjectAttribute is an attribute of an Object.
func (ObjectAttribute) ClientVersion ¶
func (d ObjectAttribute) ClientVersion() (VersionInfo, error)
type ObjectCollection ¶
type ObjectCollection struct {
Object
}
ObjectCollection represents a Collection of Objects - itself an Object, too.
func (*ObjectCollection) Append ¶
func (O *ObjectCollection) Append(data *Data) error
Append data to the collection.
func (ObjectCollection) ClientVersion ¶
func (d ObjectCollection) ClientVersion() (VersionInfo, error)
func (*ObjectCollection) Delete ¶
func (O *ObjectCollection) Delete(i int) error
Delete i-th element of the collection.
func (*ObjectCollection) First ¶
func (O *ObjectCollection) First() (int, error)
First returns the first element's index of the collection.
func (*ObjectCollection) Get ¶
func (O *ObjectCollection) Get(data *Data, i int) error
Get the i-th element of the collection into data.
func (*ObjectCollection) Last ¶
func (O *ObjectCollection) Last() (int, error)
Last returns the index of the last element.
func (*ObjectCollection) Len ¶
func (O *ObjectCollection) Len() (int, error)
Len returns the length of the collection.
func (*ObjectCollection) Next ¶
func (O *ObjectCollection) Next(i int) (int, error)
Next returns the succeeding index of i.
func (ObjectCollection) Open ¶
Open returns a new connection to the database. The name is a string in a driver-specific format.
func (*ObjectCollection) Set ¶
func (O *ObjectCollection) Set(i int, data *Data) error
Set the i-th element of the collection with data.
func (*ObjectCollection) Trim ¶
func (O *ObjectCollection) Trim(n int) error
Trim the collection to n.
type ObjectCollectionInfo ¶
type ObjectCollectionInfo interface { OracleTypeNum() C.dpiOracleTypeNum NativeTypeNum() C.dpiNativeTypeNum ObjectType() *ObjectType }
ObjectCollectionInfo holds type info of the collection.
type ObjectInfo ¶
ObjectInfo holds Object type info.
type ObjectType ¶
type ObjectType struct {
// contains filtered or unexported fields
}
ObjectType holds type info of an Object.
func GetObjectType ¶
func GetObjectType(ex Execer, typeName string) (*ObjectType, error)
GetObjectType returns the ObjectType for the name.
func (*ObjectType) Attributes ¶
func (t *ObjectType) Attributes() ([]ObjectAttribute, error)
Attributes of the ObjectType.
func (ObjectType) ClientVersion ¶
func (d ObjectType) ClientVersion() (VersionInfo, error)
func (*ObjectType) Info ¶
func (t *ObjectType) Info() (ObjectInfo, error)
Info returns ObjectInfo of the ObjectType.
func (*ObjectType) NewObject ¶
func (t *ObjectType) NewObject() (*Object, error)
NewObject returns a new Object with ObjectType type.
type Option ¶
type Option func(*stmtOptions)
Option holds statement options.
PlSQLArrays is to signal that the slices given in arguments of Exec to be left as is - the default is to treat them as arguments for ExecMany.
func ArraySize ¶
ArraySize returns an option to set the array size to be used, overriding DefaultArraySize.
func FetchRowCount ¶
FetchRowCount returns an option to set the rows to be fetched, overriding DefaultFetchRowCount.
type QueryColumn ¶
QueryColumn is the described column.
func DescribeQuery ¶
DescribeQuery describes the columns in the qry.
This can help using unknown-at-compile-time, a.k.a. dynamic queries.
type QueryEvent ¶
type QueryEvent struct { Operation ID uint64 Tables []TableEvent }
QueryEvent is an event of a Query.
type Subscription ¶
type Subscription struct {
// contains filtered or unexported fields
}
Subscription for events in the DB.
func (Subscription) BeginTx ¶
BeginTx starts and returns a new transaction. If the context is canceled by the user the sql package will call Tx.Rollback before discarding and closing the connection.
This must check opts.Isolation to determine if there is a set isolation level. If the driver does not support a non-default level and one is set or if there is a non-default isolation level that is not supported, an error must be returned.
This must also check opts.ReadOnly to determine if the read-only value is true to either set the read-only transaction property if supported or return an error if it is not supported.
func (Subscription) GetObjectType ¶
func (c Subscription) GetObjectType(name string) (*ObjectType, error)
GetObjectType returns the ObjectType of a name.
func (Subscription) NewSubscription ¶
func (c Subscription) NewSubscription(name string, cb func(Event)) (*Subscription, error)
NewSubscription creates a new Subscription in the DB.
func (Subscription) PrepareContext ¶
PrepareContext returns a prepared statement, bound to this connection. context is for the preparation of the statement, it must not store the context within the statement itself.
func (*Subscription) Register ¶
func (s *Subscription) Register(qry string, params ...interface{}) error
Register a query for Change Notification.
func (Subscription) ServerVersion ¶
func (c Subscription) ServerVersion() (VersionInfo, error)
type TableEvent ¶
TableEvent is for a Table-related event.
type TraceTag ¶
type TraceTag struct { // ClientIdentifier - specifies an end user based on the logon ID, such as HR.HR ClientIdentifier string // ClientInfo - client-specific info ClientInfo string // DbOp - database operation DbOp string // Module - specifies a functional block, such as Accounts Receivable or General Ledger, of an application Module string // Action - specifies an action, such as an INSERT or UPDATE operation, in a module Action string }
type VersionInfo ¶
type VersionInfo struct {
Version, Release, Update, PortRelease, PortUpdate, Full int
ServerRelease string
}
VersionInfo holds version info returned by Oracle DB.
func ClientVersion ¶
func ClientVersion(ex Execer) (VersionInfo, error)
ClientVersion returns the VersionInfo from the DB.
func ServerVersion ¶
func ServerVersion(ex Execer) (VersionInfo, error)
ServerVersion returns the VersionInfo of the client.
func (VersionInfo) String ¶
func (V VersionInfo) String() string