From 79bde753e47bd86f0199c4aa6a5c2ead1e4aec95 Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Tue, 9 Mar 2021 13:36:34 -0500 Subject: Apply percent sign escaping to op(), custom_op() Fixed bug where the "percent escaping" feature that occurs with dialects that use the "format" or "pyformat" bound parameter styles was not enabled for the :meth:`.Operations.op` and :meth:`.Operations.custom_op` methods, for custom operators that use percent signs. The percent sign will now be automatically doubled based on the paramstyle as necessary. Fixes: #6016 Change-Id: I285c5fc082481c2ee989edf1b02a83a6087ea26a --- lib/sqlalchemy/sql/compiler.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'lib/sqlalchemy/sql') diff --git a/lib/sqlalchemy/sql/compiler.py b/lib/sqlalchemy/sql/compiler.py index 8f046a802..0ea251fb4 100644 --- a/lib/sqlalchemy/sql/compiler.py +++ b/lib/sqlalchemy/sql/compiler.py @@ -2055,17 +2055,19 @@ class SQLCompiler(Compiled): def visit_custom_op_binary(self, element, operator, **kw): kw["eager_grouping"] = operator.eager_grouping return self._generate_generic_binary( - element, " " + operator.opstring + " ", **kw + element, + " " + self.escape_literal_column(operator.opstring) + " ", + **kw ) def visit_custom_op_unary_operator(self, element, operator, **kw): return self._generate_generic_unary_operator( - element, operator.opstring + " ", **kw + element, self.escape_literal_column(operator.opstring) + " ", **kw ) def visit_custom_op_unary_modifier(self, element, operator, **kw): return self._generate_generic_unary_modifier( - element, " " + operator.opstring, **kw + element, " " + self.escape_literal_column(operator.opstring), **kw ) def _generate_generic_binary( -- cgit v1.2.1