diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2010-12-19 22:48:39 -0500 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2010-12-19 22:48:39 -0500 |
commit | d8c5474db69c16a15e0e3a5b3da6d2703aa4d236 (patch) | |
tree | 3718ceb2ed544638e712cb6c5b4ef3371ca8fbaa /lib/sqlalchemy/engine/base.py | |
parent | fb6ad4c450e33a4c7b4774ffd058be519f0c9689 (diff) | |
download | sqlalchemy-d8c5474db69c16a15e0e3a5b3da6d2703aa4d236.tar.gz |
more inlines
Diffstat (limited to 'lib/sqlalchemy/engine/base.py')
-rw-r--r-- | lib/sqlalchemy/engine/base.py | 37 |
1 files changed, 25 insertions, 12 deletions
diff --git a/lib/sqlalchemy/engine/base.py b/lib/sqlalchemy/engine/base.py index f3f32f833..4e11117f7 100644 --- a/lib/sqlalchemy/engine/base.py +++ b/lib/sqlalchemy/engine/base.py @@ -889,16 +889,19 @@ class Connection(Connectable): try: return self.__connection except AttributeError: - if self.__invalid: - if self.__transaction is not None: - raise exc.InvalidRequestError( - "Can't reconnect until invalid " - "transaction is rolled back") - self.__connection = self.engine.raw_connection() - self.__invalid = False - return self.__connection - raise exc.ResourceClosedError("This Connection is closed") - + return self._revalidate_connection() + + def _revalidate_connection(self): + if self.__invalid: + if self.__transaction is not None: + raise exc.InvalidRequestError( + "Can't reconnect until invalid " + "transaction is rolled back") + self.__connection = self.engine.raw_connection() + self.__invalid = False + return self.__connection + raise exc.ResourceClosedError("This Connection is closed") + @property def _connection_is_valid(self): # use getattr() for is_valid to support exceptions raised in @@ -1214,9 +1217,14 @@ class Connection(Connectable): """Execute a schema.ColumnDefault object.""" try: + try: + conn = self.__connection + except AttributeError: + conn = self._revalidate_connection() + dialect = self.dialect ctx = dialect.execution_ctx_cls._init_default( - dialect, self) + dialect, self, conn) except Exception, e: self._handle_dbapi_exception(e, None, None, None, None) raise @@ -1306,7 +1314,12 @@ class Connection(Connectable): a :class:`.ResultProxy`.""" try: - context = constructor(dialect, self, *args) + try: + conn = self.__connection + except AttributeError: + conn = self._revalidate_connection() + + context = constructor(dialect, self, conn, *args) except Exception, e: self._handle_dbapi_exception(e, statement, parameters, |