summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/engine/default.py
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2010-01-29 02:01:11 +0000
committerMike Bayer <mike_mp@zzzcomputing.com>2010-01-29 02:01:11 +0000
commita04c4dc42cf4c3c35163b59a78f05efe47547dc0 (patch)
tree4d21f99e6d5ada6c701ea77e824163482f818896 /lib/sqlalchemy/engine/default.py
parente78cee66186b8851a5018e32f6935ca72be0cf7e (diff)
downloadsqlalchemy-a04c4dc42cf4c3c35163b59a78f05efe47547dc0.tar.gz
- inline some code and turn some instance-level defaults into class level
Diffstat (limited to 'lib/sqlalchemy/engine/default.py')
-rw-r--r--lib/sqlalchemy/engine/default.py75
1 files changed, 50 insertions, 25 deletions
diff --git a/lib/sqlalchemy/engine/default.py b/lib/sqlalchemy/engine/default.py
index e2a03d227..44c968942 100644
--- a/lib/sqlalchemy/engine/default.py
+++ b/lib/sqlalchemy/engine/default.py
@@ -224,32 +224,62 @@ class DefaultDialect(base.Dialect):
class DefaultExecutionContext(base.ExecutionContext):
+ execution_options = util.frozendict()
+ isinsert = False
+ isupdate = False
+ isdelete = False
+ executemany = False
+ result_map = None
+ compiled = None
+ statement = None
- def __init__(self, dialect, connection, compiled_sql=None, compiled_ddl=None, statement=None, parameters=None):
+ def __init__(self,
+ dialect,
+ connection,
+ compiled_sql=None,
+ compiled_ddl=None,
+ statement=None,
+ parameters=None):
+
self.dialect = dialect
self._connection = self.root_connection = connection
self.engine = connection.engine
if compiled_ddl is not None:
self.compiled = compiled = compiled_ddl
+
+ if compiled.statement._execution_options:
+ self.execution_options = compiled.statement._execution_options
+ if connection._execution_options:
+ self.execution_options = self.execution_options.union(
+ connection._execution_options
+ )
+
if not dialect.supports_unicode_statements:
self.statement = unicode(compiled).encode(self.dialect.encoding)
else:
self.statement = unicode(compiled)
- self.isinsert = self.isupdate = self.isdelete = self.executemany = False
- self.result_map = None
+
self.cursor = self.create_cursor()
self.compiled_parameters = []
self.parameters = [self._default_params]
+
elif compiled_sql is not None:
self.compiled = compiled = compiled_sql
+ if not compiled.can_execute:
+ raise exc.ArgumentError("Not an executable clause: %s" % compiled)
+
+ if compiled.statement._execution_options:
+ self.execution_options = compiled.statement._execution_options
+ if connection._execution_options:
+ self.execution_options = self.execution_options.union(
+ connection._execution_options
+ )
+
# compiled clauseelement. process bind params, process table defaults,
# track collections used by ResultProxy to target and process results
- if not compiled.can_execute:
- raise exc.ArgumentError("Not an executable clause: %s" % compiled)
-
self.processors = dict(
(key, value) for key, value in
( (compiled.bind_names[bindparam],
@@ -270,9 +300,10 @@ class DefaultExecutionContext(base.ExecutionContext):
if not parameters:
self.compiled_parameters = [compiled.construct_params()]
- self.executemany = False
else:
- self.compiled_parameters = [compiled.construct_params(m, _group_number=grp) for grp,m in enumerate(parameters)]
+ self.compiled_parameters = [compiled.construct_params(m, _group_number=grp) for
+ grp,m in enumerate(parameters)]
+
self.executemany = len(parameters) > 1
self.cursor = self.create_cursor()
@@ -281,38 +312,32 @@ class DefaultExecutionContext(base.ExecutionContext):
self.parameters = self.__convert_compiled_params(self.compiled_parameters)
elif statement is not None:
# plain text statement
- self.result_map = self.compiled = None
+ if connection._execution_options:
+ self.execution_options = self.execution_options.union(connection._execution_options)
self.parameters = self.__encode_param_keys(parameters)
self.executemany = len(parameters) > 1
if isinstance(statement, unicode) and not dialect.supports_unicode_statements:
self.statement = statement.encode(self.dialect.encoding)
else:
self.statement = statement
- self.isinsert = self.isupdate = self.isdelete = False
self.cursor = self.create_cursor()
else:
# no statement. used for standalone ColumnDefault execution.
- self.statement = self.compiled = None
- self.isinsert = self.isupdate = self.isdelete = self.executemany = False
+ if connection._execution_options:
+ self.execution_options = self.execution_options.union(connection._execution_options)
self.cursor = self.create_cursor()
-
- @util.memoized_property
- def execution_options(self):
- if self.compiled:
- 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)
+ autocommit = self.execution_options.get('autocommit',
+ not self.compiled and
+ self.statement and
+ expression.PARSE_AUTOCOMMIT
+ or False)
+
if autocommit is expression.PARSE_AUTOCOMMIT:
- if self.statement:
- return self.should_autocommit_text(self.statement)
- else:
- return False
+ return self.should_autocommit_text(self.statement)
else:
return autocommit