summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/sql/compiler.py
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2014-02-20 16:14:29 -0500
committerMike Bayer <mike_mp@zzzcomputing.com>2014-02-20 16:14:29 -0500
commitceaa6047ef8bc3916ffdda1924844cbf233dfd94 (patch)
treeb4eb8c510023f4dc0c3142aec3ae91bce5e6a59f /lib/sqlalchemy/sql/compiler.py
parent5c88f38c7259780e9acc18cc8752110b1d369c23 (diff)
downloadsqlalchemy-ceaa6047ef8bc3916ffdda1924844cbf233dfd94.tar.gz
- More fixes to SQLite "join rewriting"; the fix from :ticket:`2967`
implemented right before the release of 0.9.3 affected the case where a UNION contained nested joins in it. "Join rewriting" is a feature with a wide range of possibilities and is the first intricate "SQL rewriting" feature we've introduced in years, so we're sort of going through a lot of iterations with it (not unlike eager loading back in the 0.2/0.3 series, polymorphic loading in 0.4/0.5). We should be there soon so thanks for bearing with us :). fixes #2969 re: #2967 - solve the issue of join rewriting inspecting various types of from objects without using isinstance(), by adding some new underscored inspection flags to the FromClause hierarchy.
Diffstat (limited to 'lib/sqlalchemy/sql/compiler.py')
-rw-r--r--lib/sqlalchemy/sql/compiler.py29
1 files changed, 17 insertions, 12 deletions
diff --git a/lib/sqlalchemy/sql/compiler.py b/lib/sqlalchemy/sql/compiler.py
index 148da19aa..5165ee78f 100644
--- a/lib/sqlalchemy/sql/compiler.py
+++ b/lib/sqlalchemy/sql/compiler.py
@@ -1280,13 +1280,7 @@ class SQLCompiler(Compiled):
cloned = {}
column_translate = [{}]
- # TODO: should we be using isinstance() for this,
- # as this whole system won't work for custom Join/Select
- # subclasses where compilation routines
- # call down to compiler.visit_join(), compiler.visit_select()
- join_name = selectable.Join.__visit_name__
- select_name = selectable.Select.__visit_name__
- alias_name = selectable.Alias.__visit_name__
+
def visit(element, **kw):
if element in column_translate[-1]:
return column_translate[-1][element]
@@ -1296,7 +1290,7 @@ class SQLCompiler(Compiled):
newelem = cloned[element] = element._clone()
- if newelem.__visit_name__ is join_name and \
+ if newelem.is_selectable and newelem._is_join and \
isinstance(newelem.right, selectable.FromGrouping):
newelem._reset_exported()
@@ -1340,11 +1334,22 @@ class SQLCompiler(Compiled):
newelem.right = selectable_
newelem.onclause = visit(newelem.onclause, **kw)
- elif newelem.__visit_name__ is alias_name \
- and newelem.element.__visit_name__ is select_name:
- column_translate.append({})
+
+ elif newelem.is_selectable and newelem._is_from_container:
+ # if we hit an Alias or CompoundSelect, put a marker in the
+ # stack.
+ kw['transform_clue'] = 'select_container'
+ newelem._copy_internals(clone=visit, **kw)
+ elif newelem.is_selectable and newelem._is_select:
+ barrier_select = kw.get('transform_clue', None) == 'select_container'
+ # if we're still descended from an Alias/CompoundSelect, we're
+ # in a FROM clause, so start with a new translate collection
+ if barrier_select:
+ column_translate.append({})
+ kw['transform_clue'] = 'inside_select'
newelem._copy_internals(clone=visit, **kw)
- del column_translate[-1]
+ if barrier_select:
+ del column_translate[-1]
else:
newelem._copy_internals(clone=visit, **kw)