Django

Code

Changeset 190

Show
Ignore:
Timestamp:
07/18/05 21:13:20 (3 years ago)
Author:
adrian
Message:

Fixed #69 -- Implemented dictfetchone(), dictfetchmany() and dictfetchall() for mysql DB backend. Thanks, Manuzhai!

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/trunk/django/core/db/backends/mysql.py

    r171 r190  
    4747            self.connection = None 
    4848 
     49def _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 
    4953def dictfetchone(cursor): 
    5054    "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) 
    5259 
    5360def dictfetchmany(cursor, number): 
    5461    "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)] 
    5664 
    5765def dictfetchall(cursor): 
    5866    "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()] 
    6069 
    6170def get_last_insert_id(cursor, table_name, pk_name):