Yield blocks of rows from a cursor and ensure the cursor is closed when done.
(cursor, sentinel, col_count, itersize)
| 2255 | |
| 2256 | |
| 2257 | def cursor_iter(cursor, sentinel, col_count, itersize): |
| 2258 | """ |
| 2259 | Yield blocks of rows from a cursor and ensure the cursor is closed when |
| 2260 | done. |
| 2261 | """ |
| 2262 | try: |
| 2263 | for rows in iter((lambda: cursor.fetchmany(itersize)), sentinel): |
| 2264 | yield rows if col_count is None else [r[:col_count] for r in rows] |
| 2265 | finally: |
| 2266 | cursor.close() |