| 48 | | |
|---|
| 49 | | def _dict_helper(desc, row): |
|---|
| 50 | | "Returns a dictionary for the given cursor.description and result row." |
|---|
| 51 | | return dict([(desc[col[0]][0], col[1]) for col in enumerate(row)]) |
|---|
| 52 | | |
|---|
| 53 | | def dictfetchone(cursor): |
|---|
| 54 | | "Returns a row from the cursor as a dict" |
|---|
| 55 | | row = cursor.fetchone() |
|---|
| 56 | | if not row: |
|---|
| 57 | | return None |
|---|
| 58 | | return _dict_helper(cursor.description, row) |
|---|
| 59 | | |
|---|
| 60 | | def dictfetchmany(cursor, number): |
|---|
| 61 | | "Returns a certain number of rows from a cursor as a dict" |
|---|
| 62 | | desc = cursor.description |
|---|
| 63 | | return [_dict_helper(desc, row) for row in cursor.fetchmany(number)] |
|---|
| 64 | | |
|---|
| 65 | | def dictfetchall(cursor): |
|---|
| 66 | | "Returns all rows from a cursor as a dict" |
|---|
| 67 | | desc = cursor.description |
|---|
| 68 | | return [_dict_helper(desc, row) for row in cursor.fetchall()] |
|---|