From 7a64f9d65f4bbcfa3a3c60f4e3dc7ba37340ada0 Mon Sep 17 00:00:00 2001 From: 2881099 <2881099@qq.com> Date: Thu, 29 Dec 2022 16:17:10 +0800 Subject: [PATCH] =?UTF-8?q?-=20=E4=BC=98=E5=8C=96=20ClickHouse=20like=20?= =?UTF-8?q?=E4=B8=BA=20positionCaseInsensitive=20#1386?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ClickHouseExpression.cs | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/Providers/FreeSql.Provider.ClickHouse/ClickHouseExpression.cs b/Providers/FreeSql.Provider.ClickHouse/ClickHouseExpression.cs index aa4c964a..bcab608c 100644 --- a/Providers/FreeSql.Provider.ClickHouse/ClickHouseExpression.cs +++ b/Providers/FreeSql.Provider.ClickHouse/ClickHouseExpression.cs @@ -317,16 +317,9 @@ namespace FreeSql.ClickHouse case "Contains": var args0Value = getExp(exp.Arguments[0]); if (args0Value == "NULL") return $"({left}) IS NULL"; - if (args0Value.Contains("%")) - { - if (exp.Method.Name == "StartsWith") return $"locate({args0Value}, {left}) = 1"; - if (exp.Method.Name == "EndsWith") return $"locate({args0Value}, {left}) = char_length({args0Value})"; - return $"locate({args0Value}, {left}) > 0"; - } - if (exp.Method.Name == "StartsWith") return $"({left}) LIKE {(args0Value.EndsWith("'") ? args0Value.Insert(args0Value.Length - 1, "%") : $"concat({args0Value}, '%')")}"; + if (exp.Method.Name == "StartsWith") return $"positionCaseInsensitive({left}, {args0Value}) = 1"; if (exp.Method.Name == "EndsWith") return $"({left}) LIKE {(args0Value.StartsWith("'") ? args0Value.Insert(1, "%") : $"concat('%', {args0Value})")}"; - if (args0Value.StartsWith("'") && args0Value.EndsWith("'")) return $"({left}) LIKE {args0Value.Insert(1, "%").Insert(args0Value.Length, "%")}"; - return $"({left}) LIKE concat('%', {args0Value}, '%')"; + return $"positionCaseInsensitive({left}, {args0Value}) > 0"; case "ToLower": return $"lower({left})"; case "ToUpper": return $"upper({left})"; case "Substring":