diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2010-08-08 17:50:44 -0400 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2010-08-08 17:50:44 -0400 |
commit | bb5a85feca1a6ed1aa7d18a04c0dfff3afa306c1 (patch) | |
tree | 12d6f26d360310bfa8b718e0876eff8eedd42c11 /lib/sqlalchemy/engine/base.py | |
parent | 0b9afe1412898ba31282e75d90ca4d728613ca2b (diff) | |
parent | bb3be98d3bee4b2bcef791be022ddb2510b9cf9c (diff) | |
download | sqlalchemy-bb5a85feca1a6ed1aa7d18a04c0dfff3afa306c1.tar.gz |
merge tip
Diffstat (limited to 'lib/sqlalchemy/engine/base.py')
-rw-r--r-- | lib/sqlalchemy/engine/base.py | 38 |
1 files changed, 30 insertions, 8 deletions
diff --git a/lib/sqlalchemy/engine/base.py b/lib/sqlalchemy/engine/base.py index 8533e19fc..4260e923a 100644 --- a/lib/sqlalchemy/engine/base.py +++ b/lib/sqlalchemy/engine/base.py @@ -908,7 +908,7 @@ class Connection(Connectable): self.__connection = self.engine.raw_connection() self.__invalid = False return self.__connection - raise exc.InvalidRequestError("This Connection is closed") + raise exc.ResourceClosedError("This Connection is closed") @property def info(self): @@ -956,7 +956,7 @@ class Connection(Connectable): """ if self.closed: - raise exc.InvalidRequestError("This Connection is closed") + raise exc.ResourceClosedError("This Connection is closed") if self.__connection.is_valid: self.__connection.invalidate(exception) @@ -2359,7 +2359,9 @@ class ResultProxy(object): if _autoclose_connection and \ self.connection.should_close_with_result: self.connection.close() - + # allow consistent errors + self.cursor = None + def __iter__(self): while True: row = self.fetchone() @@ -2441,14 +2443,32 @@ class ResultProxy(object): return self.dialect.supports_sane_multi_rowcount def _fetchone_impl(self): - return self.cursor.fetchone() + try: + return self.cursor.fetchone() + except AttributeError: + self._non_result() def _fetchmany_impl(self, size=None): - return self.cursor.fetchmany(size) + try: + return self.cursor.fetchmany(size) + except AttributeError: + self._non_result() def _fetchall_impl(self): - return self.cursor.fetchall() - + try: + return self.cursor.fetchall() + except AttributeError: + self._non_result() + + def _non_result(self): + if self._metadata is None: + raise exc.ResourceClosedError( + "This result object does not return rows. " + "It has been closed automatically.", + ) + else: + raise exc.ResourceClosedError("This result object is closed.") + def process_rows(self, rows): process_row = self._process_row metadata = self._metadata @@ -2505,7 +2525,6 @@ class ResultProxy(object): Else the cursor is automatically closed and None is returned. """ - try: row = self._fetchone_impl() if row is not None: @@ -2525,6 +2544,9 @@ class ResultProxy(object): Returns None if no row is present. """ + if self._metadata is None: + self._non_result() + try: row = self._fetchone_impl() except Exception, e: |