mirror of
https://github.com/nsnail/FreeSql.git
synced 2025-04-22 18:52:50 +08:00
- 优化 Firebird 表达式树位运算的适配解析;#1413
This commit is contained in:
parent
b5c62ebb7c
commit
8d8926d8e2
@ -639,9 +639,15 @@ namespace FreeSql.Internal
|
||||
|
||||
static readonly Dictionary<ExpressionType, string> dicExpressionOperator = new Dictionary<ExpressionType, string>() {
|
||||
{ ExpressionType.OrElse, "OR" },
|
||||
{ ExpressionType.Or, "|" },
|
||||
{ ExpressionType.AndAlso, "AND" },
|
||||
|
||||
{ ExpressionType.Or, "|" },
|
||||
{ ExpressionType.And, "&" },
|
||||
{ ExpressionType.LeftShift, "<<" },
|
||||
{ ExpressionType.RightShift, ">>" },
|
||||
{ ExpressionType.ExclusiveOr, "^" },
|
||||
{ ExpressionType.Not, "^" },
|
||||
|
||||
{ ExpressionType.GreaterThan, ">" },
|
||||
{ ExpressionType.GreaterThanOrEqual, ">=" },
|
||||
{ ExpressionType.LessThan, "<" },
|
||||
@ -754,8 +760,6 @@ namespace FreeSql.Internal
|
||||
switch (oper)
|
||||
{
|
||||
case "OR":
|
||||
case "|":
|
||||
case "&":
|
||||
case "+":
|
||||
case "-":
|
||||
if (oper == "+" && (leftExp.Type == typeof(string) || rightExp.Type == typeof(string)))
|
||||
@ -918,7 +922,7 @@ namespace FreeSql.Internal
|
||||
{
|
||||
case ExpressionType.Not:
|
||||
var notExp = (exp as UnaryExpression)?.Operand;
|
||||
if (notExp.Type.IsNumberType()) return $"~{ExpressionLambdaToSql(notExp, tsc)}"; //位操作
|
||||
if (notExp.Type.IsNumberType())return _common.BitNot(ExpressionLambdaToSql(notExp, tsc)); //位操作
|
||||
if (notExp.NodeType == ExpressionType.MemberAccess)
|
||||
{
|
||||
var notBody = ExpressionLambdaToSql(notExp, tsc);
|
||||
@ -2019,6 +2023,11 @@ namespace FreeSql.Internal
|
||||
{
|
||||
case ExpressionType.Coalesce:
|
||||
return _common.IsNull(ExpressionLambdaToSql(expBinary.Left, tsc), ExpressionLambdaToSql(expBinary.Right, tsc));
|
||||
case ExpressionType.And: return _common.BitAnd(ExpressionLambdaToSql(expBinary.Left, tsc), ExpressionLambdaToSql(expBinary.Right, tsc));
|
||||
case ExpressionType.Or: return _common.BitOr(ExpressionLambdaToSql(expBinary.Left, tsc), ExpressionLambdaToSql(expBinary.Right, tsc));
|
||||
case ExpressionType.LeftShift: return _common.BitShiftLeft(ExpressionLambdaToSql(expBinary.Left, tsc), ExpressionLambdaToSql(expBinary.Right, tsc));
|
||||
case ExpressionType.RightShift: return _common.BitShiftRight(ExpressionLambdaToSql(expBinary.Left, tsc), ExpressionLambdaToSql(expBinary.Right, tsc));
|
||||
case ExpressionType.ExclusiveOr: return _common.BitXor(ExpressionLambdaToSql(expBinary.Left, tsc), ExpressionLambdaToSql(expBinary.Right, tsc));
|
||||
}
|
||||
if (dicExpressionOperator.TryGetValue(expBinary.NodeType, out var tryoper) == false)
|
||||
{
|
||||
|
@ -57,6 +57,12 @@ namespace FreeSql.Internal
|
||||
public abstract string StringConcat(string[] objs, Type[] types);
|
||||
public abstract string Mod(string left, string right, Type leftType, Type rightType);
|
||||
public abstract string Div(string left, string right, Type leftType, Type rightType);
|
||||
public virtual string BitAnd(string left, string right) => $"({left} & {right})";
|
||||
public virtual string BitOr(string left, string right) => $"({left} | {right})";
|
||||
public virtual string BitShiftLeft(string left, string right) => $"({left} << {right})";
|
||||
public virtual string BitShiftRight(string left, string right) => $"({left} >> {right})";
|
||||
public virtual string BitNot(string left) => $"~{left}";
|
||||
public virtual string BitXor(string left, string right) => $"({left} ^ {right})";
|
||||
public abstract string Now { get; }
|
||||
public abstract string NowUtc { get; }
|
||||
public abstract string QuoteWriteParamterAdapter(Type type, string paramterName);
|
||||
|
Loading…
x
Reference in New Issue
Block a user