diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2011-02-09 15:45:15 -0500 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2011-02-09 15:45:15 -0500 |
commit | 3f30fb065c3b6baa8d7870bb0682d20ad37a62a2 (patch) | |
tree | bd7d8a4663131e60a84b94cf5758ab1a63db591a /lib/sqlalchemy/sql/compiler.py | |
parent | 34f26ee255bf64cf6de6fb9a5f1285b696fa4bbd (diff) | |
download | sqlalchemy-3f30fb065c3b6baa8d7870bb0682d20ad37a62a2.tar.gz |
- The compiler extension now supports overriding the default
compilation of expression._BindParamClause including that
the auto-generated binds within the VALUES/SET clause
of an insert()/update() statement will also use the new
compilation rules. [ticket:2042]
Diffstat (limited to 'lib/sqlalchemy/sql/compiler.py')
-rw-r--r-- | lib/sqlalchemy/sql/compiler.py | 19 |
1 files changed, 6 insertions, 13 deletions
diff --git a/lib/sqlalchemy/sql/compiler.py b/lib/sqlalchemy/sql/compiler.py index d906bf5d4..1ab0ba405 100644 --- a/lib/sqlalchemy/sql/compiler.py +++ b/lib/sqlalchemy/sql/compiler.py @@ -579,8 +579,9 @@ class SQLCompiler(engine.Compiled): else: return fn(" " + operator + " ") - def visit_bindparam(self, bindparam, within_columns_clause=False, + def visit_bindparam(self, bindparam, within_columns_clause=False, literal_binds=False, **kwargs): + if literal_binds or \ (within_columns_clause and \ self.ansi_bind_rules): @@ -591,6 +592,7 @@ class SQLCompiler(engine.Compiled): within_columns_clause=True, **kwargs) name = self._truncate_bindparam(bindparam) + if name in self.binds: existing = self.binds[name] if existing is not bindparam: @@ -600,7 +602,8 @@ class SQLCompiler(engine.Compiled): "unique bind parameter of the same name" % bindparam.key ) - elif getattr(existing, '_is_crud', False): + elif getattr(existing, '_is_crud', False) or \ + getattr(bindparam, '_is_crud', False): raise exc.CompileError( "bindparam() name '%s' is reserved " "for automatic usage in the VALUES or SET " @@ -992,18 +995,8 @@ class SQLCompiler(engine.Compiled): bindparam = sql.bindparam(col.key, value, type_=col.type, required=required) bindparam._is_crud = True - if col.key in self.binds: - raise exc.CompileError( - "bindparam() name '%s' is reserved " - "for automatic usage in the VALUES or SET clause of this " - "insert/update statement. Please use a " - "name other than column name when using bindparam() " - "with insert() or update() (for example, 'b_%s')." - % (col.key, col.key) - ) + return bindparam._compiler_dispatch(self) - self.binds[col.key] = bindparam - return self.bindparam_string(self._truncate_bindparam(bindparam)) def _get_colparams(self, stmt): """create a set of tuples representing column/string pairs for use |