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.py Output shows the python-oracledb Thin mode was used:
python-oracledb thn : 1.0.0Testing Which Driver is in Use- import oracledb as cx_Oracle
- # or:
- # import cx_Oracle
- if cx_Oracle.__name__ == 'cx_Oracle':
- print('cx_Oracle')
- else:
- print('oracledb')
複製代碼
|