From: Mike Bayer Date: Fri, 16 May 2008 22:10:04 +0000 (+0000) Subject: - added some help for a heavily flush-order-dependent test X-Git-Tag: rel_0_5beta1~64 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=07496da9b5272451fa85b02871369b3f3ba8bcca;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git - added some help for a heavily flush-order-dependent test - quote flag propagates to _Label, [ticket:1045] --- diff --git a/lib/sqlalchemy/sql/expression.py b/lib/sqlalchemy/sql/expression.py index ec364dd76c..a644582dbc 100644 --- a/lib/sqlalchemy/sql/expression.py +++ b/lib/sqlalchemy/sql/expression.py @@ -1807,7 +1807,8 @@ class _BindParamClause(ClauseElement, _CompareMixin): """ __visit_name__ = 'bindparam' - + quote = None + def __init__(self, key, value, type_=None, unique=False, isoutparam=False, shortname=None): """Construct a _BindParamClause. @@ -2521,6 +2522,7 @@ class _Label(ColumnElement): self.name = name or "{ANON %d %s}" % (id(self), getattr(element, 'name', 'anon')) self.element = element.self_group(against=operators.as_) self.type = sqltypes.to_instance(type_ or getattr(element, 'type', None)) + self.quote = element.quote def key(self): return self.name diff --git a/test/orm/query.py b/test/orm/query.py index 675bd9eb1e..af165e47dd 100644 --- a/test/orm/query.py +++ b/test/orm/query.py @@ -2089,12 +2089,21 @@ class TestOverlyEagerEquivalentCols(_base.MappedTest): mapper(Sub1, sub1) mapper(Sub2, sub2) sess = create_session() - b1 = Base(data='b1', sub1=[Sub1(data='s11')], sub2=[]) - b2 = Base(data='b1', sub1=[Sub1(data='s12')], sub2=[Sub2(data='s2')]) + + s11 = Sub1(data='s11') + s12 = Sub1(data='s12') + s2 = Sub2(data='s2') + b1 = Base(data='b1', sub1=[s11], sub2=[]) + b2 = Base(data='b1', sub1=[s12], sub2=[]) sess.add(b1) sess.add(b2) sess.flush() + # theres an overlapping ForeignKey here, so not much option except + # to artifically control the flush order + b2.sub2 = [s2] + sess.flush() + q = sess.query(Base).outerjoin('sub2', aliased=True) assert sub1.c.id not in q._filter_aliases.equivalents diff --git a/test/sql/quote.py b/test/sql/quote.py index 6f474ba609..106189afe0 100644 --- a/test/sql/quote.py +++ b/test/sql/quote.py @@ -80,10 +80,33 @@ class QuoteTest(TestBase, AssertsCompiledSQL): Column('col1', Integer, quote=True), quote=True, schema="foo", quote_schema=True) self.assert_compile(t1.select(), '''SELECT "foo"."t1"."col1" FROM "foo"."t1"''') + self.assert_compile(t1.select().apply_labels(), '''SELECT "foo"."t1"."col1" AS "foo_t1_col1" FROM "foo"."t1"''') + a = t1.select().alias('anon') + b = select([1], a.c.col1==2, from_obj=a) + self.assert_compile(b, + '''SELECT 1 FROM (SELECT "foo"."t1"."col1" AS "col1" FROM '''\ + '''"foo"."t1") AS anon WHERE anon."col1" = :col1_1''' + ) + metadata = MetaData() t1 = Table('TableOne', metadata, Column('ColumnOne', Integer, quote=False), quote=False, schema="FooBar", quote_schema=False) - self.assert_compile(t1.select(), '''SELECT FooBar.TableOne.ColumnOne FROM FooBar.TableOne''') + self.assert_compile(t1.select(), "SELECT FooBar.TableOne.ColumnOne FROM FooBar.TableOne") + + self.assert_compile(t1.select().apply_labels(), + "SELECT FooBar.TableOne.ColumnOne AS "\ + "FooBar_TableOne_ColumnOne FROM FooBar.TableOne" # TODO: is this what we really want here ? what if table/schema + # *are* quoted? + ) + + a = t1.select().alias('anon') + b = select([1], a.c.ColumnOne==2, from_obj=a) + self.assert_compile(b, + "SELECT 1 FROM (SELECT FooBar.TableOne.ColumnOne AS "\ + "ColumnOne FROM FooBar.TableOne) AS anon WHERE anon.ColumnOne = :ColumnOne_1" + ) + + def test_table_quote_flag(self): metadata = MetaData()