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 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 ParseConnString(connString string) (connectionParams, error)
- func ReadDbmsOutput(ctx context.Context, w io.Writer, conn preparer) error
- type Column
- type CompileError
- 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() *statement
- 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 IntervalYM
- type Lob
- type Number
- 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 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(events chan<- Event, name string) (*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 VersionInfo
Constants ¶
const ( // DpiMajorVersion is the wanted major version of the underlying ODPI-C library. DpiMajorVersion = 2 // DpiMinorVersion is the wanted minor version of the underlying ODPI-C library. DpiMinorVersion = 0 // 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 // DefaultPoolInrement 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) )
const ( // Indicates that notifications should be sent for all operations on the table or query. OpAll = Operation(C.DPI_OPCODE_ALL_OPS) // 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) // Indicates that an insert operation has taken place in the table or query. OpInsert = Operation(C.DPI_OPCODE_INSERT) // Indicates that an update operation has taken place in the table or query. OpUpdate = Operation(C.DPI_OPCODE_UPDATE) // Indicates that a delete operation has taken place in the table or query. OpDelete = Operation(C.DPI_OPCODE_DELETE) // Indicates that the registered table or query has been altered. OpAlter = Operation(C.DPI_OPCODE_ALTER) // Indicates that the registered table or query has been dropped. OpDrop = Operation(C.DPI_OPCODE_DROP) // An unknown operation has taken place. OpUnknown = Operation(C.DPI_OPCODE_UNKNOWN) )
const PlSQLArrays = Option(1)
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.
const Version = "v5.0.3"
Version of this driver
Variables ¶
var ( Int64 = intType{} Float64 = floatType{} Num = numType{} )
var ErrNotCollection = errors.New("not collection")
var ErrNotExist = errors.New("not exist")
var Log = func(...interface{}) error { return nil }
Log function
Functions ¶
func CallbackSubscr ¶
func CallbackSubscr(ctx unsafe.Pointer, message *C.dpiSubscrMessage)
func ContextWithLog ¶
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.
func ParseConnString ¶
ParseConnString parses the given connection string into a struct.
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 Data ¶
type Data struct { NativeTypeNum C.dpiNativeTypeNum // contains filtered or unexported fields }
func (*Data) GetFloat32 ¶
func (*Data) GetFloat64 ¶
func (*Data) GetIntervalDS ¶
func (*Data) GetIntervalYM ¶
func (d *Data) GetIntervalYM() IntervalYM
func (*Data) SetFloat32 ¶
func (*Data) SetFloat64 ¶
func (*Data) SetIntervalDS ¶
func (*Data) SetIntervalYM ¶
func (d *Data) SetIntervalYM(ym IntervalYM)
type DataTypeInfo ¶
type DataTypeInfo struct { OracleTypeNum C.dpiOracleTypeNum NativeTypeNum C.dpiNativeTypeNum ObjectType *ObjectType DBSize, ClientSizeInBytes, CharSize int Precision int16 Scale int8 FsPrecision uint8 }
type Event ¶
type Event struct { Err error Type EventType DB string Tables []TableEvent Queries []QueryEvent }
type EventType ¶
type EventType C.dpiEventType
type IntervalYM ¶
type IntervalYM struct {
Years, Months int
}
type Object ¶
type Object struct { *ObjectType // contains filtered or unexported fields }
func (Object) ClientVersion ¶
func (d Object) ClientVersion() (VersionInfo, error)
type ObjectAttribute ¶
type ObjectAttribute struct { Name string DataTypeInfo // contains filtered or unexported fields }
func (ObjectAttribute) ClientVersion ¶
func (d ObjectAttribute) ClientVersion() (VersionInfo, error)
func (ObjectAttribute) Close ¶
func (A ObjectAttribute) Close() error
type ObjectCollection ¶
type ObjectCollection struct {
Object
}
func (*ObjectCollection) Append ¶
func (O *ObjectCollection) Append(data *Data) error
func (ObjectCollection) ClientVersion ¶
func (d ObjectCollection) ClientVersion() (VersionInfo, error)
func (*ObjectCollection) Delete ¶
func (O *ObjectCollection) Delete(i int) error
func (*ObjectCollection) First ¶
func (O *ObjectCollection) First() (int, error)
func (*ObjectCollection) Last ¶
func (O *ObjectCollection) Last() (int, error)
func (*ObjectCollection) Len ¶
func (O *ObjectCollection) Len() (int, error)
func (ObjectCollection) Open ¶
Open returns a new connection to the database. The name is a string in a driver-specific format.
func (*ObjectCollection) Trim ¶
func (O *ObjectCollection) Trim(n int) error
type ObjectCollectionInfo ¶
type ObjectCollectionInfo interface { OracleTypeNum() C.dpiOracleTypeNum NativeTypeNum() C.dpiNativeTypeNum ObjectType() *ObjectType }
type ObjectInfo ¶
type ObjectType ¶
type ObjectType struct {
// contains filtered or unexported fields
}
func GetObjectType ¶
func GetObjectType(ex execer, typeName string) (*ObjectType, error)
func (*ObjectType) Attributes ¶
func (t *ObjectType) Attributes() ([]ObjectAttribute, error)
func (ObjectType) ClientVersion ¶
func (d ObjectType) ClientVersion() (VersionInfo, error)
func (*ObjectType) Info ¶
func (t *ObjectType) Info() (ObjectInfo, error)
func (*ObjectType) NewObject ¶
func (t *ObjectType) NewObject() (*Object, error)
type QueryColumn ¶
type QueryColumn struct {
Schema, Name string
Type, Length, Precision, Scale int
Nullable bool
CharsetID, CharsetForm int
}
QueryColumn is the described column.
func DescribeQuery ¶
func DescribeQuery(ctx context.Context, db execer, qry string) ([]QueryColumn, error)
DescribeQuery describes the columns in the qry string, using DBMS_SQL.PARSE + DBMS_SQL.DESCRIBE_COLUMNS2.
This can help using unknown-at-compile-time, a.k.a. dynamic queries.
type QueryEvent ¶
type QueryEvent struct { Operation ID uint64 Tables []TableEvent }
type Subscription ¶
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) Close ¶
func (s *Subscription) Close() error
func (Subscription) GetObjectType ¶
func (c Subscription) GetObjectType(name string) (*ObjectType, error)
func (Subscription) NewSubscription ¶
func (c Subscription) NewSubscription(events chan<- Event, name string) (*Subscription, error)
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
func (Subscription) ServerVersion ¶
func (c Subscription) ServerVersion() (VersionInfo, error)
type TableEvent ¶
type VersionInfo ¶
type VersionInfo struct {
Version, Release, Update, PortRelease, PortUpdate, Full int
ServerRelease string
}
func ClientVersion ¶
func ClientVersion(ex execer) (VersionInfo, error)
func ServerVersion ¶
func ServerVersion(ex execer) (VersionInfo, error)
func (VersionInfo) String ¶
func (V VersionInfo) String() string