設為首頁收藏本站

艾歐踢論壇

 找回密碼
 立即註冊

QQ登錄

只需一步,快速開始

搜索
熱搜: 活動 交友 discuz
查看: 447|回復: 0
打印 上一主題 下一主題

Code to Aid the Upgrade to python-oracledb

[複製鏈接]
跳轉到指定樓層
樓主
發表於 2023-4-24 11:53:39 | 只看該作者 回帖獎勵 |倒序瀏覽 |閱讀模式
The sample oracledb_upgrade.py shows a way to toggle applications between cx_Oracle and the two python-oracledb modes.
  1. # test.py

  2. import oracledb_upgrade as cx_Oracle
  3. import os

  4. un = os.environ.get("PYTHON_USERNAME")
  5. pw = os.environ.get("PYTHON_PASSWORD")
  6. cs = os.environ.get("PYTHON_CONNECTSTRING")

  7. connection = cx_Oracle.connect(user=un, password=pw, dsn=cs)
  8. with connection.cursor() as cursor:
  9.     sql = """SELECT UNIQUE CLIENT_DRIVER
  10.              FROM V$SESSION_CONNECT_INFO
  11.              WHERE SID = SYS_CONTEXT('USERENV', 'SID')"""
  12.     for r, in cursor.execute(sql):
  13.         print(r)
複製代碼
You can then choose what mode is in use by setting the environment variable ORA_PYTHON_DRIVER_TYPE to one of “cx”, “thin”, or “thick”:
export ORA_PYTHON_DRIVER_TYPE=thin
python test.py
Output shows the python-oracledb Thin mode was used:
python-oracledb thn : 1.0.0Testing Which Driver is in Use
  1. import oracledb as cx_Oracle
  2. # or:
  3. # import cx_Oracle

  4. if cx_Oracle.__name__ == 'cx_Oracle':
  5.        print('cx_Oracle')
  6. else:
  7.        print('oracledb')
複製代碼




分享到:  QQ好友和群QQ好友和群 QQ空間QQ空間 騰訊微博騰訊微博 騰訊朋友騰訊朋友
收藏收藏 轉播轉播 分享分享 分享淘帖
回復

使用道具 舉報

您需要登錄後才可以回帖 登錄 | 立即註冊

本版積分規則

小黑屋|Archiver|手機版|艾歐踢創新工坊    

GMT+8, 2024-4-30 00:24 , Processed in 0.260159 second(s), 20 queries .

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回復 返回頂部 返回列表