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/expression.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/expression.py')
-rw-r--r-- | lib/sqlalchemy/sql/expression.py | 23 |
1 files changed, 19 insertions, 4 deletions
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 [] |