From: Mike Bayer Date: Thu, 28 Jan 2010 23:49:22 +0000 (+0000) Subject: - the "autocommit" flag on select() and text() as well X-Git-Tag: rel_0_6beta1~14 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=e78cee66186b8851a5018e32f6935ca72be0cf7e;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git - the "autocommit" flag on select() and text() as well as select().autocommit() are deprecated - now call .execution_options(autocommit=True) on either of those constructs, also available directly on Connection and orm.Query. --- diff --git a/CHANGES b/CHANGES index f8ebfbb41b..aef444c38a 100644 --- a/CHANGES +++ b/CHANGES @@ -240,6 +240,12 @@ CHANGES Use the 'bind' keyword argument. - sql + + - the "autocommit" flag on select() and text() as well + as select().autocommit() are deprecated - now call + .execution_options(autocommit=True) on either of those + constructs, also available directly on Connection and orm.Query. + - the autoincrement flag on column now indicates the column which should be linked to cursor.lastrowid, if that method is used. See the API docs for details. @@ -349,14 +355,16 @@ CHANGES - transaction isolation level may be specified with create_engine(... isolation_level="..."); available on postgresql and sqlite. [ticket:443] - + - Connection has execution_options(), generative method which accepts keywords that affect how the statement is executed w.r.t. the DBAPI. Currently supports "stream_results", causes psycopg2 to use a server - side cursor for that statement. Can also be set - upon select() and text() constructs directly as well - as ORM Query(). + side cursor for that statement, as well as + "autocommit", which is the new location for the "autocommit" + option from select() and text(). select() and + text() also have .execution_options() as well as + ORM Query(). - fixed the import for entrypoint-driven dialects to not rely upon silly tb_info trick to determine import diff --git a/lib/sqlalchemy/engine/default.py b/lib/sqlalchemy/engine/default.py index e168a54655..e2a03d2276 100644 --- a/lib/sqlalchemy/engine/default.py +++ b/lib/sqlalchemy/engine/default.py @@ -229,7 +229,6 @@ class DefaultExecutionContext(base.ExecutionContext): self.dialect = dialect self._connection = self.root_connection = connection self.engine = connection.engine - self.execution_options = connection._execution_options if compiled_ddl is not None: self.compiled = compiled = compiled_ddl @@ -268,9 +267,6 @@ class DefaultExecutionContext(base.ExecutionContext): self.isinsert = compiled.isinsert self.isupdate = compiled.isupdate self.isdelete = compiled.isdelete - if compiled.statement._execution_options: - self.execution_options =\ - compiled.statement._execution_options.union(self.execution_options) if not parameters: self.compiled_parameters = [compiled.construct_params()] @@ -301,18 +297,24 @@ class DefaultExecutionContext(base.ExecutionContext): self.cursor = self.create_cursor() @util.memoized_property - def should_autocommit(self): + def execution_options(self): if self.compiled: - autocommit = self.compiled.statement._autocommit - if autocommit is expression.PARSE_AUTOCOMMIT: + return self.compiled.statement._execution_options.union( + self._connection._execution_options) + else: + return self._connection._execution_options + + @util.memoized_property + def should_autocommit(self): + autocommit = self.execution_options.get('autocommit', expression.PARSE_AUTOCOMMIT) + if autocommit is expression.PARSE_AUTOCOMMIT: + if self.statement: return self.should_autocommit_text(self.statement) else: - return autocommit - elif self.statement: - return self.should_autocommit_text(self.statement) + return False else: - return False + return autocommit @util.memoized_property def _is_explicit_returning(self): diff --git a/lib/sqlalchemy/schema.py b/lib/sqlalchemy/schema.py index f2737ecde5..cd9bd48921 100644 --- a/lib/sqlalchemy/schema.py +++ b/lib/sqlalchemy/schema.py @@ -2035,7 +2035,8 @@ class SchemaVisitor(visitors.ClauseVisitor): class DDLElement(expression._Executable, expression.ClauseElement): """Base class for DDL expression constructs.""" - _autocommit = True + _execution_options = expression._Executable.\ + _execution_options.union({'autocommit':True}) target = None on = None diff --git a/lib/sqlalchemy/sql/expression.py b/lib/sqlalchemy/sql/expression.py index a4504e8330..5edb6e47fe 100644 --- a/lib/sqlalchemy/sql/expression.py +++ b/lib/sqlalchemy/sql/expression.py @@ -164,9 +164,8 @@ def select(columns=None, whereclause=None, from_obj=[], **kwargs): Additional parameters include: autocommit - indicates this SELECT statement modifies the database, and - should be subject to autocommit behavior if no transaction - has been started. + Deprecated. Use .execution_options(autocommit=) + to set the autocommit option. prefixes a list of strings or :class:`ClauseElement` objects to include @@ -805,9 +804,8 @@ def text(text, bind=None, *args, **kwargs): an optional connection or engine to be used for this text query. autocommit=True - indicates this SELECT statement modifies the database, and - should be subject to autocommit behavior if no transaction - has been started. + Deprecated. Use .execution_options(autocommit=) + to set the autocommit option. bindparams a list of :func:`bindparam()` instances which can be used to define @@ -2215,9 +2213,26 @@ class _Executable(object): @_generative def execution_options(self, **kw): - """ Set non-SQL options for the statement, such as dialect-specific options. - - The options available are covered in the respective dialect's section. + """ Set non-SQL options for the statement which take effect during execution. + + Current options include: + + * autocommit - when True, a COMMIT will be invoked after execution + when executed in 'autocommit' mode, i.e. when an explicit transaction + is not begun on the connection. Note that DBAPI connections by + default are always in a transaction - SQLAlchemy uses rules applied + to different kinds of statements to determine if COMMIT will be invoked + in order to provide its "autocommit" feature. Typically, all + INSERT/UPDATE/DELETE statements as well as CREATE/DROP statements + have autocommit behavior enabled; SELECT constructs do not. Use this + option when invokving a SELECT or other specific SQL construct + where COMMIT is desired (typically when calling stored procedures + and such). + + * stream_results - indicate to the dialect that results should be + "streamed" and not pre-buffered, if possible. This is a limitation + of many DBAPIs. The flag is currently understood only by the + psycopg2 dialect. """ self._execution_options = self._execution_options.union(kw) @@ -2233,7 +2248,8 @@ class _TextClause(_Executable, ClauseElement): __visit_name__ = 'textclause' _bind_params_regex = re.compile(r'(?