summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/sql/operators.py
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2022-07-17 11:32:27 -0400
committerMike Bayer <mike_mp@zzzcomputing.com>2022-07-17 11:32:27 -0400
commit85a88df13ab8d217331cf98392544a888b4d7df3 (patch)
tree7dbe7bd9c6b2595a6067fb4ea6b00ae7fa933362 /lib/sqlalchemy/sql/operators.py
parentf1dff43a825fe779d52e12d9a823ede0edef9bb0 (diff)
downloadsqlalchemy-85a88df13ab8d217331cf98392544a888b4d7df3.tar.gz
use concat() directly for contains, startswith, endswith
Adjusted the SQL compilation for string containment functions ``.contains()``, ``.startswith()``, ``.endswith()`` to force the use of the string concatenation operator, rather than relying upon the overload of the addition operator, so that non-standard use of these operators with for example bytestrings still produces string concatenation operators. To accommodate this, needed to add a new _rconcat operator function, which is private, as well as a fallback in concat_op() that works similarly to Python builtin ops. Fixes: #8253 Change-Id: I2b7f56492f765742d88cb2a7834ded6a2892bd7e
Diffstat (limited to 'lib/sqlalchemy/sql/operators.py')
-rw-r--r--lib/sqlalchemy/sql/operators.py17
1 files changed, 16 insertions, 1 deletions
diff --git a/lib/sqlalchemy/sql/operators.py b/lib/sqlalchemy/sql/operators.py
index 2b888769a..44d63b398 100644
--- a/lib/sqlalchemy/sql/operators.py
+++ b/lib/sqlalchemy/sql/operators.py
@@ -615,6 +615,16 @@ class ColumnOperators(Operators):
"""
return self.operate(concat_op, other)
+ def _rconcat(self, other: Any) -> ColumnOperators:
+ """Implement an 'rconcat' operator.
+
+ this is for internal use at the moment
+
+ .. versionadded:: 1.4.40
+
+ """
+ return self.reverse_operate(concat_op, other)
+
def like(
self, other: Any, escape: Optional[str] = None
) -> ColumnOperators:
@@ -1764,7 +1774,12 @@ def filter_op(a: Any, b: Any) -> Any:
@_operator_fn
def concat_op(a: Any, b: Any) -> Any:
- return a.concat(b)
+ try:
+ concat = a.concat
+ except AttributeError:
+ return b._rconcat(a)
+ else:
+ return concat(b)
@_operator_fn