ora

package module
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2025 License: MIT Imports: 16 Imported by: 1

README

ora

Oracle database driver for Go uses OCI

For now it's only implements basic database/sql/driver interface.

For 64bit go you will need 64bit oracle instant client.

windows

  • you will only need instant client installed
  • path to instant client should be in PATH system variables

linux

  • you will only need instant client installed
  • sudo ldconfig -p | grep libclntsh should return some lines

usage

package main

import (
	"database/sql"
	"fmt"
	_ "github.com/jzaikovs/ora"
)

func main() {
	db, err := sql.Open("ora", "user/password@//localhost:1521/XE")
	if err != nil {
		panic(err)
	}
	defer db.Close()

	rows, err := db.Query("select * from dual")
	if err != nil {
		panic(err)
	}
	defer rows.Close()

	dummy := ""
	for rows.Next() {
		if err = rows.Scan(&dummy); err != nil {
			panic(err)
		}
		fmt.Println(dummy)
	}
}

Documentation

Index

Constants

View Source
const (
	OCI_DEFAULT  = 0
	OCI_THREADED = 1
)
View Source
const (
	OCI_HTYPE_ENV    = 1
	OCI_HTYPE_ERROR  = 2
	OCI_HTYPE_SVCCTX = 3
	OCI_HTYPE_STMT   = 4
)

http://docs.oracle.com/cd/E11882_01/appdev.112/e10646/oci02bas.htm#g466063

View Source
const (
	OCI_BATCH_MODE        = 0x1
	OCI_COMMIT_ON_SUCCESS = 0x20
	OCI_BATCH_ERRORS      = 0x80
)
View Source
const (
	OCI_DTYPE_LOB   = 50
	OCI_DTYPE_PARAM = 53
	OCI_DTYPE_ROWID = 54
)
View Source
const (
	OCI_ATTR_CHAR_USED = 285
	OCI_ATTR_CHAR_SIZE = 286
)
View Source
const (
	OCI_ATTR_DATA_SIZE     = 1
	OCI_ATTR_DATA_TYPE     = 2
	OCI_ATTR_DISP_SIZE     = 3
	OCI_ATTR_NAME          = 4
	OCI_ATTR_PRECISION     = 5
	OCI_ATTR_SCALE         = 6
	OCI_ATTR_ROW_COUNT     = 9
	OCI_ATTR_PREFETCH_ROWS = 11
	OCI_ATTR_ROWID         = 19
	OCI_ATTR_FETCH_ROWID   = 448
)
View Source
const (
	OCI_TYP_VARCHAR = 1 // 40000byte, ora12 -> 32k
	OCI_TYP_NUMBER  = 2 // [21]byte, can be casted, float64, int64, string
	OCI_TYP_DATE    = 12
	OCI_TYP_ROWID   = 104 // this is strange, docs say it is 69, but in practice it is 104

	// working progress
	OCI_TYP_LONG = 8
	OCI_TYP_CHAR = 96

	// unsupported by this driver
	OCI_TYP_RAW           = 23
	OCI_TYP_LONG_RAW      = 24
	OCI_TYP_BINARY_FLOAT  = 100
	OCI_TYP_BINARY_DOUBLE = 100
	OCI_TYP_CLOB          = 112
	OCI_TYP_BLOB          = 113
	OCI_TYP_BFILE         = 114
	OCI_TYP_TIMESTAMP     = 180
)

internal data types: http://docs.oracle.com/cd/E11882_01/appdev.112/e10646/oci03typ.htm#CEGGBDFC

View Source
const (
	SQLT_CHR     = 1  // [n]byte
	SQLT_NUM     = 2  // float64?
	SQLT_INT     = 3  // int32
	SQLT_FLT     = 4  // float32
	SQLT_STR     = 5  // [n+1]byte
	SQLT_VNU     = 6  // VARNUM byte[22]
	SQLT_LNG     = 8  // [n]char RAW
	SQLT_DAT     = 12 // [7]byte
	SQLT_BFLOAT  = 21 // float32
	SQLT_BDOUBLE = 22 // float64
	SQLT_BIN     = 23 // [n]byte
	SQLT_UIN     = 68 // uint32
	SQLT_AFC     = 96 // [n]char
	SQLT_CLOB    = 112
	SQLT_BLOB    = 113
	SQLT_RDD     = 104
)

external data types http://docs.oracle.com/cd/E11882_01/appdev.112/e10646/oci03typ.htm#LNOCI16271

View Source
const (
	OCI_SUCCESS           = 0
	OCI_SUCCESS_WITH_INFO = 1
	OCI_NO_DATA           = 100
	OCI_ERROR             = -1
	OCI_INVALID_HANDLE    = -2
	OCI_NEED_DATA         = 99
	OCI_STILL_EXECUTING   = -3123
	OCI_CONTINUE          = -24200
	OCI_ROWCBK_DONE       = -24201
)

http://docs.oracle.com/cd/E11882_01/appdev.112/e10646/oci02bas.htm#LNOCI16220

View Source
const (
	OCI_ONE_PIECE   = 0
	OCI_FIRST_PIECE = 1
	OCI_NEXT_PIECE  = 2
	OCI_LAST_PIECE  = 3
)
View Source
const (
	SQLCS_IMPLICIT = 1
	SQLCS_NCHAR    = 2
	SQLCS_EXPLICIT = 3
	SQLCS_FLEXIBLE = 4
	SQLCS_LIT_NULL = 5
)
View Source
const (
	OCI_LOB_READONLY      = 1
	OCI_LOB_READWRITE     = 2
	OCI_LOB_WRITEONLY     = 3
	OCI_LOB_APPENDONLY    = 4
	OCI_LOB_FULLOVERWRITE = 5
	OCI_LOB_FULLREAD      = 6
)
View Source
const (
	OCI_TEMP_BLOB = 1
	OCI_TEMP_CLOB = 2
)
View Source
const DriverName = "ora"

DriverName is name used to register driver

View Source
const (
	OCI_ATTR_NUM_DML_ERRORS = 73
)
View Source
const (
	OCI_NTV_SYNTAX = 1
)

Variables

View Source
var MaxLongSize = 100000

MaxLongSize is size of buffer allocated for long type, (TODO: can this be improved to dynamic allocation?)

View Source
var PrefetchRows = 1000

PrefetchRows is binds count to prefetch

Functions

This section is empty.

Types

type Conn

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

Conn represents single connection with database

func Open

func Open(connectionString string) (*Conn, error)

Open creates new connection

func (*Conn) Begin

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

Begin begins transaction

func (*Conn) Close

func (conn *Conn) Close() error

Close closes connection

func (*Conn) Exec added in v0.5.0

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

Exec implements driver.Execer

func (*Conn) ExecContext added in v0.5.0

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

func (*Conn) NewLob added in v0.5.0

func (conn *Conn) NewLob() (lob *Lob, err error)

func (*Conn) Ping added in v0.5.0

func (conn *Conn) Ping(ctx context.Context) (err error)

func (*Conn) Prepare

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

Prepare creates statement for query

func (*Conn) Query

func (conn *Conn) Query(query string, binds ...interface{}) (qr *QueryResult, err error)

Query executes query statement using specified connection

func (*Conn) ResetSession added in v0.5.0

func (conn *Conn) ResetSession(ctx context.Context) (err error)

type ConnStd added in v0.5.0

type ConnStd struct {
	*Conn
}

func (*ConnStd) Query added in v0.5.0

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

Query implements driver.Queryer

type Descriptor

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

Descriptor describes variable where to put query result http://web.stanford.edu/dept/itss/docs/oracle/10gR2/appdev.102/b14250/oci04sql.htm#sthref629

type Driver added in v0.5.0

type Driver struct {
}

func (Driver) Open added in v0.5.0

func (Driver) Open(connectionString string) (driver.Conn, error)

Open implements driver.Open interface

type Error added in v0.5.0

type Error struct {
	Code    int
	Message string
}

Error implements oracle error with error code

func (Error) Error added in v0.5.0

func (err Error) Error() string

type Library

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

Library handler

func NewLazyDLL

func NewLazyDLL(name string) (dll *Library)

NewLazyDLL loads static library

func (*Library) NewProc

func (lib *Library) NewProc(name string) *LibraryProc

NewProc creates system call proc to passed functio from Library

type LibraryProc

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

LibraryProc handler for single procedure from library

func (LibraryProc) Call

func (lib LibraryProc) Call(args ...uintptr) (r1 uintptr, r2 uintptr, err error)

Call calls function from library

type Lob

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

Lob represents oracle lob ociHandle

func (*Lob) Close added in v0.5.0

func (lob *Lob) Close() (err error)

Close closes lob reader

func (*Lob) CreateTemp added in v0.5.0

func (lob *Lob) CreateTemp() (err error)

func (*Lob) FreeTemp added in v0.5.0

func (lob *Lob) FreeTemp() (err error)

func (*Lob) Read added in v0.5.0

func (lob *Lob) Read(buf []byte) (n int, err error)

Read reads from lob

func (*Lob) Scan added in v0.5.0

func (lob *Lob) Scan(src interface{}) (err error)

func (*Lob) String added in v0.5.0

func (lob *Lob) String() (string, error)

func (*Lob) Write added in v0.5.0

func (lob *Lob) Write(buf []byte) (n int, err error)

type QueryResult

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

QueryResult handles query result, it adds more functions for result than standard database/sql

func (*QueryResult) Close

func (qr *QueryResult) Close() (err error)

func (*QueryResult) FieldDescriptions

func (qr *QueryResult) FieldDescriptions() (fields []*Descriptor)

func (*QueryResult) Next

func (qr *QueryResult) Next() error

Next fetchers next binds in query result

func (*QueryResult) Values

func (qr *QueryResult) Values() (row []interface{}, err error)

type Result

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

Result implements driver.Result interface

func (Result) LastInsertId

func (result Result) LastInsertId() (int64, error)

LastInsertId implements driver.Result interface

func (Result) RowsAffected

func (result Result) RowsAffected() (int64, error)

RowsAffected returns affected binds count

type Rows

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

Rows implements handling query result from database

func (*Rows) Close

func (rows *Rows) Close() error

Close closes nothing to close

func (*Rows) ColumnTypePrecisionScale added in v0.5.0

func (rows *Rows) ColumnTypePrecisionScale(index int) (precision, scale int64, ok bool)

func (*Rows) Columns

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

Columns returns returned rowset column names

func (*Rows) Next

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

Next fetches rows from database and stores in destination slice

type Statement

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

Statement handles single SQL statement

func (*Statement) Close

func (stmt *Statement) Close() error

Close closes statement

func (*Statement) Exec

func (stmt *Statement) Exec(args []driver.Value) (driver.Result, error)

Exec executes statement with passed binds

func (*Statement) ExecContext added in v0.5.0

func (stmt *Statement) ExecContext(ctx context.Context, args []driver.NamedValue) (result driver.Result, err error)

func (*Statement) NumInput

func (stmt *Statement) NumInput() int

NumInput returns number of input parameters in statement

func (*Statement) Query

func (stmt *Statement) Query(args []driver.Value) (driver.Rows, error)

Query executes query statement

func (*Statement) SetPrefetch added in v0.5.0

func (stmt *Statement) SetPrefetch(n int) (err error)

SetPrefetch sets actual prefetch

type Transaction

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

Transaction handler

func (*Transaction) Commit

func (tx *Transaction) Commit() error

Commit implements transaction commit

func (*Transaction) Rollback

func (tx *Transaction) Rollback() error

Rollback implements transaction rollback

Jump to

Keyboard shortcuts

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