1048 | | def function_get_list(opts, klass, **kwargs): |
1049 | | # kwargs['select'] is a dictionary, and dictionaries' key order is |
1050 | | # undefined, so we convert it to a list of tuples internally. |
1051 | | kwargs['select'] = kwargs.get('select', {}).items() |
1052 | | |
1053 | | cursor = db.db.cursor() |
1054 | | select, sql, params = function_get_sql_clause(opts, **kwargs) |
1055 | | cursor.execute("SELECT " + (kwargs.get('distinct') and "DISTINCT " or "") + ",".join(select) + sql, params) |
1056 | | obj_list = [] |
1057 | | fill_cache = kwargs.get('select_related') |
1058 | | index_end = len(opts.fields) |
1059 | | for row in cursor.fetchall(): |
1060 | | if fill_cache: |
1061 | | obj, index_end = _get_cached_row(opts, row, 0) |
1062 | | else: |
1063 | | obj = klass(*row[:index_end]) |
1064 | | for i, k in enumerate(kwargs['select']): |
1065 | | setattr(obj, k[0], row[index_end+i]) |
1066 | | obj_list.append(obj) |
1067 | | return obj_list |
1068 | | |