cx_Oracle with multiple Oracle client versions

淺唱寂寞╮ 提交于 2019-12-11 06:31:55

问题


I am running Python 2.7 and am using cx_Oracle on a linux 64 bit OS. I need to be able to run against either an 11.2 or 12.1 Oracle client since I can't be sure which client will be installed on the deployed target. I know there are cx_Oracle built against each Oracle client. How can I be sure that the app will work? I should mention I am using pyinstaller to package up the application. Is there a version of cx_Oracle the is built against both Oracle clients or am I required to have two different versions of my application...one for 11g and one for a 12c client?


回答1:


Although in theory you should be able to build an Oracle 11g version of cx_Oracle and use it with both an Oracle 11g and Oracle 12c client, I wouldn't recommend it. If you are able to convince your users to use the Oracle 12c instant client that would be the simplest. That client is able to access both 11g and 12c databases without any difficulty. But if that isn't possible, the other option is the following:

1) Compile cx_Oracle for both 11g and 12c and place both copies in your installation named (for example) cx_Oracle_11g.so and cx_Oracle_12c.so.

2) Import cx_Oracle dynamically using code like the following:

for version in ("11g", "12c"):
    fileName = os.path.join(installDir, "cx_Oracle_%s.so" % version)
    try:
        module = imp.load_dynamic("cx_Oracle", fileName)
        break
    except ImportError:
        pass

3) Use the dynamically imported module wherever you need it in the same way as before. Since the dynamically loaded module was named cx_Oracle you should be able to import it in other code in the regular way and it will find the one you dynamically loaded.

4) Use cx_Oracle 6.x which supports any Oracle Client 11.2, 12.1 and 12.2 at the same time.



来源:https://stackoverflow.com/questions/39402974/cx-oracle-with-multiple-oracle-client-versions

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!