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 

More like this

  1. WorldIP - access to IP database over API by Alrond 3 years, 8 months ago
  2. Memory efficient Django Queryset Iterator by WoLpH 2 years, 2 months ago
  3. SQL Log Middleware + duplicates by guettli 4 years, 10 months ago
  4. Function/Stored Procedure Manager by axiak 4 years, 11 months ago
  5. Use the development server on the network by perevilas 1 year, 2 months ago

Comments

(Forgotten your password?)