Use explicit AS column name in queries that use dictfetch*

SQLite return wrong column name when using query as table
This commit is contained in:
Cédric Krier committed 2010-07-15 19:00:21 +02:00
1 parent 092196ba4b
commit 8fd9f09b72
1 file changed
+10 -7
+10 -7
View File
@@ -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,