From: Mike Bayer Date: Thu, 31 Jan 2008 17:48:22 +0000 (+0000) Subject: - added "autocommit=True" kwarg to select() and text(), X-Git-Tag: rel_0_4_3~57 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=e1aa7573f210f76e2ddf8e45fc18007e11e5bbef;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git - added "autocommit=True" kwarg to select() and text(), as well as generative autocommit() method on select(); for statements which modify the database through some user-defined means other than the usual INSERT/UPDATE/ DELETE etc., this flag will enable "autocommit" behavior during execution if no transaction is in progress [ticket:915] --- diff --git a/CHANGES b/CHANGES index 97f480eb9f..5ef21fa246 100644 --- a/CHANGES +++ b/CHANGES @@ -16,6 +16,14 @@ CHANGES - cast() accepts text('something') and other non-literal operands properly [ticket:962] + + - added "autocommit=True" kwarg to select() and text(), + as well as generative autocommit() method on select(); + for statements which modify the database through some + user-defined means other than the usual INSERT/UPDATE/ + DELETE etc., this flag will enable "autocommit" behavior + during execution if no transaction is in progress + [ticket:915] - The '.c.' attribute on a selectable now gets an entry for every column expression in its columns clause. diff --git a/lib/sqlalchemy/engine/default.py b/lib/sqlalchemy/engine/default.py index e78eedd5c8..3b93862aeb 100644 --- a/lib/sqlalchemy/engine/default.py +++ b/lib/sqlalchemy/engine/default.py @@ -164,10 +164,10 @@ class DefaultExecutionContext(base.ExecutionContext): self.isupdate = compiled.isupdate if isinstance(compiled.statement, expression._TextClause): self.returns_rows = self.returns_rows_text(self.statement) - self.should_autocommit = self.should_autocommit_text(self.statement) + self.should_autocommit = compiled.statement._autocommit or self.should_autocommit_text(self.statement) else: self.returns_rows = self.returns_rows_compiled(compiled) - self.should_autocommit = self.should_autocommit_compiled(compiled) + self.should_autocommit = getattr(compiled.statement, '_autocommit', False) or self.should_autocommit_compiled(compiled) if not parameters: self.compiled_parameters = [compiled.construct_params()] diff --git a/lib/sqlalchemy/sql/expression.py b/lib/sqlalchemy/sql/expression.py index 6c0c4659ec..2e5797b346 100644 --- a/lib/sqlalchemy/sql/expression.py +++ b/lib/sqlalchemy/sql/expression.py @@ -158,6 +158,11 @@ def select(columns=None, whereclause=None, from_obj=[], **kwargs): \**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. + prefixes a list of strings or ``ClauseElement`` objects to include directly after the SELECT keyword in the generated statement, @@ -727,6 +732,11 @@ def text(text, bind=None, *args, **kwargs): bind 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. + bindparams a list of ``bindparam()`` instances which can be used to define the types and/or initial values for the bind parameters within @@ -740,6 +750,7 @@ def text(text, bind=None, *args, **kwargs): which will be used to perform post-processing on columns within the result set (for textual statements that produce result sets). + """ return _TextClause(text, bind=bind, *args, **kwargs) @@ -1821,10 +1832,11 @@ class _TextClause(ClauseElement): _bind_params_regex = re.compile(r'(?