diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2007-12-06 22:23:10 +0000 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2007-12-06 22:23:10 +0000 |
commit | 541b6772e9b8a09b10bd7a16fa9e2b7f693d1194 (patch) | |
tree | 5dc22ca324eafbb6ac48a296f02f166984252d46 /lib/sqlalchemy/sql/compiler.py | |
parent | 3ac9c93e260aa1a5d9c88a648bf7d1213a0e817f (diff) | |
download | sqlalchemy-541b6772e9b8a09b10bd7a16fa9e2b7f693d1194.tar.gz |
- generation of "unique" bind parameters has been simplified to use the same
"unique identifier" mechanisms as everything else. This doesn't affect
user code, except any code that might have been hardcoded against the generated
names. Generated bind params now have the form "<paramname>_<num>",
whereas before only the second bind of the same name would have this form.
- bindparam() objects themselves can be used as keys for execute(), i.e.
statement.execute({bind1:'foo', bind2:'bar'})
Diffstat (limited to 'lib/sqlalchemy/sql/compiler.py')
-rw-r--r-- | lib/sqlalchemy/sql/compiler.py | 29 |
1 files changed, 8 insertions, 21 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)) |