def fetch_with_names(query,
                     dbhandle=None,
                     attach=False):

    dbhandle = connect(dbhandle, attach=attach)

    cc = dbhandle.cursor()
    sqlresult = cc.execute(query).fetchall()

    data = []
    # http://stackoverflow.com/questions/4147707/
    # python-mysqldb-sqlite-result-as-dictionary
    field_names = [d[0] for d in cc.description]
    data.append([name for name in field_names])
    for record in sqlresult:
        line = [field for field in record]
        data.append(line)

    cc.close()
    return data
Fetch query results and returns them as an array of row arrays, in
dataset/ETHPy150Open CGATOxford/cgat/CGAT/Database.py/fetch_with_names