From: Mike Bayer Date: Sat, 27 Oct 2007 18:45:20 +0000 (+0000) Subject: - inlined a couple of context variables X-Git-Tag: rel_0_4_1~104 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=1fee09fd07f6507657d28e542d725c9e7845cc31;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git - inlined a couple of context variables - PG two phase was calling text() without the correct bind param format, previous compiler checkin revealed issue --- diff --git a/lib/sqlalchemy/databases/postgres.py b/lib/sqlalchemy/databases/postgres.py index 6449bdc144..00b297f973 100644 --- a/lib/sqlalchemy/databases/postgres.py +++ b/lib/sqlalchemy/databases/postgres.py @@ -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: diff --git a/lib/sqlalchemy/engine/base.py b/lib/sqlalchemy/engine/base.py index 131f505404..880362938d 100644 --- a/lib/sqlalchemy/engine/base.py +++ b/lib/sqlalchemy/engine/base.py @@ -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 diff --git a/lib/sqlalchemy/engine/default.py b/lib/sqlalchemy/engine/default.py index d826b97fad..c98519ffe8 100644 --- a/lib/sqlalchemy/engine/default.py +++ b/lib/sqlalchemy/engine/default.py @@ -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. diff --git a/lib/sqlalchemy/pool.py b/lib/sqlalchemy/pool.py index a80502df0f..8b3acbec5b 100644 --- a/lib/sqlalchemy/pool.py +++ b/lib/sqlalchemy/pool.py @@ -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.""" diff --git a/test/engine/transaction.py b/test/engine/transaction.py index b11065933a..f1fb99316b 100644 --- a/test/engine/transaction.py +++ b/test/engine/transaction.py @@ -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