From 9aead60fe323812d24c56033adf2fbdd7e985ad6 Mon Sep 17 00:00:00 2001 From: adustman Date: Wed, 8 Mar 2000 22:50:06 +0000 Subject: [PATCH] Support for fetching rows as dictionaries, a la MySQLmodule. --- mysql/MySQLdb.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/mysql/MySQLdb.py b/mysql/MySQLdb.py index f69b545..89072ad 100644 --- a/mysql/MySQLdb.py +++ b/mysql/MySQLdb.py @@ -230,6 +230,24 @@ class _Cursor: """Fetchs all available rows from the cursor.""" return self.result.fetch_all_rows() + def fetchoneDict(self): + """Fetches a single row from the cursor as a dictionary.""" + try: + return self.result.fetch_row_as_dict() + except AttributeError: + raise ProgrammingError, "no query executed yet" + + def fetchmanyDict(self, size=None): + """cursor.fetchmany(size=cursor.arraysize) + + size -- integer, maximum number of rows to fetch. + rows are returned as dictionaries.""" + return self.result.fetch_rows_as_dict(size or self.arraysize) + + def fetchallDict(self): + """Fetchs all available rows from the cursor as dictionaries.""" + return self.result.fetch_all_rows_as_dict() + def nextset(self): return None