- 优化 string Contains 模糊查找 % 的情况;

This commit is contained in:
2881099
2022-06-29 21:59:46 +08:00
parent 81406ba37a
commit e10fb8ffe5
39 changed files with 447 additions and 131 deletions

View File

@ -146,7 +146,7 @@ namespace FreeSql.Odbc.PostgreSQL
tsc.SetMapColumnTmp(null);
var args1 = getExp(callExp.Arguments[argIndex]);
var oldMapType = tsc.SetMapTypeReturnOld(tsc.mapTypeTmp);
var oldDbParams = objExp.NodeType == ExpressionType.MemberAccess ? tsc.SetDbParamsReturnOld(null) : null; //#900 UseGenerateCommandParameterWithLambda(true) 子查询 bug、以及 #1173 参数化 bug
var oldDbParams = objExp?.NodeType == ExpressionType.MemberAccess ? tsc.SetDbParamsReturnOld(null) : null; //#900 UseGenerateCommandParameterWithLambda(true) 子查询 bug、以及 #1173 参数化 bug
tsc.isNotSetMapColumnTmp = true;
left = objExp == null ? null : getExp(objExp);
tsc.isNotSetMapColumnTmp = false;
@ -390,6 +390,12 @@ namespace FreeSql.Odbc.PostgreSQL
case "Contains":
var args0Value = getExp(exp.Arguments[0]);
if (args0Value == "NULL") return $"({left}) IS NULL";
if (args0Value.Contains("%"))
{
if (exp.Method.Name == "StartsWith") return $"strpos({args0Value}, {left}) = 1";
if (exp.Method.Name == "EndsWith") return $"strpos({args0Value}, {left}) = char_length({args0Value})";
return $"strpos({args0Value}, {left}) > 0";
}
var likeOpt = "LIKE";
if (exp.Arguments.Count > 1)
{