tgulacsi/goracle

语言: C

git: https://github.com/tgulacsi/goracle

用于Oracle访问的cx_Oracle转换
cx_Oracle translation for Oracle access
README.md (中文)

警告

这个回购被冻结,所有未来的修改都将在

github.com/go-goracle/goracle

这是为了gopkg.in版本控制,所以你可以使用

gopkg.in/goracle.v1

进口!这种变化的原因:

  1. 更好的导入路径,
  2. 版本化进口 - 制动变化将进入一个新的分支,      出现为新版本:gopkg.in/goracle.v2
  3. 我已经创建了一个新的GitHub组织和导入路径      不再包含我的名字,所以所有权的过渡      如果有更好技能的人,将来可能会更容易      更多的时间似乎保持着僵局。

goracle

goracle / oracle是一个包是翻译版的 cx_Oracle (由Anthony Tuininga)从C(Python模块)转换为Go。

goracle / godrv是一个包 数据库/ SQL / driver.Driver 兼容goracle / oracle的包装器 - 通过github.com/bradfitz/go-sql-test (如github.com/tgulacsi/go-sql-test)。

那里

CHAR,VARCHAR2,NUMBER,DATETIME,INTERVAL简单和数组绑定/定义。 CURSOR,CLOB,BLOB

不工作

无法输入PLS_INTEGER,只能输入INTEGER(这是正常的,因为PLS_INTEGER是一个 PL / SQL类型,而不是SQL类型)。

不工作ATM

我什么都不知道。

尚未测试(尚未)

LONG,LONG RAW,BFILE

用法和意图

我没有压力迫使我理解数据库/ sql - 但是。 我已经移植了cx_Oracle,因为我大部分时间都在使用Python, 并且当时Go没有特有的OCI绑定。 因此我能熟练使用cx_Oracle,这意味着goracle / oracle。

但是,只要有可能,我就会开始坚持使用数据库/ sql - 我的印象是Go的标准库非常高质量。

当然,如果您需要使用Oracle的非标准功能 (输出绑定变量,返回游标,发送和接收 PL / SQL关联表...)然后goracle / oracle是直接的选择。

用于简单(连接,Ping,Select)用法和测试连接 (DSN可能很棘手),请参阅最新消息。

变化

使用b0219c8f,我们可以重用具有不同数量的绑定变量的语句!

调试

您可以使用构建测试可执行文件(例如,使用gdb进行调试) 去测试-c

您可以使用“trace”构建标记构建跟踪版本 (go build -tags = trace)将在调用OCI之前打印出所有内容 C函数。

例如,参见c。

安装

go get github.com/tgulacsi/goracle/godrv是可以得到的 如果你有 安装了Oracle DB 或Oracle的 InstantClient 基本客户端和SDK(用于头文件)也是如此! - 已安装

对于POSIXy系统上的环境变量,您可以尝试。 ./env:

go get github.com/tgulacsi/goracle
cd $GOPATH/src/github.com/tgulacsi/goracle
. ./env
go install ./godrv

Linux的

你已经设置了适当的环境变量:

export CGO_CFLAGS=-I$(dirname $(find $ORACLE_HOME -type f -name oci.h))
export CGO_LDFLAGS=-L$(dirname $(find $ORACLE_HOME -type f -name libclntsh.so\*))
go get github.com/tgulacsi/goracle/godrv

例如,使用我的XE:

ORACLE_HOME=/u01/app/oracle/product/11.2.0/xe
CGO_CFLAGS=-I/u01/app/oracle/product/11.2.0/xe/rdbms/public
CGO_LDFLAGS=-L/u01/app/oracle/product/11.2.0/xe/lib

使用InstantClient:

CGO_CFLAGS=-I/usr/include/oracle/11.2/client64
CGO_LDFLAGS=-L/usr/include/oracle/11.2/client64

RHEL 5

如果你的git太旧,gopkg.in可能会出现过多的跳跃。你可以做

mkdir -p $GOPATH/src/gopkg.in/ && cd $GOPATH/src/gopkg.in && \
    git checkout https://github.com/go-errgo/errgo.git errgo.v1 && \
    cd errgo.v1 && git checkout -f v1
mkdir -p $GOPATH/src/gopkg.in/ && cd $GOPATH/src/gopkg.in && \
    git checkout https://github.com/inconshreveable/log15.git log15.v2 && \
    cd log15.v2 && git checkout -f v2

Mac OS X.

对于Mac OS X,我执行了以下操作:

您必须同时获得Instant Client Package Basic和Instant Client Package SDK(用于头文件)。

然后将env变量设置为此(请注意此处的SDK已解压缩到Basic包的基本目录中)

export CGO_CFLAGS=-I/Users/dfils/src/oracle/instantclient_11_2/sdk/include
export CGO_LDFLAGS=-L/Users/dfils/src/oracle/instantclient_11_2
export DYLD_LIBRARY_PATH=/Users/dfils/src/oracle/instantclient_11_2:$DYLD_LIBRARY_PATH

也许这种出口也会起作用,但我没试过。我知道这是另一种方法

export DYLD_FALLBACK_LIBRARY_PATH=/Users/dfils/src/oracle/instantclient_11_2

运行二进制文件需要DYLD变量,而不是编译它。

Windows 7 64位

感谢Johann Kropf!

要求

  • MinGW的-W64
  • MSYS
  • Oracle InstantClient Basic 64位
  • Oracle InstantClient SDK 64位
  • github.com \ tgulacsi \ goracle%GOPATH%

设置CGO_CFLAGS = -IC:\ Oracle64Instant \ SDK \包括 -LC设置CGO_LDFLAGS = \ Oracle64Instant \ SDK \ lib中

在Windows上,库libclntsh.so不存在。 因此,更改github.com \ tgulacsi \ goracle \ oracle的所有源文件中的行

从 #cgo LDFLAGS:-lclntsh

至 #cgo LDFLAGS:-loc

通过执行从oci.dll创建liboci.a文件

  1. 如果尚未安装,则从Mingw安装Msys
  2. 从http://sourceforge.net/p/mingw-w64/code/HEAD/tree/stable/v3.x/下载gendef实用程序 通过“下载快照”
  3. 解压缩zip文件并将文件夹gendef复制到Msys中的主目录
  4. 转到文件夹gendef并执行./configure和./make - 将创建gendef.exe
  5. 运行:gendef oci.dll - 将生成oci.def
  6. 运行:dlltool -D oci.dll -d oci.def -l liboci.a - 将生成liboci.a
  7. copy liboci.a C:\ Oracle64Instant \ sdk \ lib

用oracle构建oracle %GOPATH%\ github.com \ tgulacsi \ goracle \ oracle> go install

您现在可以构建导入“github.com/tgulacsi/goracle/oracle”的程序!

本文使用googletrans自动翻译,仅供参考, 原文来自github.com

en_README.md

WARNING

This repo is frozen, all future modifications will happen in

github.com/go-goracle/goracle

This is for gopkg.in versioning, so you can use

gopkg.in/goracle.v1

for imports! Reasons for this change:

  1. Nicer import path,
  2. Versioned imports - braking changes will go into a new branch,
    appearing as a new version: gopkg.in/goracle.v2
  3. I've created a new GitHub organization, and the import path
    no longer contains my name, so the transition of ownership
    may be easier in the future, if someone with better skills,
    more time appear to maintain goracle.

goracle

goracle/oracle is a package is a translated version of
cx_Oracle
(by Anthony Tuininga) converted from C (Python module) to Go.

goracle/godrv is a package which is a
database/sql/driver.Driver
compliant wrapper for goracle/oracle - passes github.com/bradfitz/go-sql-test
(as github.com/tgulacsi/go-sql-test).

There

CHAR, VARCHAR2, NUMBER, DATETIME, INTERVAL simple AND array bind/define.
CURSOR, CLOB, BLOB

Not working

Cannot input PLS_INTEGER, only INTEGER (this is OK, as PLS_INTEGER is a
PL/SQL type, not an SQL one).

Not working ATM

Nothing I know of.

Not tested (yet)

LONG, LONG RAW, BFILE

Usage and intentions

I haven't had the pressure to force me understanding database/sql - yet.
I've ported cx_Oracle because I'm using Python with Oracle most of,
and no featureful OCI binding has existed for Go that time.
Thus I'm fluent with cx_Oracle and that means goracle/oracle.

BUT I'd start and stick with database/sql as long as it is possible
- my impression is that Go's standard library is very high quality.

Of course if you need to use Oracle's non-standard features
(out bind variables, returning cursors, sending and receiving
PL/SQL associative tables...) then goracle/oracle is the straight choice.

For simple (connection, Ping, Select) usage, and testing connection
(DSN can be tricky), see conntest.

Changes

With b0219c8f we can reuse statements with different number of bind variables!

Debug

You can build the test executable (for debugging with gdb, for example) with
go test -c

You can build a tracing version with the "trace" build tag
(go build -tags=trace) that will print out everything before calling OCI
C functions.

See c for example.

Install

It is go get'able with go get github.com/tgulacsi/goracle/godrv
iff you have
Oracle DB installed
OR the Oracle's
InstantClient
both the Basic Client and the SDK (for the header files), too!
- installed

For environment variables on POSIXy systems, you can try . ./env:

go get github.com/tgulacsi/goracle
cd $GOPATH/src/github.com/tgulacsi/goracle
. ./env
go install ./godrv

Linux

AND you have set proper environment variables:

export CGO_CFLAGS=-I$(dirname $(find $ORACLE_HOME -type f -name oci.h))
export CGO_LDFLAGS=-L$(dirname $(find $ORACLE_HOME -type f -name libclntsh.so\*))
go get github.com/tgulacsi/goracle/godrv

For example, with my XE:

ORACLE_HOME=/u01/app/oracle/product/11.2.0/xe
CGO_CFLAGS=-I/u01/app/oracle/product/11.2.0/xe/rdbms/public
CGO_LDFLAGS=-L/u01/app/oracle/product/11.2.0/xe/lib

With InstantClient:

CGO_CFLAGS=-I/usr/include/oracle/11.2/client64
CGO_LDFLAGS=-L/usr/include/oracle/11.2/client64

RHEL 5

If your git is too old, gopkg.in may present too much hops. You can do

mkdir -p $GOPATH/src/gopkg.in/ && cd $GOPATH/src/gopkg.in && \
    git checkout https://github.com/go-errgo/errgo.git errgo.v1 && \
    cd errgo.v1 && git checkout -f v1
mkdir -p $GOPATH/src/gopkg.in/ && cd $GOPATH/src/gopkg.in && \
    git checkout https://github.com/inconshreveable/log15.git log15.v2 && \
    cd log15.v2 && git checkout -f v2

Mac OS X

For Mac OS X I did the following:

You have to get both the Instant Client Package Basic and the Instant Client Package SDK (for the header files).

Then set the env vars as this (note the SDK here was unpacked into the base directory of the Basic package)

export CGO_CFLAGS=-I/Users/dfils/src/oracle/instantclient_11_2/sdk/include
export CGO_LDFLAGS=-L/Users/dfils/src/oracle/instantclient_11_2
export DYLD_LIBRARY_PATH=/Users/dfils/src/oracle/instantclient_11_2:$DYLD_LIBRARY_PATH

Perhaps this export would work too, but I did not try it. I understand this is another way to do this

export DYLD_FALLBACK_LIBRARY_PATH=/Users/dfils/src/oracle/instantclient_11_2

The DYLD vars are needed to run the binary, not to compile it.

Windows 7 64-bit

Thanks to Johann Kropf!

Requirements

  • mingw-w64
  • msys
  • go
  • Oracle InstantClient Basic 64bit
  • Oracle InstantClient SDK 64bit
  • github.com\tgulacsi\goracle under %GOPATH%

Set CGO_CFLAGS=-IC:\Oracle64Instant\sdk\include
Set CGO_LDFLAGS=-LC:\Oracle64Instant\sdk\lib

On Windows the library libclntsh.so does not exist.
So change the line in all the source files of github.com\tgulacsi\goracle\oracle

From
#cgo LDFLAGS: -lclntsh

to
#cgo LDFLAGS: -loci

Create the liboci.a file from the oci.dll by doing

  1. Install Msys from Mingw if not already done
  2. Download gendef utility from http://sourceforge.net/p/mingw-w64/code/HEAD/tree/stable/v3.x/
    by "Download snapshot"
  3. Extract the zip-file and copy the folder gendef to your home-directory in Msys
  4. go to the folder gendef and execute ./configure and ./make - gendef.exe will be created
  5. Run: gendef oci.dll - oci.def will be generated
  6. Run: dlltool -D oci.dll -d oci.def -l liboci.a - liboci.a will be generated
  7. copy liboci.a C:\Oracle64Instant\sdk\lib

Build oracle with
%GOPATH%\github.com\tgulacsi\goracle\oracle>go install

You can build now your program which imports "github.com/tgulacsi/goracle/oracle"!