ora

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: May 15, 2019 License: MIT Imports: 15 Imported by: 0

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_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_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  // int64
	SQLT_FLT  = 4  // float64
	SQLT_STR  = 5  // [n+1]byte
	SQLT_LNG  = 8  // [n]char
	SQLT_DAT  = 12 // [7]byte
	SQLT_AFC  = 96 // [n]char
	SQLT_CLOB = 112
	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_ATTR_NUM_DML_ERRORS = 73
)
View Source
const (
	OCI_DEFAULT = 0
)
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 row count to prefetch

Functions

This section is empty.

Types

type Conn

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

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 TODO: test that connection is actually closed!

func (*Conn) Prepare

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

Prepare creates statement for query

func (*Conn) Query

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

Query executes query statement using specified connenction

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

func (*Descriptor) Name

func (descr *Descriptor) Name() string

func (*Descriptor) Type

func (descr *Descriptor) Type() int

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 handle

func (*Lob) OpenReader

func (lob *Lob) OpenReader() (lobr *LobReader, err error)

OpenReader creates reder for reading from oracle lob

type LobReader

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

LobReader implements reader for oracle lob reading

func (*LobReader) Close

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

Close closes lob reader

func (*LobReader) Read

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

Read reads from lob

type OraValueConverter

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

func (OraValueConverter) ConvertValue

func (ovc OraValueConverter) ConvertValue(v interface{}) (driver.Value, error)

ConvertValue converts type

type QueryResult

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

QueryResult handles query result, it adds more functions for result than standart 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 row in query result

func (*QueryResult) Scan

func (qr *QueryResult) Scan(x ...interface{}) (err error)

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 returns last inserted id TODO: this is not implemented

func (Result) RowsAffected

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

RowsAffected returns affected row count TODO: this is not implemented

type Rows

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

Rows implements handling rowset result from database

func (*Rows) Close

func (rows *Rows) Close() error

Close closes rowset handle

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 destionation 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) ColumnConverter

func (stmt *Statement) ColumnConverter(idx int) driver.ValueConverter

ColumnConverter converting specific value for sending value to database

func (*Statement) Exec

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

Exec executes statement with passed binds

func (*Statement) NumInput

func (stmt *Statement) NumInput() int

NumInput returns number of imput parameters in statement

func (*Statement) Query

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

Query executes query statement

func (*Statement) SetPrefrech

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

SetPrefrech 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