change oraconn
This commit is contained in:
parent
2d12eeffd1
commit
70223b9cd3
29
oracle.py
29
oracle.py
@ -1,16 +1,29 @@
|
||||
import cx_Oracle
|
||||
|
||||
APP_CTX_NAMESPACE = "USERENV"
|
||||
APP_CTX_ENTRIES = [
|
||||
( APP_CTX_NAMESPACE, "MODULE", "modulo prueba"),
|
||||
]
|
||||
|
||||
class OraConn:
|
||||
def __init__(self, str_conn, conn_name=None):
|
||||
self.conn = cx_Oracle.connect(str_conn, encoding='UTF-8')
|
||||
self.cur = self.conn.cursor()
|
||||
if conn_name is not None:
|
||||
self.cur.callproc('DBMS_APPLICATION_INFO.SET_MODULE', [conn_name, None])
|
||||
|
||||
class OraConn(cx_Oracle.Connection):
|
||||
# instance can return a cursor or the whole conn
|
||||
def __init__(self, str_conn, ret="conn", module_name=None):
|
||||
super().__init__(str_conn, encoding='UTF-8')
|
||||
self.cur = super().cursor()
|
||||
self.ret = ret
|
||||
if module_name is not None:
|
||||
self.cur.callproc('DBMS_APPLICATION_INFO.SET_MODULE', [module_name, None])
|
||||
|
||||
if self.ret == "conn":
|
||||
self.cur.close()
|
||||
|
||||
def __enter__(self):
|
||||
return self.conn
|
||||
if self.ret == "cursor":
|
||||
return self.cur
|
||||
return self
|
||||
|
||||
def __exit__(self, exc_type, exc_val, exc_tb):
|
||||
self.conn.close()
|
||||
if self.ret == "cursor":
|
||||
return self.cur.close()
|
||||
super().__exit__(exc_type, exc_val, exc_tb)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user