]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- added test for threadlocal not supporting begin_nested()
authorMike Bayer <mike_mp@zzzcomputing.com>
Sun, 18 May 2008 15:49:14 +0000 (15:49 +0000)
committerMike Bayer <mike_mp@zzzcomputing.com>
Sun, 18 May 2008 15:49:14 +0000 (15:49 +0000)
- removed query.compile(); use explicit query.with_labels().statement instead
- moved statement annotation step upwards from query._compile_context() to outliers from_self()/statement.  speeds zoomark.step_6_editing by 16%

lib/sqlalchemy/orm/query.py
test/engine/transaction.py
test/orm/manytomany.py
test/orm/query.py

index 5df13d8d9470deb821b2d41b9e8a2acb03957f6e..084f9b81d116e313b4344fdeaf4d2210bf95d524 100644 (file)
@@ -304,7 +304,7 @@ class Query(object):
 
     def statement(self):
         """return the full SELECT statement represented by this Query."""
-        return self._compile_context(labels=self._with_labels).statement
+        return self._compile_context(labels=self._with_labels).statement._annotate({'_halt_adapt': True})
     statement = property(statement)
 
     def subquery(self):
@@ -537,7 +537,7 @@ class Query(object):
         those being selected.
         """
 
-        fromclause = self.compile().correlate(None)
+        fromclause = self.with_labels().statement.correlate(None)
         self._statement = self._criterion = None
         self._order_by = self._group_by = self._distinct = False
         self._limit = self._offset = None
@@ -1240,11 +1240,6 @@ class Query(object):
             self.session._autoflush()
         return self.session.scalar(s, params=self._params, mapper=self._mapper_zero())
 
-    def compile(self):
-        """compiles and returns a SQL statement based on the criterion and conditions within this Query."""
-
-        return self._compile_context().statement
-
     def _compile_context(self, labels=True):
         context = QueryContext(self)
 
@@ -1324,9 +1319,9 @@ class Query(object):
 
             if context.eager_order_by:
                 statement.append_order_by(*context.eager_order_by)
-
-        context.statement = statement._annotate({'_halt_adapt': True})
-
+                
+        context.statement = statement
+        
         return context
 
     def __log_debug(self, msg):
index 69d35748ba97ada17f4dcf0e4021721b6d2d6bd1..7d8d6bd61ac2f71e94c91659d878d0947d12f0db 100644 (file)
@@ -453,6 +453,10 @@ class TLTransactionTest(TestBase):
         users.drop(tlengine)
         tlengine.dispose()
 
+    def test_nested_unsupported(self):
+        self.assertRaises(NotImplementedError, tlengine.contextual_connect().begin_nested)
+        self.assertRaises(NotImplementedError, tlengine.begin_nested)
+        
     def test_connection_close(self):
         """test that when connections are closed for real, transactions are rolled back and disposed."""
 
index 3fc62cd766d332d2b6b65155e8e0b3ad7df5c391..7a60f01c6f3680df081df38b16167fc5e5fa1bf7 100644 (file)
@@ -302,7 +302,10 @@ class M2MTest3(_base.MappedTest):
             'a1s': relation(A, secondary=c2a1, lazy=False),
             'a2s': relation(A, secondary=c2a2, lazy=False)})
 
-        assert create_session().query(C).compile()
+        assert create_session().query(C).with_labels().statement
+        
+        # TODO: seems like just a test for an ancient exception throw.
+        # how about some data/inserts/queries/assertions for this one
 
 
 if __name__ == "__main__":
index af165e47ddd6da05a6a8f1eabb40ba71ce822763..490f4ede398410131477c8374bd4f7890b9e1924 100644 (file)
@@ -326,7 +326,7 @@ class CompileTest(QueryTest):
         
     def test_deferred(self):
         session = create_session()
-        s = session.query(User).filter(and_(addresses.c.email_address == bindparam('emailad'), Address.user_id==User.id)).compile()
+        s = session.query(User).filter(and_(addresses.c.email_address == bindparam('emailad'), Address.user_id==User.id)).statement
 
         l = session.query(User).instances(s.execute(emailad = 'jack@bean.com'))
         assert [User(id=7)] == l