diff options
| author | Mike Bayer <mike_mp@zzzcomputing.com> | 2012-05-04 18:40:55 -0400 |
|---|---|---|
| committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2012-05-04 18:40:55 -0400 |
| commit | c3a0453680d3816ee6de3223d768f45e8a46344d (patch) | |
| tree | 9c6c914e5bc57d8ff71513731f32b34c1fce7401 /lib/sqlalchemy/sql | |
| parent | 03b6a5840e2e0193a21b10f3151c22e50178d9e7 (diff) | |
| download | sqlalchemy-c3a0453680d3816ee6de3223d768f45e8a46344d.tar.gz | |
- [bug] Quoting information is now passed along
from a Column with quote=True when generating
a same-named bound parameter to the bindparam()
object, as is the case in generated INSERT and UPDATE
statements, so that unknown reserved names can
be fully supported. [ticket:2437]
Diffstat (limited to 'lib/sqlalchemy/sql')
| -rw-r--r-- | lib/sqlalchemy/sql/compiler.py | 7 | ||||
| -rw-r--r-- | lib/sqlalchemy/sql/expression.py | 28 |
2 files changed, 24 insertions, 11 deletions
diff --git a/lib/sqlalchemy/sql/compiler.py b/lib/sqlalchemy/sql/compiler.py index a58da176c..05cc70aba 100644 --- a/lib/sqlalchemy/sql/compiler.py +++ b/lib/sqlalchemy/sql/compiler.py @@ -686,7 +686,7 @@ class SQLCompiler(engine.Compiled): self.binds[bindparam.key] = self.binds[name] = bindparam - return self.bindparam_string(name) + return self.bindparam_string(name, quote=bindparam.quote) def render_literal_bindparam(self, bindparam, **kw): value = bindparam.value @@ -756,7 +756,7 @@ class SQLCompiler(engine.Compiled): self.anon_map[derived] = anonymous_counter + 1 return derived + "_" + str(anonymous_counter) - def bindparam_string(self, name): + def bindparam_string(self, name, quote=None): if self.positional: self.positiontup.append(name) return self.bindtemplate % { @@ -1206,7 +1206,8 @@ class SQLCompiler(engine.Compiled): def _create_crud_bind_param(self, col, value, required=False): bindparam = sql.bindparam(col.key, value, - type_=col.type, required=required) + type_=col.type, required=required, + quote=col.quote) bindparam._is_crud = True return bindparam._compiler_dispatch(self) diff --git a/lib/sqlalchemy/sql/expression.py b/lib/sqlalchemy/sql/expression.py index a0f0bab6c..6e9ddbd5a 100644 --- a/lib/sqlalchemy/sql/expression.py +++ b/lib/sqlalchemy/sql/expression.py @@ -987,7 +987,8 @@ def table(name, *columns): """ return TableClause(name, *columns) -def bindparam(key, value=None, type_=None, unique=False, required=False, callable_=None): +def bindparam(key, value=None, type_=None, unique=False, required=False, + quote=None, callable_=None): """Create a bind parameter clause with the given key. :param key: @@ -1024,15 +1025,19 @@ def bindparam(key, value=None, type_=None, unique=False, required=False, callabl :param required: a value is required at execution time. + :param quote: + True if this parameter name requires quoting and is not + currently known as a SQLAlchemy reserved word; this currently + only applies to the Oracle backend. + """ if isinstance(key, ColumnClause): - return _BindParamClause(key.name, value, type_=key.type, - callable_=callable_, - unique=unique, required=required) - else: - return _BindParamClause(key, value, type_=type_, - callable_=callable_, - unique=unique, required=required) + type_ = key.type + key = key.name + return _BindParamClause(key, value, type_=type_, + callable_=callable_, + unique=unique, required=required, + quote=quote) def outparam(key, type_=None): """Create an 'OUT' parameter for usage in functions (stored procedures), @@ -2613,6 +2618,7 @@ class _BindParamClause(ColumnElement): def __init__(self, key, value, type_=None, unique=False, callable_=None, isoutparam=False, required=False, + quote=None, _compared_to_operator=None, _compared_to_type=None): """Construct a _BindParamClause. @@ -2648,6 +2654,11 @@ class _BindParamClause(ColumnElement): already has been located within the containing :class:`.ClauseElement`. + :param quote: + True if this parameter name requires quoting and is not + currently known as a SQLAlchemy reserved word; this currently + only applies to the Oracle backend. + :param required: a value is required at execution time. @@ -2677,6 +2688,7 @@ class _BindParamClause(ColumnElement): self.callable = callable_ self.isoutparam = isoutparam self.required = required + self.quote = quote if type_ is None: if _compared_to_type is not None: self.type = \ |
