admin 發表於 2023-4-24 11:53:39

Code to Aid the Upgrade to python-oracledb

The sample oracledb_upgrade.py shows a way to toggle applications between cx_Oracle and the two python-oracledb modes.
# test.py

import oracledb_upgrade as cx_Oracle
import os

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

connection = cx_Oracle.connect(user=un, password=pw, dsn=cs)
with connection.cursor() as cursor:
    sql = """SELECT UNIQUE CLIENT_DRIVER
             FROM V$SESSION_CONNECT_INFO
             WHERE SID = SYS_CONTEXT('USERENV', 'SID')"""
    for r, in cursor.execute(sql):
      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.pyOutput shows the python-oracledb Thin mode was used:
python-oracledb thn : 1.0.0Testing Which Driver is in Useimport oracledb as cx_Oracle
# or:
# import cx_Oracle

if cx_Oracle.__name__ == 'cx_Oracle':
       print('cx_Oracle')
else:
       print('oracledb')



頁: [1]
查看完整版本: Code to Aid the Upgrade to python-oracledb