# SessionCallback.py is when DRCP is used, as the callback is invoked on the # server and no round trip is required to set state. # # This script requires cx_Oracle 7.1 or higher. # # Also see SessionCallback.py # #------------------------------------------------------------------------------ import cx_Oracle import sample_env # create pool with session callback defined pool = cx_Oracle.SessionPool(user=sample_env.get_main_user(), password=sample_env.get_main_password(), dsn=sample_env.get_connect_string(), min=2, max=5, increment=1, threaded=True, sessionCallback="pkg_SessionCallback.TheCallback") # truncate table logging calls to PL/SQL session callback with pool.acquire() as conn: cursor = conn.cursor() cursor.execute("truncate table PLSQLSessionCallbacks") # acquire session without specifying a tag; the callback will not be invoked as # a result and no session state will be changed print("(1) acquire session without tag") with pool.acquire() as conn:
# session_callback.py is when DRCP is used, as the callback is invoked on the # server and no round trip is required to set state. # # This script requires cx_Oracle 7.1 or higher. # # Also see session_callback.py # #------------------------------------------------------------------------------ import cx_Oracle as oracledb import sample_env # create pool with session callback defined pool = oracledb.SessionPool(user=sample_env.get_main_user(), password=sample_env.get_main_password(), dsn=sample_env.get_connect_string(), min=2, max=5, increment=1, session_callback="pkg_SessionCallback.TheCallback") # truncate table logging calls to PL/SQL session callback with pool.acquire() as conn: cursor = conn.cursor() cursor.execute("truncate table PLSQLSessionCallbacks") # acquire session without specifying a tag; the callback will not be invoked as # a result and no session state will be changed print("(1) acquire session without tag") with pool.acquire() as conn: cursor = conn.cursor() cursor.execute("select to_char(current_date) from dual") result, = cursor.fetchone() print("main(): result is", repr(result))