iter_fetchmany

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
def iter_fetchmany(cursor, size=100): 
    """ 
    Handles the awkwardness of iterating using fetchmany, and exposes all records as a (generated) iterable. 
 
    Assumes django.db is the connection for the given cursor.  FIXME for multi-db support. 
    """ 
    from django.db import connection 
    rowset_iter = iter((lambda: cursor.fetchmany(size)), 
            connection.features.empty_fetchmany_value) 
    for rows in rowset_iter: 
        for row in rows: 
            yield row 

Comments

(Forgotten your password?)

You may use Markdown syntax here, but raw HTML will be removed.