From: Mike Bayer Date: Wed, 6 Jun 2007 23:39:25 +0000 (+0000) Subject: - fixed bug where selectable.corresponding_column(selectable.c.col) X-Git-Tag: rel_0_4_6~216 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5430c7177ac4bc4f2aeae9bb788b3e0470a6b030;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git - fixed bug where selectable.corresponding_column(selectable.c.col) would not return selectable.c.col, if the selectable is a join of a table and another join involving the same table. messed up ORM decision making [ticket:593] - removed is_natural_case function from ANSIIdentifierPreparer --- diff --git a/CHANGES b/CHANGES index 5f4e67e013..9952137830 100644 --- a/CHANGES +++ b/CHANGES @@ -25,6 +25,11 @@ - sql - long-identifier detection fixed to use > rather than >= for max ident length [ticket:589] + - fixed bug where selectable.corresponding_column(selectable.c.col) + would not return selectable.c.col, if the selectable is a join + of a table and another join involving the same table. messed + up ORM decision making [ticket:593] + - mysql - added 'fields' to reserved words [ticket:590] diff --git a/lib/sqlalchemy/ansisql.py b/lib/sqlalchemy/ansisql.py index 090368a58e..c489d7929a 100644 --- a/lib/sqlalchemy/ansisql.py +++ b/lib/sqlalchemy/ansisql.py @@ -1042,9 +1042,6 @@ class ANSIIdentifierPreparer(object): def should_quote(self, object): return object.quote or self._requires_quotes(object.name, object.case_sensitive) - def is_natural_case(self, object): - return object.quote or self._requires_quotes(object.name, object.case_sensitive) - def format_sequence(self, sequence): return self.__generic_obj_format(sequence, sequence.name) diff --git a/lib/sqlalchemy/schema.py b/lib/sqlalchemy/schema.py index a27adf06ee..492210061e 100644 --- a/lib/sqlalchemy/schema.py +++ b/lib/sqlalchemy/schema.py @@ -103,6 +103,13 @@ class SchemaItem(object): return True def _get_case_sensitive(self): + """late-compile the 'case-sensitive' setting when first accessed. + + typically the SchemaItem will be assembled into its final structure + of other SchemaItems at this point, whereby it can attain this setting + from its containing SchemaItem if not defined locally. + """ + try: return self.__case_sensitive except AttributeError: diff --git a/lib/sqlalchemy/sql.py b/lib/sqlalchemy/sql.py index 265a9c1fdf..afdfc9cb09 100644 --- a/lib/sqlalchemy/sql.py +++ b/lib/sqlalchemy/sql.py @@ -1671,6 +1671,8 @@ class FromClause(Selectable): the exported columns of this ``FromClause``. """ + if column in self.c: + return column if require_embedded and column not in util.Set(self._get_all_embedded_columns()): if not raiseerr: return None diff --git a/test/sql/select.py b/test/sql/select.py index 2f627ee8fe..557527d056 100644 --- a/test/sql/select.py +++ b/test/sql/select.py @@ -249,6 +249,11 @@ sq.myothertable_othername AS sq_myothertable_othername FROM (" + sqstring + ") A table1.select((table1.c.myid != 12) & ~(table1.c.name=='john')), "SELECT mytable.myid, mytable.name, mytable.description FROM mytable WHERE mytable.myid != :mytable_myid AND NOT (mytable.name = :mytable_name)" ) + + self.runtest( + table1.select((table1.c.myid != 12) & ~table1.c.name), + "SELECT mytable.myid, mytable.name, mytable.description FROM mytable WHERE mytable.myid != :mytable_myid AND NOT mytable.name" + ) self.runtest( literal("a") + literal("b") * literal("c"), ":literal + (:literal_1 * :literal_2)" diff --git a/test/sql/selectable.py b/test/sql/selectable.py index cd434a1845..221d8430c4 100755 --- a/test/sql/selectable.py +++ b/test/sql/selectable.py @@ -27,6 +27,13 @@ table2 = Table('table2', db, ) class SelectableTest(testbase.AssertMixin): + def testjoinagainstjoin(self): + j = outerjoin(table, table2, table.c.col1==table2.c.col2) + jj = select([ table.c.col1.label('bar_col1')],from_obj=[j]).alias('foo') + jjj = join(table, jj, table.c.col1==jj.c.bar_col1) + assert jjj.corresponding_column(jjj.c.table1_col1) is jjj.c.table1_col1 + + def testtablealias(self): a = table.alias('a')