From: Mike Bayer Date: Tue, 10 Jul 2007 07:11:56 +0000 (+0000) Subject: changed "_source_column" to simpler "_distance" X-Git-Tag: rel_0_3_9~34 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d947d6b79db6c1aad4b12668252c1ee181641923;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git changed "_source_column" to simpler "_distance" --- diff --git a/lib/sqlalchemy/schema.py b/lib/sqlalchemy/schema.py index d7d728f2b6..9d68dc0079 100644 --- a/lib/sqlalchemy/schema.py +++ b/lib/sqlalchemy/schema.py @@ -604,7 +604,7 @@ class Column(SchemaItem, sql._ColumnClause): c = Column(name or self.name, self.type, self.default, key = name or self.key, primary_key = self.primary_key, nullable = self.nullable, _is_oid = self._is_oid, quote=self.quote, *fk) c.table = selectable c.orig_set = self.orig_set - c._source_column = self + c._distance = self._distance + 1 c.__originating_column = self.__originating_column if not c._is_oid: selectable.columns.add(c) diff --git a/lib/sqlalchemy/sql.py b/lib/sqlalchemy/sql.py index 2a22a40c13..c4272c9269 100644 --- a/lib/sqlalchemy/sql.py +++ b/lib/sqlalchemy/sql.py @@ -1543,16 +1543,6 @@ class ColumnElement(Selectable, _CompareMixin): else: return False - def _distance(self, othercolumn): - c = othercolumn - count = 0 - while c is not self: - c = c._source_column - if c is None: - return -1 - count += 1 - return count - def _make_proxy(self, selectable, name=None): """Create a new ``ColumnElement`` representing this ``ColumnElement`` as it appears in the select list of a @@ -1768,7 +1758,10 @@ class FromClause(Selectable): cp = self._proxy_column(co) for ci in cp.orig_set: cx = self._orig_cols.get(ci) - if cx is None or ci._distance(cp) < ci._distance(cx): + # TODO: the '=' thing here relates to the order of columns as they are placed in the + # "columns" collection of a CompositeSelect, illustrated in test/sql/selectable.SelectableTest.testunion + # make this relationship less brittle + if cx is None or cp._distance <= cx._distance: self._orig_cols[ci] = cp if self.oid_column is not None: for ci in self.oid_column.orig_set: @@ -2088,7 +2081,7 @@ class _Cast(ColumnElement): self.type = sqltypes.to_instance(totype) self.clause = clause self.typeclause = _TypeClause(self.type) - self._source_column = None + self._distance = 0 def get_children(self, **kwargs): return self.clause, self.typeclause @@ -2101,7 +2094,7 @@ class _Cast(ColumnElement): def _make_proxy(self, selectable, name=None): if name is not None: co = _ColumnClause(name, selectable, type=self.type) - co._source_column = self + co._distance = self._distance + 1 co.orig_set = self.orig_set selectable.columns[name]= co return co @@ -2524,7 +2517,7 @@ class _ColumnClause(ColumnElement): self.table = selectable self.type = sqltypes.to_instance(type) self._is_oid = _is_oid - self._source_column = None + self._distance = 0 self.__label = None self.case_sensitive = case_sensitive self.is_literal = is_literal @@ -2584,7 +2577,7 @@ class _ColumnClause(ColumnElement): is_literal = self.is_literal and (name is None or name == self.name) c = _ColumnClause(name or self.name, selectable=selectable, _is_oid=self._is_oid, type=self.type, is_literal=is_literal) c.orig_set = self.orig_set - c._source_column = self + c._distance = self._distance + 1 if not self._is_oid: selectable.columns[c.name] = c return c diff --git a/test/sql/selectable.py b/test/sql/selectable.py index 340c55837d..853821f9af 100755 --- a/test/sql/selectable.py +++ b/test/sql/selectable.py @@ -85,6 +85,8 @@ class SelectableTest(testbase.AssertMixin): print ["%d %s" % (id(c),c.key) for c in u.c] c = u.corresponding_column(s1.c.table1_col2) print "%d %s" % (id(c), c.key) + print id(u.corresponding_column(s1.c.table1_col2).table) + print id(u.c.col2.table) assert u.corresponding_column(s1.c.table1_col2) is u.c.col2 assert u.corresponding_column(s2.c.table2_col2) is u.c.col2