I'm working with Python and JayDeBeApi to connect to a Oracle-type database.
In the SELECT's statements I need to get about 10+ thousand of records.
In the first time I done by using the "fetchAll()" method, but this loads my memory and I wouldn't like to this to happen.
I get the cursor by using the code below:
def do_select(sql, db_conn):
resultSet = None
try:
cursor = db_conn.cursor()
cursor.execute(sql)
resultSet = {
"cursor": cursor,
"columns": cursor.description
}
except Exception as error:
print("An error occurred" + str(error))
return resultSet
And instead of using this type of code:
resultSet = self.do_select(sql, self.get_db_conn())
rows = resultSet["cursor"].fetchAll()
for row in rows:
# Do something...
I would like to do something like this:
resultSet = self.do_select(sql, self.get_db_conn())
while resultSet.next():
entire_row_tuple = resultSet.getCurrent() #I don't know if this is possible in python
#Do something with entire_row_tuple...
Is this possible in python? Or, does exists a better way instead of using "fetchAll()" method?
Thank you