summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--doc/build/changelog/changelog_10.rst13
-rw-r--r--lib/sqlalchemy/sql/elements.py4
-rw-r--r--test/dialect/mssql/test_reflection.py4
-rw-r--r--test/sql/test_compiler.py13
4 files changed, 30 insertions, 4 deletions
diff --git a/doc/build/changelog/changelog_10.rst b/doc/build/changelog/changelog_10.rst
index e63e023d9..4e5e1ba1d 100644
--- a/doc/build/changelog/changelog_10.rst
+++ b/doc/build/changelog/changelog_10.rst
@@ -23,6 +23,19 @@
.. 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
Fixed the name of the :paramref:`.PoolEvents.reset.dbapi_connection`
diff --git a/lib/sqlalchemy/sql/elements.py b/lib/sqlalchemy/sql/elements.py
index fa9b66024..734f78632 100644
--- a/lib/sqlalchemy/sql/elements.py
+++ b/lib/sqlalchemy/sql/elements.py
@@ -1092,7 +1092,7 @@ class BindParameter(ColumnElement):
"""
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:
@@ -3335,7 +3335,7 @@ class ColumnClause(Immutable, ColumnElement):
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)
diff --git a/test/dialect/mssql/test_reflection.py b/test/dialect/mssql/test_reflection.py
index e93162a8e..0ef69f656 100644
--- a/test/dialect/mssql/test_reflection.py
+++ b/test/dialect/mssql/test_reflection.py
@@ -187,7 +187,7 @@ class InfoCoerceUnicodeTest(fixtures.TestBase, AssertsCompiledSQL):
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
)
@@ -197,7 +197,7 @@ class InfoCoerceUnicodeTest(fixtures.TestBase, AssertsCompiledSQL):
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
)
diff --git a/test/sql/test_compiler.py b/test/sql/test_compiler.py
index bfafed599..5d1afe616 100644
--- a/test/sql/test_compiler.py
+++ b/test/sql/test_compiler.py
@@ -435,6 +435,19 @@ class SelectTest(fixtures.TestBase, AssertsCompiledSQL):
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."""