else isinstance(right.name, elements._anonymous_label)
)
+ def compare_cte(self, elements, left, right, **kw):
+ raise NotImplementedError("TODO")
+
def compare_extract(self, left, right, **kw):
return left.field == right.field
self.element._generate_fromclause_column_proxies(self)
def _copy_internals(self, clone=_clone, **kw):
- # don't apply anything to an aliased Table
- # for now. May want to drive this from
- # the given **kw.
- if isinstance(self.element, TableClause):
- return
- self._reset_exported()
- self.element = clone(self.element, **kw)
+ element = clone(self.element, **kw)
+ if element is not self.element:
+ self._reset_exported()
+ self.element = element
def get_children(self, column_collections=True, **kw):
if column_collections:
[clone(elem, **kw) for elem in self._restates]
)
+ def _cache_key(self, *arg, **kw):
+ raise NotImplementedError("TODO")
+
def alias(self, name=None, flat=False):
"""Return an :class:`.Alias` of this :class:`.CTE`.
raise NotImplementedError()
def _copy_internals(self, clone=_clone, **kw):
- if self._limit_clause is not None:
- self._limit_clause = clone(self._limit_clause, **kw)
- if self._offset_clause is not None:
- self._offset_clause = clone(self._offset_clause, **kw)
+ raise NotImplementedError()
class CompoundSelect(GenerativeSelect):
return self.selects[0].selected_columns
def _copy_internals(self, clone=_clone, **kw):
- super(CompoundSelect, self)._copy_internals(clone, **kw)
self._reset_memoizations()
self.selects = [clone(s, **kw) for s in self.selects]
if hasattr(self, "_col_map"):
del self._col_map
for attr in (
+ "_limit_clause",
+ "_offset_clause",
"_order_by_clause",
"_group_by_clause",
"_for_update_arg",
return False
def _copy_internals(self, clone=_clone, **kw):
- super(Select, self)._copy_internals(clone, **kw)
# Select() object has been cloned and probably adapted by the
# given clone function. Apply the cloning function to internal
# present here.
self._raw_columns = [clone(c, **kw) for c in self._raw_columns]
for attr in (
+ "_limit_clause",
+ "_offset_clause",
"_whereclause",
"_having",
"_order_by_clause",
return newcol
def replace(self, col):
- if isinstance(col, FromClause) and self.selectable.is_derived_from(
- col
- ):
- return self.selectable
+ if isinstance(col, FromClause):
+ if self.selectable.is_derived_from(col):
+ return self.selectable
+ elif isinstance(col, Alias) and isinstance(
+ col.element, TableClause
+ ):
+ # we are a SELECT statement and not derived from an alias of a
+ # table (which nonetheless may be a table our SELECT derives
+ # from), so return the alias to prevent futher traversal
+ # or
+ # we are an alias of a table and we are not derived from an
+ # alias of a table (which nonetheless may be the same table
+ # as ours) so, same thing
+ return col
+ else:
+ # other cases where we are a selectable and the element
+ # is another join or selectable that contains a table which our
+ # selectable derives from, that we want to process
+ return None
elif not isinstance(col, ColumnElement):
return None
elif self.include_fn and not self.include_fn(col):
)
s = vis.traverse(s)
- assert t2alias not in s._froms # not present because it's been
- # cloned
+ assert t2alias in s._froms # present because it was not cloned
assert t1alias in s._froms # present because the adapter placed
- # it there
+ # it there and was also not cloned
# correlate list on "s" needs to take into account the full
# _cloned_set for each element in _froms when correlating
s2 = select([s1]).limit(5).offset(10).alias()
talias = t1.alias("bar")
+ # here is the problem. s2 is derived from s1 which is derived
+ # from t1
+ assert s2.is_derived_from(t1)
+
+ # however, s2 is not derived from talias, which *is* derived from t1
assert not s2.is_derived_from(talias)
+
+ # therefore, talias gets its table replaced, except for a rule
+ # we added to ClauseAdapter to stop traversal if the selectable is
+ # not derived from an alias of a table. This rule was previously
+ # in Alias._copy_internals().
+
j = s1.outerjoin(talias, s1.c.col1 == talias.c.col1)
self.assert_compile(