views:

240

answers:

2

I want to fetch data from a mysql database using sqlalchemy and use the data in a different class.. Basically I fetch a row at a time, use the data, fetch another row, use the data and so on.. I am running into some problem doing this..

Basically, how do I output data a row at a time from mysql data?.. I have looked into all tutorials but they are not helping much.

A: 

From what I understand, you're interested in something like this:

# s is object returned by the .select() method
rs = s.execute()
row = rs.fetchone()
# do something with the row
row = rs.fetchone()
# do something with another row

You can find this in a tutorial here.

kender
+1  A: 

Exactly what problems are you running into?

You can simply iterate over the ResultProxy object:

for row in conn_or_sess_or_engine.execute(selectable_obj_or_SQLstring):
   do_something_with(row)
codeape
I think this still loads the whole list into memory. Which with large data sets is bad...
Matthew Schinckel
"I think this still loads the whole list into memory": I do not believe this is correct.
codeape