diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2013-01-08 10:04:55 -0500 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2013-01-08 10:04:55 -0500 |
commit | ac1ee45fcc749de4d75283f0b343be4b4c6c31ff (patch) | |
tree | 34b2e0d83bfbc97ac963829f14ee33c4e44f7b7d /lib/sqlalchemy/sql/compiler.py | |
parent | 0755114f75dc765c5f7c61483323338ef477dd14 (diff) | |
download | sqlalchemy-ac1ee45fcc749de4d75283f0b343be4b4c6c31ff.tar.gz |
Tweaked the "REQUIRED" symbol used by the compiler to identify
INSERT/UPDATE bound parameters that need to be passed, so that
it's more easily identifiable when writing custom bind-handling
code. [ticket:2648]
Diffstat (limited to 'lib/sqlalchemy/sql/compiler.py')
-rw-r--r-- | lib/sqlalchemy/sql/compiler.py | 19 |
1 files changed, 14 insertions, 5 deletions
diff --git a/lib/sqlalchemy/sql/compiler.py b/lib/sqlalchemy/sql/compiler.py index ce3ecad60..127de1dfa 100644 --- a/lib/sqlalchemy/sql/compiler.py +++ b/lib/sqlalchemy/sql/compiler.py @@ -64,6 +64,17 @@ BIND_TEMPLATES = { 'named': ":%(name)s" } +REQUIRED = util.symbol('REQUIRED', """ +Placeholder for the value within a :class:`.BindParameter` +which is required to be present when the statement is passed +to :meth:`.Connection.execute`. + +This symbol is typically used when a :func:`.expression.insert` +or :func:`.expression.update` statement is compiled without parameter +values present. + +""") + OPERATORS = { # binary @@ -1496,8 +1507,6 @@ class SQLCompiler(engine.Compiled): for c in stmt.table.columns ] - required = object() - if stmt._has_multi_parameters: stmt_parameters = stmt.parameters[0] else: @@ -1508,7 +1517,7 @@ class SQLCompiler(engine.Compiled): if self.column_keys is None: parameters = {} else: - parameters = dict((sql._column_as_key(key), required) + parameters = dict((sql._column_as_key(key), REQUIRED) for key in self.column_keys if not stmt_parameters or key not in stmt_parameters) @@ -1560,7 +1569,7 @@ class SQLCompiler(engine.Compiled): value = normalized_params[c] if sql._is_literal(value): value = self._create_crud_bind_param( - c, value, required=value is required) + c, value, required=value is REQUIRED) else: self.postfetch.append(c) value = self.process(value.self_group()) @@ -1594,7 +1603,7 @@ class SQLCompiler(engine.Compiled): value = parameters.pop(c.key) if sql._is_literal(value): value = self._create_crud_bind_param( - c, value, required=value is required, + c, value, required=value is REQUIRED, name=c.key if not stmt._has_multi_parameters else "%s_0" % c.key |