cur_as_dict
add function to convert cursor to python dictionary
This commit is contained in:
parent
4a53bf76f3
commit
8a45a653a3
10
oracle.py
10
oracle.py
@ -23,6 +23,16 @@ def dbmsoutput(cursor):
|
|||||||
return output
|
return output
|
||||||
|
|
||||||
|
|
||||||
|
def cur_as_dict(cursor):
|
||||||
|
"""
|
||||||
|
needs a open cursor and returns all rows as dict, be careful
|
||||||
|
with large results
|
||||||
|
"""
|
||||||
|
columns = [cols[0] for cols in cursor.description]
|
||||||
|
ret = [dict(zip(columns, row)) for row in cursor]
|
||||||
|
return ret
|
||||||
|
|
||||||
|
|
||||||
class OraConn(cx_Oracle.Connection):
|
class OraConn(cx_Oracle.Connection):
|
||||||
# instance can return a cursor or the whole conn
|
# instance can return a cursor or the whole conn
|
||||||
def __init__(self, str_conn, ret="conn", module_name=None):
|
def __init__(self, str_conn, ret="conn", module_name=None):
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user