diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2010-01-29 02:01:11 +0000 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2010-01-29 02:01:11 +0000 |
commit | a04c4dc42cf4c3c35163b59a78f05efe47547dc0 (patch) | |
tree | 4d21f99e6d5ada6c701ea77e824163482f818896 /lib/sqlalchemy/dialects/postgresql/psycopg2.py | |
parent | e78cee66186b8851a5018e32f6935ca72be0cf7e (diff) | |
download | sqlalchemy-a04c4dc42cf4c3c35163b59a78f05efe47547dc0.tar.gz |
- inline some code and turn some instance-level defaults into class level
Diffstat (limited to 'lib/sqlalchemy/dialects/postgresql/psycopg2.py')
-rw-r--r-- | lib/sqlalchemy/dialects/postgresql/psycopg2.py | 30 |
1 files changed, 14 insertions, 16 deletions
diff --git a/lib/sqlalchemy/dialects/postgresql/psycopg2.py b/lib/sqlalchemy/dialects/postgresql/psycopg2.py index 54283581d..bb6562dea 100644 --- a/lib/sqlalchemy/dialects/postgresql/psycopg2.py +++ b/lib/sqlalchemy/dialects/postgresql/psycopg2.py @@ -112,22 +112,20 @@ SERVER_SIDE_CURSOR_RE = re.compile( class PostgreSQL_psycopg2ExecutionContext(PGExecutionContext): def create_cursor(self): # TODO: coverage for server side cursors + select.for_update() - stream_results_option = self.execution_options.get('stream_results') - is_server_side = ( - # Enabled for this statement ... - (stream_results_option or - # ... or enabled for all statements - (self.dialect.server_side_cursors and - # ... and not explicitly disabled for this one. - (stream_results_option or stream_results_option is None)) - ) and ( - # But don't use SS-cursors when autocommit is on ... - (not self.should_autocommit and - self.compiled and isinstance(self.compiled.statement, expression.Selectable)) - or ( - # ... or if it's not even a SELECT. - (not self.compiled or isinstance(self.compiled.statement, expression._TextClause)) - and self.statement and SERVER_SIDE_CURSOR_RE.match(self.statement)))) + + if self.dialect.server_side_cursors: + is_server_side = \ + self.execution_options.get('stream_results', True) and ( + (self.compiled and isinstance(self.compiled.statement, expression.Selectable) \ + or \ + ( + (not self.compiled or + isinstance(self.compiled.statement, expression._TextClause)) + and self.statement and SERVER_SIDE_CURSOR_RE.match(self.statement)) + ) + ) + else: + is_server_side = self.execution_options.get('stream_results', False) self.__is_server_side = is_server_side if is_server_side: |