doulianqi3870 2014-03-06 07:16
浏览 116
已采纳

如何在Go中连接到Oracle

I gather there are two ways to connect to Oracle DB in Go (on windows):

  1. github.com/tgulacsi/goracle
  2. github.com/mattn/go-oci8

But for someone of my level (beginner in open source+golang), those two methods/drivers are awfully tricky.

It's also a burden having to go through all of that for deployment, development on different machines etc. (Also assuming it will work).

Is there a better way to connect to Oracle db in golang or if there is not then can someone explain to me in high level view or any view for that matter that would make this easier?

Pointers would be very much appreciated.

TQ.

  • 写回答

1条回答 默认 最新

  • dongliehuan3925 2014-09-19 19:29
    关注

    If you are still interested, I have been working with Go and Oracle on Windows for a few months now. My favorite driver so far is go-oci8. It is much faster than goracle and seems to be more active.

    Some of our applications need to be deployed on computers that we don't have access to. Both native SQL drivers are compiled with the application without the need for any external configuration, so that is a huge plus. The computer will still need Oracle client installed, but that is the only external dependency.

    I won't say go-oci8 is production ready yet, but it's stable enough when you know its limitations. One example is that it panics when running on multiple goroutines simultaneously, so if you need that you might want to use a mutex.

    I have basically followed this tutorial to install it: https://gist.github.com/mnadel/8678269

    The trickiest part was creating oci8.pc corretly. Mine is:

    prefix=/devel/target/1.0
    exec_prefix=${prefix}
    libdir=C:/oracle/instantclient_12_1_64/sdk/lib/msvc
    includedir=C:/oracle/instantclient_12_1_64/sdk/include
    oralib=C:/oracle/instantclient_12_1_64/sdk/lib/msvc
    orainclude=C:/oracle/instantclient_12_1_64/sdk/include
    gcclib=c:/MinGW_64/mingw64/lib
    gccinclude=c:/MinGW_64/mingw64/lib
    glib_genmarshal=glib-genmarshal
    gobject_query=gobject-query
    glib_mkenums=glib-mkenums
    Name: oci8
    Version: 12.1
    Description: oci8 library
    Libs: -L${oralib} -L${gcclib} -loci
    Libs.private:
    Cflags: -I${orainclude} -I${gccinclude}
    

    Some things might be reduntant, I might try to improve it on a clean machine.

    An important thing to have in mind is that you should use the same architecture for Go and the Oracle client. So if you want to use the 64 bit version of Go you will also need the 64 bit version of Oracle. I have both 32 and 64 bit versions of both, and while 64 bit is my default I use bat files to change the necessary paths and environment variables when I need to build a 32 bit version.

    It might be worth investing some time to make it work, you will probably get much better performance than using ODBC. I have been using it with somewhat high data volume (queries that fetch 5+ million rows) and it works very well.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥50 永磁型步进电机PID算法
  • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥200 uniapp长期运行卡死问题解决
  • ¥15 latex怎么处理论文引理引用参考文献
  • ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?
  • ¥15 为什么使用javacv转封装rtsp为rtmp时出现如下问题:[h264 @ 000000004faf7500]no frame?