]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- inlined a couple of context variables
authorMike Bayer <mike_mp@zzzcomputing.com>
Sat, 27 Oct 2007 18:45:20 +0000 (18:45 +0000)
committerMike Bayer <mike_mp@zzzcomputing.com>
Sat, 27 Oct 2007 18:45:20 +0000 (18:45 +0000)
- PG two phase was calling text() without the correct bind param format, previous compiler checkin revealed issue

lib/sqlalchemy/databases/postgres.py
lib/sqlalchemy/engine/base.py
lib/sqlalchemy/engine/default.py
lib/sqlalchemy/pool.py
test/engine/transaction.py

index 6449bdc1447e2b0b9e48433a8d5280a0d3928d49..00b297f973b952bf0c4a4ceacf2e819b6ef93fbe 100644 (file)
@@ -310,7 +310,7 @@ class PGDialect(default.DefaultDialect):
         self.do_begin(connection.connection)
 
     def do_prepare_twophase(self, connection, xid):
-        connection.execute(sql.text("PREPARE TRANSACTION %(tid)s", bindparams=[sql.bindparam('tid', xid)]))
+        connection.execute(sql.text("PREPARE TRANSACTION :tid", bindparams=[sql.bindparam('tid', xid)]))
 
     def do_rollback_twophase(self, connection, xid, is_prepared=True, recover=False):
         if is_prepared:
@@ -318,7 +318,7 @@ class PGDialect(default.DefaultDialect):
                 #FIXME: ugly hack to get out of transaction context when commiting recoverable transactions
                 # Must find out a way how to make the dbapi not open a transaction.
                 connection.execute(sql.text("ROLLBACK"))
-            connection.execute(sql.text("ROLLBACK PREPARED %(tid)s", bindparams=[sql.bindparam('tid', xid)]))
+            connection.execute(sql.text("ROLLBACK PREPARED :tid", bindparams=[sql.bindparam('tid', xid)]))
             connection.execute(sql.text("BEGIN"))
             self.do_rollback(connection.connection)
         else:
@@ -328,7 +328,7 @@ class PGDialect(default.DefaultDialect):
         if is_prepared:
             if recover:
                 connection.execute(sql.text("ROLLBACK"))
-            connection.execute(sql.text("COMMIT PREPARED %(tid)s", bindparams=[sql.bindparam('tid', xid)]))
+            connection.execute(sql.text("COMMIT PREPARED :tid", bindparams=[sql.bindparam('tid', xid)]))
             connection.execute(sql.text("BEGIN"))
             self.do_rollback(connection.connection)
         else:
index 131f50540443dd722351cddf300ab5c5e03b1dfb..880362938dbe32823c736559bf32f4597426b356 100644 (file)
@@ -671,32 +671,30 @@ class Connection(Connectable):
         return self.__transaction is not None
 
     def _begin_impl(self):
-        if self.__connection.is_valid:
-            if self.__engine._should_log_info:
-                self.__engine.logger.info("BEGIN")
-            try:
-                self.__engine.dialect.do_begin(self.connection)
-            except Exception, e:
-                raise exceptions.DBAPIError.instance(None, None, e)
+        if self.__engine._should_log_info:
+            self.__engine.logger.info("BEGIN")
+        try:
+            self.__engine.dialect.do_begin(self.__connection)
+        except Exception, e:
+            raise exceptions.DBAPIError.instance(None, None, e)
 
     def _rollback_impl(self):
         if self.__connection.is_valid:
             if self.__engine._should_log_info:
                 self.__engine.logger.info("ROLLBACK")
             try:
-                self.__engine.dialect.do_rollback(self.connection)
+                self.__engine.dialect.do_rollback(self.__connection)
             except Exception, e:
                 raise exceptions.DBAPIError.instance(None, None, e)
         self.__transaction = None
 
     def _commit_impl(self):
-        if self.__connection.is_valid:
-            if self.__engine._should_log_info:
-                self.__engine.logger.info("COMMIT")
-            try:
-                self.__engine.dialect.do_commit(self.connection)
-            except Exception, e:
-                raise exceptions.DBAPIError.instance(None, None, e)
+        if self.__engine._should_log_info:
+            self.__engine.logger.info("COMMIT")
+        try:
+            self.__engine.dialect.do_commit(self.__connection)
+        except Exception, e:
+            raise exceptions.DBAPIError.instance(None, None, e)
         self.__transaction = None
 
     def _savepoint_impl(self, name=None):
@@ -1307,6 +1305,7 @@ class ResultProxy(object):
         self.dialect = context.dialect
         self.closed = False
         self.cursor = context.cursor
+        self.connection = context.root_connection
         self.__echo = context.engine._should_log_info
         if context.is_select():
             self._init_metadata()
@@ -1315,8 +1314,6 @@ class ResultProxy(object):
             self._rowcount = context.get_rowcount()
             self.close()
 
-    connection = property(lambda self:self.context.root_connection)
-
     def _get_rowcount(self):
         if self._rowcount is not None:
             return self._rowcount
index d826b97fadabf9ec0a5fbf9711fb07203628a68d..c98519ffe84942e3bab1d2da28fa177a9f5e209c 100644 (file)
@@ -134,7 +134,7 @@ class DefaultDialect(base.Dialect):
 class DefaultExecutionContext(base.ExecutionContext):
     def __init__(self, dialect, connection, compiled=None, statement=None, parameters=None):
         self.dialect = dialect
-        self._connection = connection
+        self._connection = self.root_connection = connection
         self.compiled = compiled
         self._postfetch_cols = util.Set()
         self.engine = connection.engine
@@ -169,8 +169,6 @@ class DefaultExecutionContext(base.ExecutionContext):
     
     connection = property(lambda s:s._connection._branch())
     
-    root_connection = property(lambda s:s._connection)
-    
     def __encode_param_keys(self, params):
         """apply string encoding to the keys of dictionary-based bind parameters.
         
index a80502df0fe2ccc66ee654a9e62b8e9a62095ad5..8b3acbec5b5d1d10c506c83a2d1759ff98887822 100644 (file)
@@ -301,7 +301,7 @@ class _ConnectionFairy(object):
     _logger = property(lambda self: self._pool.logger)
     
     is_valid = property(lambda self:self.connection is not None)
-
+    
     def _get_properties(self):
         """A property collection unique to this DB-API connection."""
         
index b11065933af78f385c0aebace779a483b602edad..f1fb99316bde8337289b1d654140cf9d6fa6a8ce 100644 (file)
@@ -249,36 +249,36 @@ class TransactionTest(PersistTest):
     @testing.exclude('mysql', '<', (5, 0, 3))
     def testmixedtwophasetransaction(self):
         connection = testbase.db.connect()
-        
+    
         transaction = connection.begin_twophase()
         connection.execute(users.insert(), user_id=1, user_name='user1')
-        
+    
         transaction2 = connection.begin()
         connection.execute(users.insert(), user_id=2, user_name='user2')
-        
+    
         transaction3 = connection.begin_nested()
         connection.execute(users.insert(), user_id=3, user_name='user3')
-        
+    
         transaction4 = connection.begin()
         connection.execute(users.insert(), user_id=4, user_name='user4')
         transaction4.commit()
-        
+    
         transaction3.rollback()
-        
+    
         connection.execute(users.insert(), user_id=5, user_name='user5')
-        
+    
         transaction2.commit()
-        
+    
         transaction.prepare()
-        
+    
         transaction.commit()
-        
+    
         self.assertEquals(
             connection.execute(select([users.c.user_id]).order_by(users.c.user_id)).fetchall(),
             [(1,),(2,),(5,)]
         )
         connection.close()
-        
+            
     @testing.supported('postgres')
     def testtwophaserecover(self):
         # MySQL recovery doesn't currently seem to work correctly