diff --git a/trytond/backend/postgresql/database.py b/trytond/backend/postgresql/database.py index 38da3f5375..dad35e6b2f 100644 --- a/trytond/backend/postgresql/database.py +++ b/trytond/backend/postgresql/database.py @@ -241,10 +241,8 @@ class Database(DatabaseInterface): class _Cursor(cursor): def __build_dict(self, row): - res = {} - for i in range(len(self.description)): - res[self.description[i][0]] = row[i] - return res + return dict((desc[0], row[i]) + for i, desc in enumerate(self.description)) def dictfetchone(self): row = self.fetchone() @@ -254,18 +252,12 @@ class _Cursor(cursor): return row def dictfetchmany(self, size): - res = [] rows = self.fetchmany(size) - for row in rows: - res.append(self.__build_dict(row)) - return res + return [self.__build_dict(row) for row in rows] def dictfetchall(self): - res = [] rows = self.fetchall() - for row in rows: - res.append(self.__build_dict(row)) - return res + return [self.__build_dict(row) for row in rows] class Cursor(CursorInterface): diff --git a/trytond/backend/sqlite/database.py b/trytond/backend/sqlite/database.py index 2774eca21c..d522a599ce 100644 --- a/trytond/backend/sqlite/database.py +++ b/trytond/backend/sqlite/database.py @@ -233,10 +233,8 @@ class Database(DatabaseInterface): class _Cursor(sqlite.Cursor): def __build_dict(self, row): - res = {} - for i in range(len(self.description)): - res[self.description[i][0].strip('"')] = row[i] - return res + return dict((desc[0], row[i]) + for i, desc in enumerate(self.description)) def dictfetchone(self): row = self.fetchone() @@ -246,18 +244,12 @@ class _Cursor(sqlite.Cursor): return row def dictfetchmany(self, size): - res = [] rows = self.fetchmany(size) - for row in rows: - res.append(self.__build_dict(row)) - return res + return [self.__build_dict(row) for row in rows] def dictfetchall(self): - res = [] rows = self.fetchall() - for row in rows: - res.append(self.__build_dict(row)) - return res + return [self.__build_dict(row) for row in rows] class Cursor(CursorInterface):