diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2005-09-24 07:06:41 +0000 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2005-09-24 07:06:41 +0000 |
commit | 2f2498c4ef2262335b2925b07b6826b7f38458c2 (patch) | |
tree | 504d67227a2bd044d53b9ecb5139832734640c4b /lib/sqlalchemy/sql.py | |
parent | 35f336867a6ebb0af159afd4923460f362c75978 (diff) | |
download | sqlalchemy-2f2498c4ef2262335b2925b07b6826b7f38458c2.tar.gz |
Diffstat (limited to 'lib/sqlalchemy/sql.py')
-rw-r--r-- | lib/sqlalchemy/sql.py | 19 |
1 files changed, 8 insertions, 11 deletions
diff --git a/lib/sqlalchemy/sql.py b/lib/sqlalchemy/sql.py index 671c59c67..3887c63b5 100644 --- a/lib/sqlalchemy/sql.py +++ b/lib/sqlalchemy/sql.py @@ -115,8 +115,8 @@ def alias(*args, **params): def subquery(alias, *args, **params): return Alias(Select(*args, **params), alias) -def bindparam(key, value = None): - return BindParamClause(key, value) +def bindparam(key, value = None, type=None): + return BindParamClause(key, value, type=type) def text(text): return TextClause(text) @@ -183,7 +183,7 @@ class Compiled(ClauseVisitor): params = [self.get_params(**m) for m in multiparams] else: params = self.get_params(**params) - return self.engine.execute(str(self), params, compiled = self) + return self.engine.execute(str(self), params, compiled = self, typemap = self.typemap) class ClauseElement(object): """base class for elements of a programmatically constructed SQL expression. @@ -297,7 +297,7 @@ class BindParamClause(ClauseElement): self.key = key self.value = value self.shortname = shortname - self.type = type + self.type = type or types.NULLTYPE def accept_visitor(self, visitor): visitor.visit_bindparam(self) @@ -309,10 +309,7 @@ class BindParamClause(ClauseElement): return "BindParam(%s, %s, %s)" % (repr(self.key), repr(self.value), repr(self.shortname)) def typeprocess(self, value): - if self.type is not None: - return self.type.convert_bind_param(value) - else: - return value + return self.type.convert_bind_param(value) class TextClause(ClauseElement): """represents any plain text WHERE clause or full SQL statement""" @@ -768,7 +765,7 @@ class UpdateBase(ClauseElement): else: col = key try: - parameters[key] = bindparam(col.name, value) + parameters[key] = bindparam(col.name, value, type=col.type) except KeyError: del parameters[key] return parameters @@ -777,7 +774,7 @@ class UpdateBase(ClauseElement): # case one: no parameters in the statement, no parameters in the # compiled params - just return binds for all the table columns if parameters is None and self.parameters is None: - return [(c, bindparam(c.name)) for c in self.table.columns] + return [(c, bindparam(c.name, type=c.type)) for c in self.table.columns] # if we have statement parameters - set defaults in the # compiled params @@ -807,7 +804,7 @@ class UpdateBase(ClauseElement): if d.has_key(c): value = d[c] if _is_literal(value): - value = bindparam(c.name, value) + value = bindparam(c.name, value, type=c.type) values.append((c, value)) return values |