diff options
Diffstat (limited to 'lib/sqlalchemy/sql')
| -rw-r--r-- | lib/sqlalchemy/sql/compiler.py | 29 | ||||
| -rw-r--r-- | lib/sqlalchemy/sql/expression.py | 23 |
2 files changed, 27 insertions, 25 deletions
diff --git a/lib/sqlalchemy/sql/compiler.py b/lib/sqlalchemy/sql/compiler.py index 749ce4c10..aec75e76c 100644 --- a/lib/sqlalchemy/sql/compiler.py +++ b/lib/sqlalchemy/sql/compiler.py @@ -196,7 +196,7 @@ class DefaultCompiler(engine.Compiled): if params: pd = {} for bindparam, name in self.bind_names.iteritems(): - for paramname in (bindparam.key, bindparam.shortname, name): + for paramname in (bindparam, bindparam.key, bindparam.shortname, name): if paramname in params: pd[name] = params[paramname] break @@ -373,26 +373,13 @@ class DefaultCompiler(engine.Compiled): return self.operators.get(operator, str(operator)) def visit_bindparam(self, bindparam, **kwargs): - # TODO: remove this whole "unique" thing, just use regular - # anonymous params to implement. params used for inserts/updates - # etc. should no longer be "unique". - if bindparam.unique: - count = 1 - key = bindparam.key - # redefine the generated name of the bind param in the case - # that we have multiple conflicting bind parameters. - while self.binds.setdefault(key, bindparam) is not bindparam: - tag = "_%d" % count - key = bindparam.key + tag - count += 1 - bindparam.key = key - return self.bindparam_string(self._truncate_bindparam(bindparam)) - else: - existing = self.binds.get(bindparam.key) - if existing is not None and existing.unique: + name = self._truncate_bindparam(bindparam) + if name in self.binds: + existing = self.binds[name] + if existing.unique or bindparam.unique: raise exceptions.CompileError("Bind parameter '%s' conflicts with unique bind parameter of the same name" % bindparam.key) - self.binds[bindparam.key] = bindparam - return self.bindparam_string(self._truncate_bindparam(bindparam)) + self.binds[bindparam.key] = self.binds[name] = bindparam + return self.bindparam_string(name) def _truncate_bindparam(self, bindparam): if bindparam in self.bind_names: @@ -632,7 +619,7 @@ class DefaultCompiler(engine.Compiled): """ def create_bind_param(col, value): - bindparam = sql.bindparam(col.key, value, type_=col.type, unique=True) + bindparam = sql.bindparam(col.key, value, type_=col.type) self.binds[col.key] = bindparam return self.bindparam_string(self._truncate_bindparam(bindparam)) diff --git a/lib/sqlalchemy/sql/expression.py b/lib/sqlalchemy/sql/expression.py index 6ad29218f..732d4fdf9 100644 --- a/lib/sqlalchemy/sql/expression.py +++ b/lib/sqlalchemy/sql/expression.py @@ -922,7 +922,7 @@ class ClauseElement(object): if bind.key in kwargs: bind.value = kwargs[bind.key] if unique: - bind.unique=True + bind._convert_to_unique() return Vis().traverse(self, clone=True) def compare(self, other): @@ -1749,10 +1749,14 @@ class _BindParamClause(ClauseElement, _CompareMixin): if True, the parameter should be treated like a stored procedure "OUT" parameter. """ - - self.key = key or "{ANON %d param}" % id(self) - self.value = value + + if unique: + self.key = "{ANON %d %s}" % (id(self), key or 'param') + else: + self.key = key or "{ANON %d param}" % id(self) + self._orig_key = key self.unique = unique + self.value = value self.isoutparam = isoutparam self.shortname = shortname @@ -1778,6 +1782,17 @@ class _BindParamClause(ClauseElement, _CompareMixin): type(None):sqltypes.NullType } + def _clone(self): + c = ClauseElement._clone(self) + if self.unique: + c.key = "{ANON %d %s}" % (id(c), c._orig_key or 'param') + return c + + def _convert_to_unique(self): + if not self.unique: + self.unique=True + self.key = "{ANON %d %s}" % (id(self), self._orig_key or 'param') + def _get_from_objects(self, **modifiers): return [] |
