series as well. For changes that are specific to 1.0 with an emphasis
on compatibility concerns, see :doc:`/changelog/migration_10`.
+ .. change::
+ :tags: bug, sql
+ :tickets: 3245
+
+ The :attr:`.Column.key` attribute is now used as the source of
+ anonymous bound parameter names within expressions, to match the
+ existing use of this value as the key when rendered in an INSERT
+ or UPDATE statement. This allows :attr:`.Column.key` to be used
+ as a "substitute" string to work around a difficult column name
+ that doesn't translate well into a bound parameter name. Note that
+ the paramstyle is configurable on :func:`.create_engine` in any case,
+ and most DBAPIs today support a named and positional style.
+
.. change::
:tags: bug, sql
:pullreq: github:146
"""
if isinstance(key, ColumnClause):
type_ = key.type
- key = key.name
+ key = key.key
if required is NO_ARG:
required = (value is NO_ARG and callable_ is None)
if value is NO_ARG:
return name
def _bind_param(self, operator, obj):
- return BindParameter(self.name, obj,
+ return BindParameter(self.key, obj,
_compared_to_operator=operator,
_compared_to_type=self.type,
unique=True)
stmt = tables.c.table_name == 'somename'
self.assert_compile(
stmt,
- "[TABLES_1].[TABLE_NAME] = :TABLE_NAME_1",
+ "[TABLES_1].[TABLE_NAME] = :table_name_1",
dialect=dialect
)
stmt = tables.c.table_name == 'somename'
self.assert_compile(
stmt,
- "[TABLES_1].[TABLE_NAME] = CAST(:TABLE_NAME_1 AS NVARCHAR(max))",
+ "[TABLES_1].[TABLE_NAME] = CAST(:table_name_1 AS NVARCHAR(max))",
dialect=dialect
)
dialect=default.DefaultDialect(paramstyle='pyformat')
)
+ def test_anon_param_name_on_keys(self):
+ self.assert_compile(
+ keyed.insert(),
+ "INSERT INTO keyed (x, y, z) VALUES (%(colx)s, %(coly)s, %(z)s)",
+ dialect=default.DefaultDialect(paramstyle='pyformat')
+ )
+ self.assert_compile(
+ keyed.c.coly == 5,
+ "keyed.y = %(coly_1)s",
+ checkparams={'coly_1': 5},
+ dialect=default.DefaultDialect(paramstyle='pyformat')
+ )
+
def test_dupe_columns(self):
"""test that deduping is performed against clause
element identity, not rendered result."""