golang 串連 oracle

來源:互聯網
上載者:User
這是一個建立於 的文章,其中的資訊可能已經有所發展或是發生改變。

Connecting Go to Oracle gives a bit more work than other databases. This is because the Oracle drivers not just link to C code, but also depend on specific environment settings. This post was first written with Windows in mind, but I added a section with Linux specific instructions below. This was tested with the following drivers:

  • go-oci8
  • ora

First, remember, you will need the 32-bits version of everything (This works on 64-bits Windows, though). This is because some of the tools you will need are available just as 32-bits for Windows. So, first thing, check if the Go version you have is 32-bits.

Second, you will need to install the oficial MinGW package (again, 32-bits). Don’t forget to add the /bin folder inside the MinGW installation to the PATH.

Now, create a folder called C:\pkg-config, and extract these three ZIP files inside:

  • http://ftp.gnome.org/pub/gnome/binaries/win32/dependencies/pkg-config_0.26-1_win32.zip
  • http://ftp.gnome.org/pub/gnome/binaries/win32/glib/2.28/glib_2.28.8-1_win32.zip
  • http://ftp.gnome.org/pub/gnome/binaries/win32/dependencies/gettext-runtime_0.18.1.1-2_win32.zip

Now download the Oracle client (32-bits) and put it on C:\instantclient_11_2. Also download the Oracle SDK (32-bits) and put on C:\instantclient_11_2\sdk.C:\instantclient_11_2 should be added to your PATH.

Now create a folder C:\pkg-config\PKG_CONFIG_PATH, and create a file calledoci8.pc inside with the following content:

prefix=/devel/target/XXXXXXXXXXXXXXXXXXXXXXXXXXexec_prefix=${prefix}libdir=C:/instantclient_11_2/sdk/lib/msvcincludedir=C:/instantclient_11_2/sdk/includeglib_genmarshal=glib-genmarshalgobject_query=gobject-queryglib_mkenums=glib-mkenumsName: oci8Version: 11.2Description: oci8 libraryLibs: -L${libdir} -lociCflags: -I${includedir}

Add C:\pkg-config\bin to PATH and C:\pkg-config\PKG_CONFIG_PATH to a environment variable called PKG_CONFIG_PATH.

Restart any command prompt to make sure the new environment variables were reconized. If everything is OK, you should be able to properly install one of the Oracle packages:

go install -v github.com/rana/ora# orgo install -v github.com/mattn/go-oci8

On Linux

This was tested on Ubuntu 16.04, x64 version. First, make sure you installed these tools:

sudo apt-get install build-essential pkg-config

For installing Oracle Client + SDK on Ubuntu, please carefully read and follow this guide on the oficial Ubuntu Wiki. This post won’t cover the SDK installation because it’s very well covered there.

Once you did the installation, create a folder called PKG_CONFIG_PATH in a place you remember later, and then a environment variable called PKG_CONFIG_PATH pointing to this folder. Then, create a file called oci8.pc with the following template (instead of the above for Windows):

prefix=/devel/target/XXXXXXXXXXXXXXXXXXXXXXXXXXexec_prefix=${prefix}libdir=/usr/lib/oracle/11.2/client64/libincludedir=/usr/include/oracle/11.2/client64glib_genmarshal=glib-genmarshalgobject_query=gobject-queryglib_mkenums=glib-mkenumsName: oci8Description: oci8 libraryLibs: -L${libdir} -lclntshCflags: -I${includedir}Version: 11.2

And try compile to see if everything is OK:

go install -v github.com/mattn/go-oci8# orgo install -v github.com/rana/ora
相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.