diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2007-03-24 19:24:27 +0000 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2007-03-24 19:24:27 +0000 |
commit | 748f9b9acfdccf614342aae71c33f4d28df0f471 (patch) | |
tree | 347302f584a4855b44a218c2ce1e32b107ad86c6 /lib/sqlalchemy/sql.py | |
parent | e07cf69deff7e2a9152b41385c4505f1acaa958b (diff) | |
download | sqlalchemy-748f9b9acfdccf614342aae71c33f4d28df0f471.tar.gz |
- column labels are now generated in the compilation phase, which
means their lengths are dialect-dependent. So on oracle a label
that gets truncated to 30 chars will go out to 63 characters
on postgres. Also, the true labelname is always attached as the
accessor on the parent Selectable so theres no need to be aware
of the genrerated label names [ticket:512].
- ResultProxy column targeting is greatly simplified, and relies
upon the ANSICompiler's column_labels map to translate the built-in
label on a _ColumnClause (which is now considered to be a unique
identifier of that column) to the label which was generated at compile
time.
- still need to put a baseline of ColumnClause targeting for
ResultProxy objects that originated from a textual query.
Diffstat (limited to 'lib/sqlalchemy/sql.py')
-rw-r--r-- | lib/sqlalchemy/sql.py | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/lib/sqlalchemy/sql.py b/lib/sqlalchemy/sql.py index 8059d9515..bd018e89c 100644 --- a/lib/sqlalchemy/sql.py +++ b/lib/sqlalchemy/sql.py @@ -1771,7 +1771,7 @@ class Join(FromClause): return [self] + self.onclause._get_from_objects() + self.left._get_from_objects() + self.right._get_from_objects() class Alias(FromClause): - def __init__(self, selectable, alias = None): + def __init__(self, selectable, alias=None): baseselectable = selectable while isinstance(baseselectable, Alias): baseselectable = baseselectable.selectable @@ -1808,6 +1808,7 @@ class Alias(FromClause): for c in self.c: yield c yield self.selectable + def accept_visitor(self, visitor): visitor.visit_alias(self) @@ -1865,6 +1866,13 @@ class _ColumnClause(ColumnElement): self.is_literal = is_literal def _get_label(self): + """generate a 'label' for this column. + + the label is a product of the parent table name and column name, and + is treated as a unique identifier of this Column across all Tables and derived + selectables for a particular metadata collection. + """ + # for a "literal" column, we've no idea what the text is # therefore no 'label' can be automatically generated if self.is_literal: @@ -1872,8 +1880,10 @@ class _ColumnClause(ColumnElement): if self.__label is None: if self.table is not None and self.table.named_with_column(): self.__label = self.table.name + "_" + self.name - if self.table.c.has_key(self.__label) or len(self.__label) >= 30: - self.__label = self.__label[0:24] + "_" + hex(random.randint(0, 65535))[2:] + counter = 1 + while self.table.c.has_key(self.__label): + self.__label = self.__label + "_%d" % counter + counter += 1 else: self.__label = self.name self.__label = "".join([x for x in self.__label if x in legal_characters]) |