summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/engine/base.py
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2007-08-12 19:37:47 +0000
committerMike Bayer <mike_mp@zzzcomputing.com>2007-08-12 19:37:47 +0000
commit8b004dc7af444cd7f0e5394835b9e2f90a7c9434 (patch)
tree38dde8fad6c64e5137c48b3741268ea7e8a0a1ea /lib/sqlalchemy/engine/base.py
parentd06fba535c39661568a0fc5d8cb731aea7b82b29 (diff)
downloadsqlalchemy-8b004dc7af444cd7f0e5394835b9e2f90a7c9434.tar.gz
added "should_commit()" hook to ExecutionContext. dialects can override with specific tests
Diffstat (limited to 'lib/sqlalchemy/engine/base.py')
-rw-r--r--lib/sqlalchemy/engine/base.py11
1 files changed, 8 insertions, 3 deletions
diff --git a/lib/sqlalchemy/engine/base.py b/lib/sqlalchemy/engine/base.py
index a4e41e996..56a07018b 100644
--- a/lib/sqlalchemy/engine/base.py
+++ b/lib/sqlalchemy/engine/base.py
@@ -373,6 +373,11 @@ class ExecutionContext(object):
raise NotImplementedError()
+ def should_autocommit(self):
+ """return True if this context's statement should be 'committed' automatically in a non-transactional context"""
+
+ raise NotImplementedError()
+
def last_inserted_ids(self):
"""Return the list of the primary key values for the last insert statement executed.
@@ -695,11 +700,11 @@ class Connection(Connectable):
self.__engine.dialect.do_commit_twophase(self, xid, is_prepared)
self.__transaction = None
- def _autocommit(self, statement):
+ def _autocommit(self, context):
"""When no Transaction is present, this is called after executions to provide "autocommit" behavior."""
# TODO: have the dialect determine if autocommit can be set on the connection directly without this
# extra step
- if not self.in_transaction() and re.match(r'UPDATE|INSERT|CREATE|DELETE|DROP|ALTER', statement.lstrip(), re.I):
+ if not self.in_transaction() and context.should_autocommit():
self._commit_impl()
def _autorollback(self):
@@ -782,7 +787,7 @@ class Connection(Connectable):
self.__executemany(context)
else:
self.__execute(context)
- self._autocommit(context.statement)
+ self._autocommit(context)
def __execute(self, context):
if context.parameters is None: