Python Forum
Best way to return Cursor Data - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Best way to return Cursor Data (/thread-11872.html)



Best way to return Cursor Data - rajuarien - Jul-29-2018

I am very new to python.

--This method is encapsulated in class OracleQuery :
def executeProcedure(self, query):
try:
oracleConnectionRef = OracleConnection(self._host, self._port, self._serviceName, self._schemaUser, self._schemaPassword)
oracleConn = oracleConnectionRef.createConnection()
if oracleConn is None :
print("Connection failed to open..")
return None
else:
cur = oracleConn.cursor()
refCursorVar = cur.var(cx_Oracle.CURSOR)
cur.callproc(query, [14032, refCursorVar] )
return refCursorVar.getvalue()
except Exception as e:
print("Exception: " + str(e))

I want to write a module that will be able to run Oracle Queries( Packages, Functions, Stored Prcoedures) . What the best way to return the results of a ref Cursor. it should contain both the column definition / rows data for external clients to consume it.

Problem is if i return the cursor i am unable to iterate it because its closed.