Skip to content

Commit

Permalink
- 修复 .Contains('b%') 部分数据库函数参数位置错误;#1826
Browse files Browse the repository at this point in the history
  • Loading branch information
2881099 committed Jun 19, 2024
1 parent 6bf4c21 commit 20b8824
Show file tree
Hide file tree
Showing 23 changed files with 53 additions and 54 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ public override string ExpressionLambdaToSqlCallString(MethodCallExpression exp,
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})";
if (exp.Method.Name == "EndsWith") return $"locate({args0Value}, {left}) = char_length({left})-char_length({args0Value})+1";
return $"locate({args0Value}, {left}) > 0";
}
if (exp.Method.Name == "StartsWith") return $"({left}) LIKE {(args0Value.EndsWith("'") ? args0Value.Insert(args0Value.Length - 1, "%") : $"concat({args0Value}, '%')")}";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -318,9 +318,9 @@ public override string ExpressionLambdaToSqlCallString(MethodCallExpression exp,
if (args0Value == "NULL") return $"({left}) IS NULL";
if (args0Value.Contains("%"))
{
if (exp.Method.Name == "StartsWith") return $"instr({args0Value}, {left}) = 1";
if (exp.Method.Name == "EndsWith") return $"instr({args0Value}, {left}) = length({args0Value})";
return $"instr({args0Value}, {left}) > 0";
if (exp.Method.Name == "StartsWith") return $"instr({left}, {args0Value}, 1, 1) = 1";
if (exp.Method.Name == "EndsWith") return $"instr({left}, {args0Value}, 1, 1) = length({left})-length({args0Value})+1";
return $"instr({left}, {args0Value}, 1, 1) > 0";
}
if (exp.Method.Name == "StartsWith") return $"({left}) LIKE {(args0Value.EndsWith("'") ? args0Value.Insert(args0Value.Length - 1, "%") : $"(to_char({args0Value})||'%')")}";
if (exp.Method.Name == "EndsWith") return $"({left}) LIKE {(args0Value.StartsWith("'") ? args0Value.Insert(1, "%") : $"('%'||to_char({args0Value}))")}";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -407,9 +407,9 @@ public override string ExpressionLambdaToSqlCallString(MethodCallExpression exp,
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";
if (exp.Method.Name == "StartsWith") return $"strpos({left}, {args0Value}) = 1";
if (exp.Method.Name == "EndsWith") return $"strpos({left}, {args0Value}) = char_length({left})-char_length({args0Value})+1";
return $"strpos({left}, {args0Value}) > 0";
}
var likeOpt = "LIKE";
if (exp.Arguments.Count > 1)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ public override string ExpressionLambdaToSqlCallString(MethodCallExpression exp,
if (args0Value.Contains("%"))
{
if (exp.Method.Name == "StartsWith") return $"charindex({args0Value}, {left}) = 1";
if (exp.Method.Name == "EndsWith") return $"charindex({args0Value}, {left}) = len({args0Value})";
if (exp.Method.Name == "EndsWith") return $"charindex({args0Value}, {left}) = len({left})-len({args0Value})+1";
return $"charindex({args0Value}, {left}) > 0";
}
if (exp.Method.Name == "StartsWith") return $"({left}) LIKE {(args0Value.EndsWith("'") ? args0Value.Insert(args0Value.Length - 1, "%") : $"(cast({args0Value} as nvarchar(max))+'%')")}";
Expand Down
6 changes: 3 additions & 3 deletions Providers/FreeSql.Provider.Dameng/DamengExpression.cs
Original file line number Diff line number Diff line change
Expand Up @@ -318,9 +318,9 @@ public override string ExpressionLambdaToSqlCallString(MethodCallExpression exp,
if (args0Value == "NULL") return $"({left}) IS NULL";
if (args0Value.Contains("%"))
{
if (exp.Method.Name == "StartsWith") return $"instr({args0Value}, {left}) = 1";
if (exp.Method.Name == "EndsWith") return $"instr({args0Value}, {left}) = length({args0Value})";
return $"instr({args0Value}, {left}) > 0";
if (exp.Method.Name == "StartsWith") return $"instr({left}, {args0Value}, 1, 1) = 1";
if (exp.Method.Name == "EndsWith") return $"instr({left}, {args0Value}, 1, 1) = length({left})-length({args0Value})+1";
return $"instr({left}, {args0Value}, 1, 1) > 0";
}
if (exp.Method.Name == "StartsWith") return $"({left}) LIKE {(args0Value.EndsWith("'") ? args0Value.Insert(args0Value.Length - 1, "%") : $"(to_char({args0Value})||'%')")}";
if (exp.Method.Name == "EndsWith") return $"({left}) LIKE {(args0Value.StartsWith("'") ? args0Value.Insert(1, "%") : $"('%'||to_char({args0Value}))")}";
Expand Down
2 changes: 1 addition & 1 deletion Providers/FreeSql.Provider.Firebird/FirebirdExpression.cs
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ public override string ExpressionLambdaToSqlCallString(MethodCallExpression exp,
if (args0Value.Contains("%"))
{
if (exp.Method.Name == "StartsWith") return $"position({args0Value}, {left}) = 1";
if (exp.Method.Name == "EndsWith") return $"position({args0Value}, {left}) = char_length({args0Value})";
if (exp.Method.Name == "EndsWith") return $"position({args0Value}, {left}) = char_length({left})-char_length({args0Value})+1";
return $"position({args0Value}, {left}) > 0";
}
if (exp.Method.Name == "StartsWith") return $"({left}) LIKE {(args0Value.EndsWith("'") ? args0Value.Insert(args0Value.Length - 1, "%") : $"({args0Value})||'%'")}";
Expand Down
2 changes: 1 addition & 1 deletion Providers/FreeSql.Provider.GBase/GBaseExpression.cs
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ public override string ExpressionLambdaToSqlCallString(MethodCallExpression exp,
if (args0Value.Contains("%"))
{
if (exp.Method.Name == "StartsWith") return $"instr({args0Value}, {left}) = 1";
if (exp.Method.Name == "EndsWith") return $"instr({args0Value}, {left}) = char_length({args0Value})";
if (exp.Method.Name == "EndsWith") return $"instr({args0Value}, {left}) = char_length({left})-char_length({args0Value})+1";
return $"instr({args0Value}, {left}) > 0";
}
if (exp.Method.Name == "StartsWith") return $"({left}) LIKE {(args0Value.EndsWith("'") ? args0Value.Insert(args0Value.Length - 1, "%") : $"({args0Value})||'%'")}";
Expand Down
6 changes: 3 additions & 3 deletions Providers/FreeSql.Provider.KingbaseES/KingbaseESExpression.cs
Original file line number Diff line number Diff line change
Expand Up @@ -385,9 +385,9 @@ public override string ExpressionLambdaToSqlCallString(MethodCallExpression exp,
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";
if (exp.Method.Name == "StartsWith") return $"strpos({left}, {args0Value}) = 1";
if (exp.Method.Name == "EndsWith") return $"strpos({left}, {args0Value}) = char_length({left})-char_length({args0Value})+1";
return $"strpos({left}, {args0Value}) > 0";
}
var likeOpt = "LIKE";
if (exp.Arguments.Count > 1)
Expand Down
6 changes: 3 additions & 3 deletions Providers/FreeSql.Provider.MsAccess/MsAccessExpression.cs
Original file line number Diff line number Diff line change
Expand Up @@ -279,9 +279,9 @@ public override string ExpressionLambdaToSqlCallString(MethodCallExpression exp,
if (args0Value == "NULL") return $"({left}) IS NULL";
if (args0Value.Contains("%"))
{
if (exp.Method.Name == "StartsWith") return $"instr({args0Value}, {left}) = 1";
if (exp.Method.Name == "EndsWith") return $"instr({args0Value}, {left}) = len({args0Value})";
return $"instr({args0Value}, {left}) > 0";
if (exp.Method.Name == "StartsWith") return $"instr({left}, {args0Value}) = 1";
if (exp.Method.Name == "EndsWith") return $"instr({left}, {args0Value}) = len({left})-len({args0Value})+1";
return $"instr({left}, {args0Value}) > 0";
}
if (exp.Method.Name == "StartsWith") return $"({left}) LIKE {(args0Value.EndsWith("'") ? args0Value.Insert(args0Value.Length - 1, "%") : $"({args0Value}+'%')")}";
if (exp.Method.Name == "EndsWith") return $"({left}) LIKE {(args0Value.StartsWith("'") ? args0Value.Insert(1, "%") : $"('%'+{args0Value})")}";
Expand Down
2 changes: 1 addition & 1 deletion Providers/FreeSql.Provider.MySql/MySqlExpression.cs
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ public override string ExpressionLambdaToSqlCallString(MethodCallExpression exp,
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})";
if (exp.Method.Name == "EndsWith") return $"locate({args0Value}, {left}) = char_length({left})-char_length({args0Value})+1";
return $"locate({args0Value}, {left}) > 0";
}
if (exp.Method.Name == "StartsWith") return $"({left}) LIKE {(args0Value.EndsWith("'") ? args0Value.Insert(args0Value.Length - 1, "%") : $"concat({args0Value}, '%')")}";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -318,9 +318,9 @@ public override string ExpressionLambdaToSqlCallString(MethodCallExpression exp,
if (args0Value == "NULL") return $"({left}) IS NULL";
if (args0Value.Contains("%"))
{
if (exp.Method.Name == "StartsWith") return $"instr({args0Value}, {left}) = 1";
if (exp.Method.Name == "EndsWith") return $"instr({args0Value}, {left}) = length({args0Value})";
return $"instr({args0Value}, {left}) > 0";
if (exp.Method.Name == "StartsWith") return $"instr({left}, {args0Value}, 1, 1) = 1";
if (exp.Method.Name == "EndsWith") return $"instr({left}, {args0Value}, 1, 1) = length({left})-length({args0Value})+1";
return $"instr({left}, {args0Value}, 1, 1) > 0";
}
if (exp.Method.Name == "StartsWith") return $"({left}) LIKE {(args0Value.EndsWith("'") ? args0Value.Insert(args0Value.Length - 1, "%") : $"(to_char({args0Value})||'%')")}";
if (exp.Method.Name == "EndsWith") return $"({left}) LIKE {(args0Value.StartsWith("'") ? args0Value.Insert(1, "%") : $"('%'||to_char({args0Value}))")}";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -385,9 +385,9 @@ public override string ExpressionLambdaToSqlCallString(MethodCallExpression exp,
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";
if (exp.Method.Name == "StartsWith") return $"strpos({left}, {args0Value}) = 1";
if (exp.Method.Name == "EndsWith") return $"strpos({left}, {args0Value}) = char_length({left})-char_length({args0Value})+1";
return $"strpos({left}, {args0Value}) > 0";
}
var likeOpt = "LIKE";
if (exp.Arguments.Count > 1)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ public override string ExpressionLambdaToSqlCallString(MethodCallExpression exp,
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})";
if (exp.Method.Name == "EndsWith") return $"locate({args0Value}, {left}) = char_length({left})-char_length({args0Value})+1";
return $"locate({args0Value}, {left}) > 0";
}
if (exp.Method.Name == "StartsWith") return $"({left}) LIKE {(args0Value.EndsWith("'") ? args0Value.Insert(args0Value.Length - 1, "%") : $"concat({args0Value}, '%')")}";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -318,9 +318,9 @@ public override string ExpressionLambdaToSqlCallString(MethodCallExpression exp,
if (args0Value == "NULL") return $"({left}) IS NULL";
if (args0Value.Contains("%"))
{
if (exp.Method.Name == "StartsWith") return $"instr({args0Value}, {left}) = 1";
if (exp.Method.Name == "EndsWith") return $"instr({args0Value}, {left}) = length({args0Value})";
return $"instr({args0Value}, {left}) > 0";
if (exp.Method.Name == "StartsWith") return $"instr({left}, {args0Value}, 1, 1) = 1";
if (exp.Method.Name == "EndsWith") return $"instr({left}, {args0Value}, 1, 1) = length({left})-length({args0Value})+1";
return $"instr({left}, {args0Value}, 1, 1) > 0";
}
if (exp.Method.Name == "StartsWith") return $"({left}) LIKE {(args0Value.EndsWith("'") ? args0Value.Insert(args0Value.Length - 1, "%") : $"(to_char({args0Value})||'%')")}";
if (exp.Method.Name == "EndsWith") return $"({left}) LIKE {(args0Value.StartsWith("'") ? args0Value.Insert(1, "%") : $"('%'||to_char({args0Value}))")}";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -407,9 +407,9 @@ public override string ExpressionLambdaToSqlCallString(MethodCallExpression exp,
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";
if (exp.Method.Name == "StartsWith") return $"strpos({left}, {args0Value}) = 1";
if (exp.Method.Name == "EndsWith") return $"strpos({left}, {args0Value}) = char_length({left})-char_length({args0Value})+1";
return $"strpos({left}, {args0Value}) > 0";
}
var likeOpt = "LIKE";
if (exp.Arguments.Count > 1)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ public override string ExpressionLambdaToSqlCallString(MethodCallExpression exp,
if (args0Value.Contains("%"))
{
if (exp.Method.Name == "StartsWith") return $"charindex({args0Value}, {left}) = 1";
if (exp.Method.Name == "EndsWith") return $"charindex({args0Value}, {left}) = len({args0Value})";
if (exp.Method.Name == "EndsWith") return $"charindex({args0Value}, {left}) = len({left})-len({args0Value})+1";
return $"charindex({args0Value}, {left}) > 0";
}
if (exp.Method.Name == "StartsWith") return $"({left}) LIKE {(args0Value.EndsWith("'") ? args0Value.Insert(args0Value.Length - 1, "%") : $"(cast({args0Value} as nvarchar(max))+'%')")}";
Expand Down
6 changes: 3 additions & 3 deletions Providers/FreeSql.Provider.Oracle/OracleExpression.cs
Original file line number Diff line number Diff line change
Expand Up @@ -318,9 +318,9 @@ public override string ExpressionLambdaToSqlCallString(MethodCallExpression exp,
if (args0Value == "NULL") return $"({left}) IS NULL";
if (args0Value.Contains("%"))
{
if (exp.Method.Name == "StartsWith") return $"instr({args0Value}, {left}) = 1";
if (exp.Method.Name == "EndsWith") return $"instr({args0Value}, {left}) = length({args0Value})";
return $"instr({args0Value}, {left}) > 0";
if (exp.Method.Name == "StartsWith") return $"instr({left}, {args0Value}, 1, 1) = 1";
if (exp.Method.Name == "EndsWith") return $"instr({left}, {args0Value}, 1, 1) = length({left})-length({args0Value})+1";
return $"instr({left}, {args0Value}, 1, 1) > 0";
}
if (exp.Method.Name == "StartsWith") return $"({left}) LIKE {(args0Value.EndsWith("'") ? args0Value.Insert(args0Value.Length - 1, "%") : $"(to_char({args0Value})||'%')")}";
if (exp.Method.Name == "EndsWith") return $"({left}) LIKE {(args0Value.StartsWith("'") ? args0Value.Insert(1, "%") : $"('%'||to_char({args0Value}))")}";
Expand Down
6 changes: 3 additions & 3 deletions Providers/FreeSql.Provider.PostgreSQL/PostgreSQLExpression.cs
Original file line number Diff line number Diff line change
Expand Up @@ -438,9 +438,9 @@ public override string ExpressionLambdaToSqlCallString(MethodCallExpression exp,
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";
if (exp.Method.Name == "StartsWith") return $"strpos({left}, {args0Value}) = 1";
if (exp.Method.Name == "EndsWith") return $"strpos({left}, {args0Value}) = char_length({left})-char_length({args0Value})+1";
return $"strpos({left}, {args0Value}) > 0";
}
var likeOpt = "LIKE";
if (exp.Arguments.Count > 1)
Expand Down
7 changes: 3 additions & 4 deletions Providers/FreeSql.Provider.QuestDb/QuestDbExpression.cs
Original file line number Diff line number Diff line change
Expand Up @@ -345,10 +345,9 @@ public override string ExpressionLambdaToSqlCallString(MethodCallExpression exp,
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}) = length({args0Value})";
return $"strpos({args0Value}, {left}) > 0";
if (exp.Method.Name == "StartsWith") return $"strpos({left}, {args0Value}) = 1";
if (exp.Method.Name == "EndsWith") return $"strpos({left}, {args0Value}) = length({left})-length({args0Value})+1";
return $"strpos({left}, {args0Value}) > 0";
}

var likeOpt = "LIKE";
Expand Down
Loading

0 comments on commit 20b8824

Please sign in to comment.