I'm having some trouble converting some working code to a function. The first code sample is running without issue, but the function below just hangs. A little debugging using print showed that the function moves all the way through the cursor to the final record, appending it to the list, but the the program hangs and won't exit.
Cursor is part of the cx_Oracle module. The intent is to query an oracle db, then create a list. I have tested the original code on several queries and had no problems (max return is about 15000 rows). At this point I can make the code work using the original format, but I'd like to know what I might be doing wrong in the function.
Working code:
cursor = db.cursor()
cursor.execute(mysqlexp)
for row in cursor:
myList.append(row)
cursor.close()
Function (not working):
def sqlToList(listname, sqlexp):
cursor = db.cursor()
cursor.execute(sqlexp)
for row in cursor:
listname.append(row)
#print statement here indicates that final record appends
#but then the program stops responding
#print statement here never appears (indicating for loop hasn't exited?)
cursor.close()
sqlToList(myList, mysqlexp)