From 8fd9f09b72eea08c16d74378d29e0eee54e3e962 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Thu, 15 Jul 2010 19:00:21 +0200 Subject: [PATCH] Use explicit AS column name in queries that use dictfetch* SQLite return wrong column name when using query as table --- trytond/model/modelsql.py | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/trytond/model/modelsql.py b/trytond/model/modelsql.py index bcc6e65401..41ac19b71d 100644 --- a/trytond/model/modelsql.py +++ b/trytond/model/modelsql.py @@ -491,21 +491,23 @@ class ModelSQL(ModelStorage): history_limit = cursor.limit_clause('', 1) history_args = [context['_datetime']] if len(fields_pre) : - fields_pre2 = ['"' + x + '"' for x in fields_pre \ - if x != '_timestamp'] + fields_pre2 = ['"%s"."%s" AS "%s"' % (self._table, x, x) + for x in fields_pre if x != '_timestamp'] if '_timestamp' in fields_pre: if not self.table_query(context): fields_pre2 += ['CAST(EXTRACT(EPOCH FROM ' - '(COALESCE(write_date, create_date))) AS ' + \ - FIELDS['numeric'].sql_type(self.create_date)[1] + \ - ') AS _timestamp'] + '(COALESCE("%s".write_date, "%s".create_date))) AS %s' + ') AS _timestamp' % + (self._table, self._table, + FIELDS['numeric'].sql_type(self.create_date)[1])] for i in range(0, len(ids), in_max): sub_ids = ids[i:i + in_max] red_sql, red_ids = reduce_ids('id', sub_ids) if domain1: cursor.execute('SELECT ' + \ - ','.join(fields_pre2 + ['id']) + \ + ','.join(fields_pre2 + + ['"%s".id AS id' % self._table]) + \ ' FROM ' + table_query + '\"' + self._table +'\" ' \ 'WHERE ' + red_sql + \ history_clause + \ @@ -514,7 +516,8 @@ class ModelSQL(ModelStorage): table_args + red_ids + history_args + domain2) else: cursor.execute('SELECT ' + \ - ','.join(fields_pre2 + ['id']) + \ + ','.join(fields_pre2 + + ['"%s".id AS id' % self._table]) + \ ' FROM ' + table_query + '\"' + self._table + '\" '\ 'WHERE ' + red_sql + \ history_clause + history_order + history_limit,