From 8a45a653a3da8919e1566069b2f542e23f2f2535 Mon Sep 17 00:00:00 2001 From: Josue Gomez Date: Tue, 14 May 2019 16:24:51 -0600 Subject: [PATCH] cur_as_dict add function to convert cursor to python dictionary --- oracle.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/oracle.py b/oracle.py index a27a936..342ea0b 100644 --- a/oracle.py +++ b/oracle.py @@ -23,6 +23,16 @@ def dbmsoutput(cursor): 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): # instance can return a cursor or the whole conn def __init__(self, str_conn, ret="conn", module_name=None):