summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/sql/compiler.py
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2008-04-07 01:12:44 +0000
committerMike Bayer <mike_mp@zzzcomputing.com>2008-04-07 01:12:44 +0000
commite3b2305d6721a1f1ed20f9c520765f7c33876f32 (patch)
tree8fa4a5565f42dc836a22c44219762dee4b933fd7 /lib/sqlalchemy/sql/compiler.py
parent5b3cddc48e5b436a0c46f0df3b016a837d823c92 (diff)
downloadsqlalchemy-e3b2305d6721a1f1ed20f9c520765f7c33876f32.tar.gz
- merged -r4458:4466 of query_columns branch
- this branch changes query.values() to immediately return an iterator, adds a new "aliased" construct which will be the primary method to get at aliased columns when using values() - tentative ORM versions of _join and _outerjoin are not yet public, would like to integrate with Query better (work continues in the branch) - lots of fixes to expressions regarding cloning and correlation. Some apparent ORM bug-workarounds removed. - to fix a recursion issue with anonymous identifiers, bind parameters generated against columns now just use the name of the column instead of the tablename_columnname label (plus the unique integer counter). this way expensive recursive schemes aren't needed for the anon identifier logic. This, as usual, impacted a ton of compiler unit tests which needed a search-n-replace for the new bind names.
Diffstat (limited to 'lib/sqlalchemy/sql/compiler.py')
-rw-r--r--lib/sqlalchemy/sql/compiler.py16
1 files changed, 7 insertions, 9 deletions
diff --git a/lib/sqlalchemy/sql/compiler.py b/lib/sqlalchemy/sql/compiler.py
index 868904c21..47e5ec9c5 100644
--- a/lib/sqlalchemy/sql/compiler.py
+++ b/lib/sqlalchemy/sql/compiler.py
@@ -18,7 +18,7 @@ creating database-specific compilers and schema generators, the module
is otherwise internal to SQLAlchemy.
"""
-import string, re
+import string, re, itertools
from sqlalchemy import schema, engine, util, exceptions
from sqlalchemy.sql import operators, functions
from sqlalchemy.sql import expression as sql
@@ -47,7 +47,7 @@ ILLEGAL_INITIAL_CHARACTERS = re.compile(r'[0-9$]')
BIND_PARAMS = re.compile(r'(?<![:\w\$\x5c]):([\w\$]+)(?![:\w\$])', re.UNICODE)
BIND_PARAMS_ESC = re.compile(r'\x5c(:[\w\$]+)(?![:\w\$])', re.UNICODE)
-ANONYMOUS_LABEL = re.compile(r'{ANON (-?\d+) (.*?)}')
+ANONYMOUS_LABEL = re.compile(r'{ANON (-?\d+) ([^{}]+)}')
BIND_TEMPLATES = {
'pyformat':"%%(%(name)s)s",
@@ -404,7 +404,7 @@ class DefaultCompiler(engine.Compiled):
def _truncated_identifier(self, ident_class, name):
if (ident_class, name) in self.generated_ids:
return self.generated_ids[(ident_class, name)]
-
+
anonname = ANONYMOUS_LABEL.sub(self._process_anon, name)
if len(anonname) > self.dialect.max_identifier_length:
@@ -415,9 +415,10 @@ class DefaultCompiler(engine.Compiled):
truncname = anonname
self.generated_ids[(ident_class, name)] = truncname
return truncname
-
+
def _process_anon(self, match):
(ident, derived) = match.group(1,2)
+
key = ('anonymous', ident)
if key in self.generated_ids:
return self.generated_ids[key]
@@ -460,7 +461,7 @@ class DefaultCompiler(engine.Compiled):
not isinstance(column.table, sql.Select):
return column.label(column.name)
elif not isinstance(column, (sql._UnaryExpression, sql._TextClause)) and (not hasattr(column, 'name') or isinstance(column, sql._Function)):
- return column.anon_label
+ return column.label(column.anon_label)
else:
return column
@@ -488,10 +489,7 @@ class DefaultCompiler(engine.Compiled):
froms = select._get_display_froms(existingfroms)
- correlate_froms = util.Set()
- for f in froms:
- correlate_froms.add(f)
- correlate_froms.update(f._get_from_objects())
+ correlate_froms = util.Set(itertools.chain(*([froms] + [f._get_from_objects() for f in froms])))
# TODO: might want to propigate existing froms for select(select(select))
# where innermost select should correlate to outermost