summaryrefslogtreecommitdiff
path: root/test/dialect/mssql/test_compiler.py
diff options
context:
space:
mode:
authorShan <shan224@gmail.com>2023-01-22 11:19:11 -0500
committerMike Bayer <mike_mp@zzzcomputing.com>2023-01-23 10:48:41 -0500
commitaa50375a9aa72be896a7cf3afbbbec161c7111bd (patch)
treec7f9efa34a14a8796c47fd9ab59fd092f7202862 /test/dialect/mssql/test_compiler.py
parent2f91dd79310657814ad28b6ef64f91fff7a007c9 (diff)
downloadsqlalchemy-aa50375a9aa72be896a7cf3afbbbec161c7111bd.tar.gz
Run bracket interpretation for reflection
Fixed bug where a schema name given with brackets, but no dots inside the name, for parameters such as :paramref:`_schema.Table.schema` would not be interpreted within the context of the SQL Server dialect's documented behavior of interpreting explicit brackets as token delimiters, first added in 1.2 for #2626, when referring to the schema name in reflection operations. The original assumption for #2626's behavior was that the special interpretation of brackets was only significant if dots were present, however in practice, the brackets are not included as part of the identifier name for all SQL rendering operations since these are not valid characters within regular or delimited identifiers. Pull request courtesy Shan. Fixes: #9133 Closes: #9134 Pull-request: https://github.com/sqlalchemy/sqlalchemy/pull/9134 Pull-request-sha: 5dac87c82cd3063dd8e50f0075c7c00330be6439 Change-Id: I7a507bc38d75a04ffcb7e920298775baae22c6d1
Diffstat (limited to 'test/dialect/mssql/test_compiler.py')
-rw-r--r--test/dialect/mssql/test_compiler.py41
1 files changed, 41 insertions, 0 deletions
diff --git a/test/dialect/mssql/test_compiler.py b/test/dialect/mssql/test_compiler.py
index 00bbc2af4..0076c76fd 100644
--- a/test/dialect/mssql/test_compiler.py
+++ b/test/dialect/mssql/test_compiler.py
@@ -599,6 +599,47 @@ class CompileTest(fixtures.TestBase, AssertsCompiledSQL):
checkpositional=("bar",),
)
+ @testing.variation("use_schema_translate", [True, False])
+ @testing.combinations(
+ "abc", "has spaces", "[abc]", "[has spaces]", argnames="schemaname"
+ )
+ def test_schema_single_token_bracketed(
+ self, use_schema_translate, schemaname
+ ):
+ """test for #9133.
+
+ this is not the actual regression case for #9133, which is instead
+ within the reflection process. However, when we implemented
+ #2626, we never considered the case of ``[schema]`` without any
+ dots in it.
+
+ """
+
+ schema_no_brackets = schemaname.strip("[]")
+
+ if " " in schemaname:
+ rendered_schema = "[%s]" % (schema_no_brackets,)
+ else:
+ rendered_schema = schema_no_brackets
+
+ metadata = MetaData()
+ tbl = Table(
+ "test",
+ metadata,
+ Column("id", Integer, primary_key=True),
+ schema=schemaname if not use_schema_translate else None,
+ )
+
+ self.assert_compile(
+ select(tbl),
+ "SELECT %(name)s.test.id FROM %(name)s.test"
+ % {"name": rendered_schema},
+ schema_translate_map={None: schemaname}
+ if use_schema_translate
+ else None,
+ render_schema_translate=True if use_schema_translate else False,
+ )
+
def test_schema_many_tokens_one(self):
metadata = MetaData()
tbl = Table(