diff options
| author | Mike Bayer <mike_mp@zzzcomputing.com> | 2010-01-17 20:43:35 +0000 |
|---|---|---|
| committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2010-01-17 20:43:35 +0000 |
| commit | 151fa4e75ce951e42068b3a5785e06a8ecf4dd44 (patch) | |
| tree | 8b3958e357e37192fe4c233fa181e35ccc63096a /lib | |
| parent | 2b1937a31e5b5d8de56f266ec7692a3d0dd90976 (diff) | |
| download | sqlalchemy-151fa4e75ce951e42068b3a5785e06a8ecf4dd44.tar.gz | |
statement_options -> execution_options
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/sqlalchemy/dialects/postgresql/psycopg2.py | 8 | ||||
| -rw-r--r-- | lib/sqlalchemy/engine/default.py | 4 | ||||
| -rw-r--r-- | lib/sqlalchemy/orm/query.py | 26 | ||||
| -rw-r--r-- | lib/sqlalchemy/sql/expression.py | 62 |
4 files changed, 52 insertions, 48 deletions
diff --git a/lib/sqlalchemy/dialects/postgresql/psycopg2.py b/lib/sqlalchemy/dialects/postgresql/psycopg2.py index 7733aadcd..54283581d 100644 --- a/lib/sqlalchemy/dialects/postgresql/psycopg2.py +++ b/lib/sqlalchemy/dialects/postgresql/psycopg2.py @@ -35,10 +35,10 @@ Transactions The psycopg2 dialect fully supports SAVEPOINT and two-phase commit operations. -Statement options ------------------ +Per-Statement Execution Options +------------------------------- -The following statement options are respected: +The following per-statement execution options are respected: * *stream_results* - Enable or disable usage of server side cursors for the SELECT-statement. If *None* or not set, the *server_side_cursors* option of the connection is used. If @@ -112,7 +112,7 @@ 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.statement_options.get('stream_results') + stream_results_option = self.execution_options.get('stream_results') is_server_side = ( # Enabled for this statement ... (stream_results_option or diff --git a/lib/sqlalchemy/engine/default.py b/lib/sqlalchemy/engine/default.py index baa92b5d4..5d37741bd 100644 --- a/lib/sqlalchemy/engine/default.py +++ b/lib/sqlalchemy/engine/default.py @@ -223,7 +223,7 @@ class DefaultDialect(base.Dialect): class DefaultExecutionContext(base.ExecutionContext): - statement_options = util.frozendict() + execution_options = util.frozendict() def __init__(self, dialect, connection, compiled_sql=None, compiled_ddl=None, statement=None, parameters=None): self.dialect = dialect @@ -269,7 +269,7 @@ class DefaultExecutionContext(base.ExecutionContext): self.isupdate = compiled.isupdate self.isdelete = compiled.isdelete self.should_autocommit = compiled.statement._autocommit - self.statement_options = compiled.statement._statement_options + self.execution_options = compiled.statement._execution_options if self.should_autocommit is expression.PARSE_AUTOCOMMIT: self.should_autocommit = self.should_autocommit_text(self.statement) diff --git a/lib/sqlalchemy/orm/query.py b/lib/sqlalchemy/orm/query.py index 444ad37bc..0a7a738c8 100644 --- a/lib/sqlalchemy/orm/query.py +++ b/lib/sqlalchemy/orm/query.py @@ -80,7 +80,7 @@ class Query(object): _filter_aliases = None _from_obj_alias = None _joinpath = _joinpoint = util.frozendict() - _statement_options = util.frozendict() + _execution_options = util.frozendict() _params = util.frozendict() _attributes = util.frozendict() _with_options = () @@ -490,14 +490,14 @@ class Query(object): Also note that many DBAPIs do not "stream" results, pre-buffering all rows before making them available, including mysql-python and - psycopg2. yield_per() will also set the ``stream_results`` statement + psycopg2. yield_per() will also set the ``stream_results`` execution option to ``True``, which currently is only understood by psycopg2 and causes server side cursors to be used. """ self._yield_per = count - self._statement_options = self._statement_options.copy() - self._statement_options['stream_results'] = True + self._execution_options = self._execution_options.copy() + self._execution_options['stream_results'] = True def get(self, ident): """Return an instance of the object based on the given identifier, or None if not found. @@ -676,19 +676,21 @@ class Query(object): opt.process_query(self) @_generative() - def statement_options(self, **kwargs): - """ Set non-SQL options for the resulting statement, such as dialect-specific options. + def execution_options(self, **kwargs): + """ Set non-SQL options for the resulting statement, + such as dialect-specific options. The only option currently understood is ``stream_results=True``, only used by Psycopg2 to enable "server side cursors". This option - only has a useful effect if used in conjunction with :meth:`~sqlalchemy.orm.query.Query.yield_per()`, + only has a useful effect if used in conjunction with + :meth:`~sqlalchemy.orm.query.Query.yield_per()`, which currently sets ``stream_results`` to ``True`` automatically. """ - _statement_options = self._statement_options.copy() + _execution_options = self._execution_options.copy() for key, value in kwargs.items(): - _statement_options[key] = value - self._statement_options = _statement_options + _execution_options[key] = value + self._execution_options = _execution_options @_generative() def with_lockmode(self, mode): @@ -1938,7 +1940,7 @@ class Query(object): context.adapter = sql_util.ColumnAdapter(inner, equivs) - statement = sql.select([inner] + context.secondary_columns, for_update=for_update, use_labels=labels, statement_options=self._statement_options) + statement = sql.select([inner] + context.secondary_columns, for_update=for_update, use_labels=labels, execution_options=self._execution_options) from_clause = inner for eager_join in eager_joins: @@ -1970,7 +1972,7 @@ class Query(object): for_update=for_update, correlate=False, order_by=context.order_by, - statement_options=self._statement_options, + execution_options=self._execution_options, **self._select_args ) diff --git a/lib/sqlalchemy/sql/expression.py b/lib/sqlalchemy/sql/expression.py index 2dc13ee82..26338359a 100644 --- a/lib/sqlalchemy/sql/expression.py +++ b/lib/sqlalchemy/sql/expression.py @@ -977,6 +977,15 @@ def _corresponding_column_or_error(fromclause, column, require_embedded=False): ) return c +@util.decorator +def _generative(fn, *args, **kw): + """Mark a method as generative.""" + + self = args[0]._generate() + fn(self, *args[1:], **kw) + return self + + def is_column(col): """True if ``col`` is an instance of :class:`ColumnElement`.""" @@ -2182,7 +2191,20 @@ class _Executable(object): """Mark a ClauseElement as supporting execution.""" supports_execution = True - _statement_options = util.frozendict() + _execution_options = util.frozendict() + + @_generative + def execution_options(self, **kwargs): + """ Set non-SQL options for the statement, such as dialect-specific options. + + The options available are covered in the respective dialect's section. + + """ + _execution_options = self._execution_options.copy() + for key, value in kwargs.items(): + _execution_options[key] = value + self._execution_options = _execution_options + class _TextClause(_Executable, ClauseElement): """Represent a literal SQL text fragment. @@ -2202,14 +2224,14 @@ class _TextClause(_Executable, ClauseElement): _hide_froms = [] def __init__(self, text = "", bind=None, - bindparams=None, typemap=None, autocommit=PARSE_AUTOCOMMIT, statement_options=None): + bindparams=None, typemap=None, autocommit=PARSE_AUTOCOMMIT, execution_options=None): self._bind = bind self.bindparams = {} self.typemap = typemap self._autocommit = autocommit - self._statement_options = statement_options - if self._statement_options is None: - self._statement_options = {} + self._execution_options = execution_options + if self._execution_options is None: + self._execution_options = {} if typemap is not None: for key in typemap.keys(): typemap[key] = sqltypes.to_instance(typemap[key]) @@ -2799,7 +2821,7 @@ class Alias(FromClause): self.supports_execution = baseselectable.supports_execution if self.supports_execution: self._autocommit = baseselectable._autocommit - self._statement_options = baseselectable._statement_options + self._execution_options = baseselectable._execution_options self.element = selectable if alias is None: if self.original.named_with_column: @@ -3160,14 +3182,6 @@ class TableClause(_Immutable, FromClause): def _from_objects(self): return [self] -@util.decorator -def _generative(fn, *args, **kw): - """Mark a method as generative.""" - - self = args[0]._generate() - fn(self, *args[1:], **kw) - return self - class _SelectBaseMixin(_Executable): """Base class for :class:`Select` and ``CompoundSelects``.""" @@ -3180,16 +3194,16 @@ class _SelectBaseMixin(_Executable): group_by=None, bind=None, autocommit=False, - statement_options=None): + execution_options=None): self.use_labels = use_labels self.for_update = for_update self._autocommit = autocommit self._limit = limit self._offset = offset self._bind = bind - self._statement_options = statement_options - if self._statement_options is None: - self._statement_options = dict() + self._execution_options = execution_options + if self._execution_options is None: + self._execution_options = dict() self._order_by_clause = ClauseList(*util.to_list(order_by) or []) self._group_by_clause = ClauseList(*util.to_list(group_by) or []) @@ -3301,18 +3315,6 @@ class _SelectBaseMixin(_Executable): def _from_objects(self): return [self] - @_generative - def statement_options(self, **kwargs): - """ Set non-SQL options for the statement, such as dialect-specific options. - - The options available are covered in the respective dialect's section. - - """ - _statement_options = self._statement_options.copy() - for key, value in kwargs.items(): - _statement_options[key] = value - self._statement_options = _statement_options - class _ScalarSelect(_Grouping): _from_objects = [] |
