Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #69 -- Implemented dictfetchone(), dictfetchmany() and dictfetc…

…hall() for mysql DB backend. Thanks, Manuzhai!

git-svn-id: http://code.djangoproject.com/svn/django/trunk@190 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 8f4fa5a4e7435876a99383bffafb7a09ba6667e1 1 parent 00f54d6
Adrian Holovaty authored July 19, 2005

Showing 1 changed file with 12 additions and 3 deletions. Show diff stats Hide diff stats

  1. 15  django/core/db/backends/mysql.py
15  django/core/db/backends/mysql.py
@@ -46,17 +46,26 @@ def close(self):
46 46
             self.connection.close()
47 47
             self.connection = None
48 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
+
49 53
 def dictfetchone(cursor):
50 54
     "Returns a row from the cursor as a dict"
51  
-    raise NotImplementedError
  55
+    row = cursor.fetchone()
  56
+    if not row:
  57
+        return None
  58
+    return _dict_helper(cursor.description, row)
52 59
 
53 60
 def dictfetchmany(cursor, number):
54 61
     "Returns a certain number of rows from a cursor as a dict"
55  
-    raise NotImplementedError
  62
+    desc = cursor.description
  63
+    return [_dict_helper(desc, row) for row in cursor.fetchmany(number)]
56 64
 
57 65
 def dictfetchall(cursor):
58 66
     "Returns all rows from a cursor as a dict"
59  
-    raise NotImplementedError
  67
+    desc = cursor.description
  68
+    return [_dict_helper(desc, row) for row in cursor.fetchall()]
60 69
 
61 70
 def get_last_insert_id(cursor, table_name, pk_name):
62 71
     cursor.execute("SELECT LAST_INSERT_ID()")

0 notes on commit 8f4fa5a

Please sign in to comment.
Something went wrong with that request. Please try again.