summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/sql/compiler.py
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2012-02-05 16:58:32 -0500
committerMike Bayer <mike_mp@zzzcomputing.com>2012-02-05 16:58:32 -0500
commit2dbeeff50b7ccc6f47b2816a59f99f051fdabc8c (patch)
treec23ba02c34a7fec923bdddd99ff46b670e30bac2 /lib/sqlalchemy/sql/compiler.py
parent28765734826f2619fcfd40f047a5980c3af49010 (diff)
downloadsqlalchemy-2dbeeff50b7ccc6f47b2816a59f99f051fdabc8c.tar.gz
- [bug] Added support for using the .key
of a Column as a string identifier in a result set row. The .key is currently listed as an "alternate" name for a column, and is superseded by the name of a column which has that key value as its regular name. For the next major release of SQLAlchemy we may reverse this precedence so that .key takes precedence, but this is not decided on yet. [ticket:2392]
Diffstat (limited to 'lib/sqlalchemy/sql/compiler.py')
-rw-r--r--lib/sqlalchemy/sql/compiler.py26
1 files changed, 19 insertions, 7 deletions
diff --git a/lib/sqlalchemy/sql/compiler.py b/lib/sqlalchemy/sql/compiler.py
index 598e87932..de18c48f9 100644
--- a/lib/sqlalchemy/sql/compiler.py
+++ b/lib/sqlalchemy/sql/compiler.py
@@ -154,9 +154,10 @@ class _CompileLabel(visitors.Visitable):
__visit_name__ = 'label'
__slots__ = 'element', 'name'
- def __init__(self, col, name):
+ def __init__(self, col, name, alt_names=()):
self.element = col
self.name = name
+ self._alt_names = alt_names
@property
def proxy_set(self):
@@ -360,8 +361,10 @@ class SQLCompiler(engine.Compiled):
labelname = label.name
if result_map is not None:
- result_map[labelname.lower()] = \
- (label.name, (label, label.element, labelname),\
+ result_map[labelname.lower()] = (
+ label.name,
+ (label, label.element, labelname, ) +
+ label._alt_names,
label.type)
return label.element._compiler_dispatch(self,
@@ -386,7 +389,9 @@ class SQLCompiler(engine.Compiled):
name = self._truncated_identifier("colident", name)
if result_map is not None:
- result_map[name.lower()] = (orig_name, (column, name), column.type)
+ result_map[name.lower()] = (orig_name,
+ (column, name, column.key),
+ column.type)
if is_literal:
name = self.escape_literal_column(name)
@@ -775,8 +780,14 @@ class SQLCompiler(engine.Compiled):
if isinstance(column, sql._Label):
return column
- elif select is not None and select.use_labels and column._label:
- return _CompileLabel(column, column._label)
+ elif select is not None and \
+ select.use_labels and \
+ column._label:
+ return _CompileLabel(
+ column,
+ column._label,
+ alt_names=(column._key_label, )
+ )
elif \
asfrom and \
@@ -784,7 +795,8 @@ class SQLCompiler(engine.Compiled):
not column.is_literal and \
column.table is not None and \
not isinstance(column.table, sql.Select):
- return _CompileLabel(column, sql._as_truncated(column.name))
+ return _CompileLabel(column, sql._as_truncated(column.name),
+ alt_names=(column.key,))
elif not isinstance(column,
(sql._UnaryExpression, sql._TextClause)) \
and (not hasattr(column, 'name') or \