From e06ef2154210ce1a5ced6f58330a258f7adfaa55 Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Thu, 15 Dec 2022 10:22:36 -0500 Subject: implement literal_binds with expanding + bind_expression Fixed bug where SQL compilation would fail to make use of :meth:`_types.TypeEngine.bind_expression` on a given type when used in the context of an "expanding" (i.e. "IN") parameter with the ``literal_binds`` compiler parameter in use. Fixes: #8989 Change-Id: Ic9fd27b46381b488117295ea5a492d8fc158e39f --- test/sql/test_type_expressions.py | 48 ++++++++++++++++++++++++--------------- 1 file changed, 30 insertions(+), 18 deletions(-) (limited to 'test/sql') diff --git a/test/sql/test_type_expressions.py b/test/sql/test_type_expressions.py index 6c717123b..c2ecd46e2 100644 --- a/test/sql/test_type_expressions.py +++ b/test/sql/test_type_expressions.py @@ -183,28 +183,40 @@ class SelectTest(_ExprFixture, fixtures.TestBase, AssertsCompiledSQL): "test_table WHERE test_table.y = lower(:y_1)", ) - def test_in_binds(self): + @testing.variation( + "compile_opt", ["plain", "postcompile", "literal_binds"] + ) + def test_in_binds(self, compile_opt): table = self._fixture() - self.assert_compile( - select(table).where( - table.c.y.in_(["hi", "there", "some", "expr"]) - ), - "SELECT test_table.x, lower(test_table.y) AS y FROM " - "test_table WHERE test_table.y IN " - "(__[POSTCOMPILE_y_1~~lower(~~REPL~~)~~])", - render_postcompile=False, + stmt = select(table).where( + table.c.y.in_(["hi", "there", "some", "expr"]) ) - self.assert_compile( - select(table).where( - table.c.y.in_(["hi", "there", "some", "expr"]) - ), - "SELECT test_table.x, lower(test_table.y) AS y FROM " - "test_table WHERE test_table.y IN " - "(lower(:y_1_1), lower(:y_1_2), lower(:y_1_3), lower(:y_1_4))", - render_postcompile=True, - ) + if compile_opt.plain: + self.assert_compile( + stmt, + "SELECT test_table.x, lower(test_table.y) AS y FROM " + "test_table WHERE test_table.y IN " + "(__[POSTCOMPILE_y_1~~lower(~~REPL~~)~~])", + render_postcompile=False, + ) + elif compile_opt.postcompile: + self.assert_compile( + stmt, + "SELECT test_table.x, lower(test_table.y) AS y FROM " + "test_table WHERE test_table.y IN " + "(lower(:y_1_1), lower(:y_1_2), lower(:y_1_3), lower(:y_1_4))", + render_postcompile=True, + ) + elif compile_opt.literal_binds: + self.assert_compile( + stmt, + "SELECT test_table.x, lower(test_table.y) AS y FROM " + "test_table WHERE test_table.y IN " + "(lower('hi'), lower('there'), lower('some'), lower('expr'))", + literal_binds=True, + ) def test_dialect(self): table = self._fixture() -- cgit v1.2.1