Ticket #69: my-dict.diff

File my-dict.diff, 1.1 KB (added by Manuzhai <mail@…>, 10 years ago)

Fix the dictfetch*() function for the MySQL backend.

  • backends/mysql.py

     
    4848
    4949def dictfetchone(cursor):
    5050    "Returns a row from the cursor as a dict"
    51     raise NotImplementedError
     51    res = {}
     52    desc = cursor.description
     53    row = cursor.fetchone()
     54    if not row:
     55        return None
     56    for col in enumerate(row):
     57        res[desc[col[0]][0]] = col[1]
     58    return res
    5259
    5360def dictfetchmany(cursor, number):
    5461    "Returns a certain number of rows from a cursor as a dict"
    55     raise NotImplementedError
     62    ls = []
     63    for i in range(number):
     64        ls.append(dictfetchone(cursor))
     65    return ls
    5666
    5767def dictfetchall(cursor):
    5868    "Returns all rows from a cursor as a dict"
    59     raise NotImplementedError
     69    ls = []
     70    row = dictfetchone(cursor)
     71    while row != None:
     72        ls.append(row)
     73        row = dictfetchone(cursor)
     74    return ls
    6075
    6176def get_last_insert_id(cursor, table_name, pk_name):
    6277    cursor.execute("SELECT LAST_INSERT_ID()")
Back to Top