On Fri, Jul 4, 2014 at 6:54 AM, 'Frank Liou' via sqlalchemy
<sqlalchemy@googlegroups.com> wrote:
>
>> Hi Simon
>
>
> thanks for your answer
>
> but i can't understand what's "fetchall()" mean
>
> i remove the  " fetchall()"  it still work....
>

This is because the ResultProxy returned from conn.execute() is what
is known in Python as "iterable", which basically means that you can
iterate over it (for example, use it in a "for" loop or a list
comprehension).

The main catch is that you can only iterate over the ResultProxy once,
so the following wouldn't work:

    rows = conn.execute(check)

    # This line iterates over the ResultProxy, consuming it in the process
    obj1 = [dict(row.items()) for row in rows]

    # This line will not do what you expect because
    # the ResultProxy has been consumed
    obj2 = [dict(row.items()) for row in rows]

If you use .fetchall(), then "rows" is a simple python list, so you
can iterate over it as many times as you like. For what you are trying
to do, you don't need to iterate over it more than once, so it doesn't
really matter which you do.

There are other things to be aware of. You can't necessarily use the
len() function to get the length of an arbitrary iterable, you can't
sort them in place, and so on.

Hope that helps,

Simon

-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.

Reply via email to