In cx_Oracle (or Oracle generally), can you really allocate a cursor for every query, in order to reuse a cursor across several queries.
def getSomeData(curs): # case 1: pass in a cursor, which is generally curs.execute('select ...') # reused across queries return curs.fetchall() def getSomeData(conn): # case 2: pass in a connection,allocate curs=conn.cursor() # a cursor for this query curs.execute('select ...') return curs.fetchall()
Obviously, both approaches return exactly the same data.
Do you know the tradeoffs between your two approaches? Is a particularly pretty much efficient? What are the potential issues to re-using a cursor over many queries?
You are able to re-make use of a cx_Oracle cursor around you want, not a problem. If you are performing 1000's of small queries in a tiny period of time, you might visit a slight performance improvement by re-while using cursor, however i doubt it.
I'll sometimes create new cursors, and in other cases re-make use of an existing one, based on whether or not this helps make the code simpler to see and understand.
For instance, if I've got a number of methods that require to gain access to the database, I would pass an Oracle connection object around, or perhaps a cursor produced on that connection.
Whatever makes your code more readable and simpler to keep is exactly what I'd choose.