diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2021-04-20 15:09:51 -0400 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2021-04-20 15:28:45 -0400 |
commit | 3a0a6e1db43a4aefd3570f2956ae2567e3062a77 (patch) | |
tree | fddf3de01a9e37cb6ff4661ff78ceebeeb117ef3 /test/sql/test_values.py | |
parent | 141846612700b5355173e7883f048ffa21ad1f75 (diff) | |
download | sqlalchemy-3a0a6e1db43a4aefd3570f2956ae2567e3062a77.tar.gz |
Propagate compiler kw for visit_values to parameters
Fixed issue in SQL compiler where the bound parameters set up for a
:class:`.Values` construct wouldn't be positionally tracked correctly if
inside of a :class:`_sql.CTE`, affecting database drivers that support
VALUES + ctes and use positional parameters such as SQL Server in
particular as well as asyncpg. The fix also repairs support for
compiler flags such as ``literal_binds``.
Fixes: #6327
Change-Id: I2d549228691d0bfc10dadd0955b1549d7584db51
Diffstat (limited to 'test/sql/test_values.py')
-rw-r--r-- | test/sql/test_values.py | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/test/sql/test_values.py b/test/sql/test_values.py index 43e8f8531..dcd32a679 100644 --- a/test/sql/test_values.py +++ b/test/sql/test_values.py @@ -85,6 +85,69 @@ class ValuesTest(fixtures.TablesTest, AssertsCompiledSQL): 'AS "Spaces and Cases" ("CaseSensitive", "has spaces", number)', ) + def test_values_in_cte_params(self): + cte1 = select( + Values( + column("col1", String), + column("col2", Integer), + name="temp_table", + ).data([("a", 2), ("b", 3)]) + ).cte("cte1") + + cte2 = select(cte1.c.col1).where(cte1.c.col1 == "q").cte("cte2") + stmt = select(cte2.c.col1) + + dialect = default.DefaultDialect() + dialect.positional = True + dialect.paramstyle = "numeric" + self.assert_compile( + stmt, + "WITH cte1 AS (SELECT temp_table.col1 AS col1, " + "temp_table.col2 AS col2 FROM (VALUES (:1, :2), (:3, :4)) AS " + "temp_table (col1, col2)), " + "cte2 AS " + "(SELECT cte1.col1 AS col1 FROM cte1 WHERE cte1.col1 = :5) " + "SELECT cte2.col1 FROM cte2", + checkpositional=("a", 2, "b", 3, "q"), + dialect=dialect, + ) + + self.assert_compile( + stmt, + "WITH cte1 AS (SELECT temp_table.col1 AS col1, " + "temp_table.col2 AS col2 FROM (VALUES ('a', 2), ('b', 3)) " + "AS temp_table (col1, col2)), " + "cte2 AS " + "(SELECT cte1.col1 AS col1 FROM cte1 WHERE cte1.col1 = 'q') " + "SELECT cte2.col1 FROM cte2", + literal_binds=True, + dialect=dialect, + ) + + def test_values_in_cte_literal_binds(self): + cte1 = select( + Values( + column("col1", String), + column("col2", Integer), + name="temp_table", + literal_binds=True, + ).data([("a", 2), ("b", 3)]) + ).cte("cte1") + + cte2 = select(cte1.c.col1).where(cte1.c.col1 == "q").cte("cte2") + stmt = select(cte2.c.col1) + + self.assert_compile( + stmt, + "WITH cte1 AS (SELECT temp_table.col1 AS col1, " + "temp_table.col2 AS col2 FROM (VALUES ('a', 2), ('b', 3)) " + "AS temp_table (col1, col2)), " + "cte2 AS " + "(SELECT cte1.col1 AS col1 FROM cte1 WHERE cte1.col1 = :col1_1) " + "SELECT cte2.col1 FROM cte2", + checkparams={"col1_1": "q"}, + ) + @testing.fixture def literal_parameter_fixture(self): def go(literal_binds, omit=None): |