]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- added some help for a heavily flush-order-dependent test
authorMike Bayer <mike_mp@zzzcomputing.com>
Fri, 16 May 2008 22:10:04 +0000 (22:10 +0000)
committerMike Bayer <mike_mp@zzzcomputing.com>
Fri, 16 May 2008 22:10:04 +0000 (22:10 +0000)
- quote flag propagates to _Label, [ticket:1045]

lib/sqlalchemy/sql/expression.py
test/orm/query.py
test/sql/quote.py

index ec364dd76c4c17fc1474807e1dcd92f51ae178fa..a644582dbc1219b2959b193078a816d99856a6d4 100644 (file)
@@ -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
index 675bd9eb1e0cd00dfdc7569fc310af9742f335fe..af165e47ddd6da05a6a8f1eabb40ba71ce822763 100644 (file)
@@ -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
 
index 6f474ba609c33a786b1412b7bb149440d2139e74..106189afe09285f4032a400df9372195d763f7c1 100644 (file)
@@ -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()