diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2021-11-08 18:29:16 -0500 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2021-11-09 15:30:58 -0500 |
commit | b919a0a85afd5066f9188b20ef06ee1b4af884a9 (patch) | |
tree | 39536ce18d644aae3488905ba501aeffcee8337b /test/dialect/mssql/test_compiler.py | |
parent | cf404d840c15fe167518dd884b295dc99ee26178 (diff) | |
download | sqlalchemy-b919a0a85afd5066f9188b20ef06ee1b4af884a9.tar.gz |
change the POSTCOMPILE/ SCHEMA symbols to not conflict w mssql quoting
Adjusted the compiler's generation of "post compile" symbols including
those used for "expanding IN" as well as for the "schema translate map" to
not be based directly on plain bracketed strings with underscores, as this
conflicts directly with SQL Server's quoting format of also using brackets,
which produces false matches when the compiler replaces "post compile" and
"schema translate" symbols. The issue created easy to reproduce examples
both with the :meth:`.Inspector.get_schema_names` method when used in
conjunction with the
:paramref:`_engine.Connection.execution_options.schema_translate_map`
feature, as well in the unlikely case that a symbol overlapping with the
internal name "POSTCOMPILE" would be used with a feature like "expanding
in".
Fixes: #7300
Change-Id: I6255c850b140522a4aba95085216d0bca18ce230
Diffstat (limited to 'test/dialect/mssql/test_compiler.py')
-rw-r--r-- | test/dialect/mssql/test_compiler.py | 35 |
1 files changed, 18 insertions, 17 deletions
diff --git a/test/dialect/mssql/test_compiler.py b/test/dialect/mssql/test_compiler.py index dc6805a2b..e9ff8fb19 100644 --- a/test/dialect/mssql/test_compiler.py +++ b/test/dialect/mssql/test_compiler.py @@ -333,8 +333,8 @@ class CompileTest(fixtures.TestBase, AssertsCompiledSQL): @testing.combinations( ( lambda: select(literal("x"), literal("y")), - "SELECT [POSTCOMPILE_param_1] AS anon_1, " - "[POSTCOMPILE_param_2] AS anon_2", + "SELECT __[POSTCOMPILE_param_1] AS anon_1, " + "__[POSTCOMPILE_param_2] AS anon_2", { "check_literal_execute": {"param_1": "x", "param_2": "y"}, "check_post_param": {}, @@ -343,7 +343,7 @@ class CompileTest(fixtures.TestBase, AssertsCompiledSQL): ( lambda t: select(t).where(t.c.foo.in_(["x", "y", "z"])), "SELECT sometable.foo FROM sometable WHERE sometable.foo " - "IN ([POSTCOMPILE_foo_1])", + "IN (__[POSTCOMPILE_foo_1])", { "check_literal_execute": {"foo_1": ["x", "y", "z"]}, "check_post_param": {}, @@ -435,7 +435,8 @@ class CompileTest(fixtures.TestBase, AssertsCompiledSQL): crit = q.c.myid == table1.c.myid self.assert_compile( select("*").where(crit), - "SELECT * FROM (SELECT TOP [POSTCOMPILE_param_1] mytable.myid AS " + "SELECT * FROM (SELECT TOP __[POSTCOMPILE_param_1] " + "mytable.myid AS " "myid FROM mytable ORDER BY mytable.myid) AS foo, mytable WHERE " "foo.myid = mytable.myid", ) @@ -809,10 +810,10 @@ class CompileTest(fixtures.TestBase, AssertsCompiledSQL): self.assert_compile( u, "SELECT t1.col3 AS col3, t1.col4 AS col4 " - "FROM t1 WHERE t1.col2 IN ([POSTCOMPILE_col2_1]) " + "FROM t1 WHERE t1.col2 IN (__[POSTCOMPILE_col2_1]) " "UNION SELECT t2.col3 AS col3, " "t2.col4 AS col4 FROM t2 WHERE t2.col2 IN " - "([POSTCOMPILE_col2_2]) ORDER BY col3, col4", + "(__[POSTCOMPILE_col2_2]) ORDER BY col3, col4", checkparams={ "col2_1": ["t1col2r1", "t1col2r2"], "col2_2": ["t2col2r2", "t2col2r3"], @@ -822,9 +823,9 @@ class CompileTest(fixtures.TestBase, AssertsCompiledSQL): u.alias("bar").select(), "SELECT bar.col3, bar.col4 FROM (SELECT " "t1.col3 AS col3, t1.col4 AS col4 FROM t1 " - "WHERE t1.col2 IN ([POSTCOMPILE_col2_1]) UNION " + "WHERE t1.col2 IN (__[POSTCOMPILE_col2_1]) UNION " "SELECT t2.col3 AS col3, t2.col4 AS col4 " - "FROM t2 WHERE t2.col2 IN ([POSTCOMPILE_col2_2])) AS bar", + "FROM t2 WHERE t2.col2 IN (__[POSTCOMPILE_col2_2])) AS bar", checkparams={ "col2_1": ["t1col2r1", "t1col2r2"], "col2_2": ["t2col2r2", "t2col2r3"], @@ -971,7 +972,7 @@ class CompileTest(fixtures.TestBase, AssertsCompiledSQL): self.assert_compile( s, - "SELECT TOP [POSTCOMPILE_param_1] t.x, t.y FROM t " + "SELECT TOP __[POSTCOMPILE_param_1] t.x, t.y FROM t " "WHERE t.x = :x_1 ORDER BY t.y", checkparams={"x_1": 5, "param_1": 10}, ) @@ -999,7 +1000,7 @@ class CompileTest(fixtures.TestBase, AssertsCompiledSQL): self.assert_compile( s, - "SELECT TOP [POSTCOMPILE_param_1] t.x, t.y FROM t " + "SELECT TOP __[POSTCOMPILE_param_1] t.x, t.y FROM t " "WHERE t.x = :x_1 ORDER BY t.y", checkparams={"x_1": 5, "param_1": 0}, ) @@ -1200,7 +1201,7 @@ class CompileTest(fixtures.TestBase, AssertsCompiledSQL): # of zero, so produces TOP 0 self.assert_compile( s, - "SELECT TOP [POSTCOMPILE_param_1] t.x, t.y FROM t " + "SELECT TOP __[POSTCOMPILE_param_1] t.x, t.y FROM t " "WHERE t.x = :x_1 ORDER BY t.y", checkparams={"x_1": 5, "param_1": 0}, ) @@ -1444,21 +1445,21 @@ class CompileTest(fixtures.TestBase, AssertsCompiledSQL): 5, 0, {"percent": True}, - "TOP [POSTCOMPILE_param_1] PERCENT", + "TOP __[POSTCOMPILE_param_1] PERCENT", {"param_1": 5}, ), ( 5, None, {"percent": True, "with_ties": True}, - "TOP [POSTCOMPILE_param_1] PERCENT WITH TIES", + "TOP __[POSTCOMPILE_param_1] PERCENT WITH TIES", {"param_1": 5}, ), ( 5, 0, {"with_ties": True}, - "TOP [POSTCOMPILE_param_1] WITH TIES", + "TOP __[POSTCOMPILE_param_1] WITH TIES", {"param_1": 5}, ), ( @@ -1536,21 +1537,21 @@ class CompileTest(fixtures.TestBase, AssertsCompiledSQL): 5, 0, {"percent": True}, - "TOP [POSTCOMPILE_param_1] PERCENT", + "TOP __[POSTCOMPILE_param_1] PERCENT", {"param_1": 5}, ), ( 5, None, {"percent": True, "with_ties": True}, - "TOP [POSTCOMPILE_param_1] PERCENT WITH TIES", + "TOP __[POSTCOMPILE_param_1] PERCENT WITH TIES", {"param_1": 5}, ), ( 5, 0, {"with_ties": True}, - "TOP [POSTCOMPILE_param_1] WITH TIES", + "TOP __[POSTCOMPILE_param_1] WITH TIES", {"param_1": 5}, ), ( |