Skip to content

Commit 20b8824

Browse files
committed
- 修复 .Contains('b%') 部分数据库函数参数位置错误;#1826
1 parent 6bf4c21 commit 20b8824

File tree

23 files changed

+53
-54
lines changed

23 files changed

+53
-54
lines changed

Providers/FreeSql.Provider.Custom/MySql/CustomMySqlExpression.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ public override string ExpressionLambdaToSqlCallString(MethodCallExpression exp,
316316
if (args0Value.Contains("%"))
317317
{
318318
if (exp.Method.Name == "StartsWith") return $"locate({args0Value}, {left}) = 1";
319-
if (exp.Method.Name == "EndsWith") return $"locate({args0Value}, {left}) = char_length({args0Value})";
319+
if (exp.Method.Name == "EndsWith") return $"locate({args0Value}, {left}) = char_length({left})-char_length({args0Value})+1";
320320
return $"locate({args0Value}, {left}) > 0";
321321
}
322322
if (exp.Method.Name == "StartsWith") return $"({left}) LIKE {(args0Value.EndsWith("'") ? args0Value.Insert(args0Value.Length - 1, "%") : $"concat({args0Value}, '%')")}";

Providers/FreeSql.Provider.Custom/Oracle/CustomOracleExpression.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -318,9 +318,9 @@ public override string ExpressionLambdaToSqlCallString(MethodCallExpression exp,
318318
if (args0Value == "NULL") return $"({left}) IS NULL";
319319
if (args0Value.Contains("%"))
320320
{
321-
if (exp.Method.Name == "StartsWith") return $"instr({args0Value}, {left}) = 1";
322-
if (exp.Method.Name == "EndsWith") return $"instr({args0Value}, {left}) = length({args0Value})";
323-
return $"instr({args0Value}, {left}) > 0";
321+
if (exp.Method.Name == "StartsWith") return $"instr({left}, {args0Value}, 1, 1) = 1";
322+
if (exp.Method.Name == "EndsWith") return $"instr({left}, {args0Value}, 1, 1) = length({left})-length({args0Value})+1";
323+
return $"instr({left}, {args0Value}, 1, 1) > 0";
324324
}
325325
if (exp.Method.Name == "StartsWith") return $"({left}) LIKE {(args0Value.EndsWith("'") ? args0Value.Insert(args0Value.Length - 1, "%") : $"(to_char({args0Value})||'%')")}";
326326
if (exp.Method.Name == "EndsWith") return $"({left}) LIKE {(args0Value.StartsWith("'") ? args0Value.Insert(1, "%") : $"('%'||to_char({args0Value}))")}";

Providers/FreeSql.Provider.Custom/PostgreSQL/CustomPostgreSQLExpression.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -407,9 +407,9 @@ public override string ExpressionLambdaToSqlCallString(MethodCallExpression exp,
407407
if (args0Value == "NULL") return $"({left}) IS NULL";
408408
if (args0Value.Contains("%"))
409409
{
410-
if (exp.Method.Name == "StartsWith") return $"strpos({args0Value}, {left}) = 1";
411-
if (exp.Method.Name == "EndsWith") return $"strpos({args0Value}, {left}) = char_length({args0Value})";
412-
return $"strpos({args0Value}, {left}) > 0";
410+
if (exp.Method.Name == "StartsWith") return $"strpos({left}, {args0Value}) = 1";
411+
if (exp.Method.Name == "EndsWith") return $"strpos({left}, {args0Value}) = char_length({left})-char_length({args0Value})+1";
412+
return $"strpos({left}, {args0Value}) > 0";
413413
}
414414
var likeOpt = "LIKE";
415415
if (exp.Arguments.Count > 1)

Providers/FreeSql.Provider.Custom/SqlServer/CustomSqlServerExpression.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@ public override string ExpressionLambdaToSqlCallString(MethodCallExpression exp,
339339
if (args0Value.Contains("%"))
340340
{
341341
if (exp.Method.Name == "StartsWith") return $"charindex({args0Value}, {left}) = 1";
342-
if (exp.Method.Name == "EndsWith") return $"charindex({args0Value}, {left}) = len({args0Value})";
342+
if (exp.Method.Name == "EndsWith") return $"charindex({args0Value}, {left}) = len({left})-len({args0Value})+1";
343343
return $"charindex({args0Value}, {left}) > 0";
344344
}
345345
if (exp.Method.Name == "StartsWith") return $"({left}) LIKE {(args0Value.EndsWith("'") ? args0Value.Insert(args0Value.Length - 1, "%") : $"(cast({args0Value} as nvarchar(max))+'%')")}";

Providers/FreeSql.Provider.Dameng/DamengExpression.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -318,9 +318,9 @@ public override string ExpressionLambdaToSqlCallString(MethodCallExpression exp,
318318
if (args0Value == "NULL") return $"({left}) IS NULL";
319319
if (args0Value.Contains("%"))
320320
{
321-
if (exp.Method.Name == "StartsWith") return $"instr({args0Value}, {left}) = 1";
322-
if (exp.Method.Name == "EndsWith") return $"instr({args0Value}, {left}) = length({args0Value})";
323-
return $"instr({args0Value}, {left}) > 0";
321+
if (exp.Method.Name == "StartsWith") return $"instr({left}, {args0Value}, 1, 1) = 1";
322+
if (exp.Method.Name == "EndsWith") return $"instr({left}, {args0Value}, 1, 1) = length({left})-length({args0Value})+1";
323+
return $"instr({left}, {args0Value}, 1, 1) > 0";
324324
}
325325
if (exp.Method.Name == "StartsWith") return $"({left}) LIKE {(args0Value.EndsWith("'") ? args0Value.Insert(args0Value.Length - 1, "%") : $"(to_char({args0Value})||'%')")}";
326326
if (exp.Method.Name == "EndsWith") return $"({left}) LIKE {(args0Value.StartsWith("'") ? args0Value.Insert(1, "%") : $"('%'||to_char({args0Value}))")}";

Providers/FreeSql.Provider.Firebird/FirebirdExpression.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ public override string ExpressionLambdaToSqlCallString(MethodCallExpression exp,
306306
if (args0Value.Contains("%"))
307307
{
308308
if (exp.Method.Name == "StartsWith") return $"position({args0Value}, {left}) = 1";
309-
if (exp.Method.Name == "EndsWith") return $"position({args0Value}, {left}) = char_length({args0Value})";
309+
if (exp.Method.Name == "EndsWith") return $"position({args0Value}, {left}) = char_length({left})-char_length({args0Value})+1";
310310
return $"position({args0Value}, {left}) > 0";
311311
}
312312
if (exp.Method.Name == "StartsWith") return $"({left}) LIKE {(args0Value.EndsWith("'") ? args0Value.Insert(args0Value.Length - 1, "%") : $"({args0Value})||'%'")}";

Providers/FreeSql.Provider.GBase/GBaseExpression.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ public override string ExpressionLambdaToSqlCallString(MethodCallExpression exp,
306306
if (args0Value.Contains("%"))
307307
{
308308
if (exp.Method.Name == "StartsWith") return $"instr({args0Value}, {left}) = 1";
309-
if (exp.Method.Name == "EndsWith") return $"instr({args0Value}, {left}) = char_length({args0Value})";
309+
if (exp.Method.Name == "EndsWith") return $"instr({args0Value}, {left}) = char_length({left})-char_length({args0Value})+1";
310310
return $"instr({args0Value}, {left}) > 0";
311311
}
312312
if (exp.Method.Name == "StartsWith") return $"({left}) LIKE {(args0Value.EndsWith("'") ? args0Value.Insert(args0Value.Length - 1, "%") : $"({args0Value})||'%'")}";

Providers/FreeSql.Provider.KingbaseES/KingbaseESExpression.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -385,9 +385,9 @@ public override string ExpressionLambdaToSqlCallString(MethodCallExpression exp,
385385
if (args0Value == "NULL") return $"({left}) IS NULL";
386386
if (args0Value.Contains("%"))
387387
{
388-
if (exp.Method.Name == "StartsWith") return $"strpos({args0Value}, {left}) = 1";
389-
if (exp.Method.Name == "EndsWith") return $"strpos({args0Value}, {left}) = char_length({args0Value})";
390-
return $"strpos({args0Value}, {left}) > 0";
388+
if (exp.Method.Name == "StartsWith") return $"strpos({left}, {args0Value}) = 1";
389+
if (exp.Method.Name == "EndsWith") return $"strpos({left}, {args0Value}) = char_length({left})-char_length({args0Value})+1";
390+
return $"strpos({left}, {args0Value}) > 0";
391391
}
392392
var likeOpt = "LIKE";
393393
if (exp.Arguments.Count > 1)

Providers/FreeSql.Provider.MsAccess/MsAccessExpression.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -279,9 +279,9 @@ public override string ExpressionLambdaToSqlCallString(MethodCallExpression exp,
279279
if (args0Value == "NULL") return $"({left}) IS NULL";
280280
if (args0Value.Contains("%"))
281281
{
282-
if (exp.Method.Name == "StartsWith") return $"instr({args0Value}, {left}) = 1";
283-
if (exp.Method.Name == "EndsWith") return $"instr({args0Value}, {left}) = len({args0Value})";
284-
return $"instr({args0Value}, {left}) > 0";
282+
if (exp.Method.Name == "StartsWith") return $"instr({left}, {args0Value}) = 1";
283+
if (exp.Method.Name == "EndsWith") return $"instr({left}, {args0Value}) = len({left})-len({args0Value})+1";
284+
return $"instr({left}, {args0Value}) > 0";
285285
}
286286
if (exp.Method.Name == "StartsWith") return $"({left}) LIKE {(args0Value.EndsWith("'") ? args0Value.Insert(args0Value.Length - 1, "%") : $"({args0Value}+'%')")}";
287287
if (exp.Method.Name == "EndsWith") return $"({left}) LIKE {(args0Value.StartsWith("'") ? args0Value.Insert(1, "%") : $"('%'+{args0Value})")}";

Providers/FreeSql.Provider.MySql/MySqlExpression.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ public override string ExpressionLambdaToSqlCallString(MethodCallExpression exp,
318318
if (args0Value.Contains("%"))
319319
{
320320
if (exp.Method.Name == "StartsWith") return $"locate({args0Value}, {left}) = 1";
321-
if (exp.Method.Name == "EndsWith") return $"locate({args0Value}, {left}) = char_length({args0Value})";
321+
if (exp.Method.Name == "EndsWith") return $"locate({args0Value}, {left}) = char_length({left})-char_length({args0Value})+1";
322322
return $"locate({args0Value}, {left}) > 0";
323323
}
324324
if (exp.Method.Name == "StartsWith") return $"({left}) LIKE {(args0Value.EndsWith("'") ? args0Value.Insert(args0Value.Length - 1, "%") : $"concat({args0Value}, '%')")}";

0 commit comments

Comments
 (0)