mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-05-18 14:09:34 +08:00
Update exp to sql
This commit is contained in:
parent
d047a4fe58
commit
96f58fba8c
@ -8,6 +8,13 @@ namespace SqlSugar
|
|||||||
{
|
{
|
||||||
public class ExpressionTool
|
public class ExpressionTool
|
||||||
{
|
{
|
||||||
|
public static bool IsComparisonOperatorBool(BinaryExpression binaryExp)
|
||||||
|
{
|
||||||
|
return binaryExp.NodeType.IsIn(ExpressionType.Equal,
|
||||||
|
ExpressionType.GreaterThan, ExpressionType.GreaterThanOrEqual,
|
||||||
|
ExpressionType.LessThan, ExpressionType.LessThanOrEqual);
|
||||||
|
}
|
||||||
|
|
||||||
public static string GetOperator(ExpressionType expressiontype)
|
public static string GetOperator(ExpressionType expressiontype)
|
||||||
{
|
{
|
||||||
switch (expressiontype)
|
switch (expressiontype)
|
||||||
|
@ -362,6 +362,15 @@ namespace SqlSugar
|
|||||||
{
|
{
|
||||||
return "( 1 = 2 ) ";
|
return "( 1 = 2 ) ";
|
||||||
}
|
}
|
||||||
|
public virtual string TrueValue()
|
||||||
|
{
|
||||||
|
return "1 ";
|
||||||
|
}
|
||||||
|
|
||||||
|
public virtual string FalseValue()
|
||||||
|
{
|
||||||
|
return "0";
|
||||||
|
}
|
||||||
|
|
||||||
public string GuidNew()
|
public string GuidNew()
|
||||||
{
|
{
|
||||||
|
@ -58,6 +58,8 @@ namespace SqlSugar
|
|||||||
string GetSelfAndAutoFill(string shortName,bool isSingle);
|
string GetSelfAndAutoFill(string shortName,bool isSingle);
|
||||||
string True();
|
string True();
|
||||||
string False();
|
string False();
|
||||||
|
string TrueValue();
|
||||||
|
string FalseValue();
|
||||||
string GuidNew();
|
string GuidNew();
|
||||||
string MergeString(params string[] strings);
|
string MergeString(params string[] strings);
|
||||||
string EqualTrue(string value);
|
string EqualTrue(string value);
|
||||||
|
@ -416,7 +416,15 @@ namespace SqlSugar
|
|||||||
}
|
}
|
||||||
if (isRoot && parameter.BaseExpression == null && this.Context.ResolveType.IsIn(ResolveExpressType.WhereMultiple, ResolveExpressType.WhereSingle) && (parameter.CurrentExpression is ConditionalExpression) && ((parameter.CurrentExpression as ConditionalExpression).Type == UtilConstants.BoolType))
|
if (isRoot && parameter.BaseExpression == null && this.Context.ResolveType.IsIn(ResolveExpressType.WhereMultiple, ResolveExpressType.WhereSingle) && (parameter.CurrentExpression is ConditionalExpression) && ((parameter.CurrentExpression as ConditionalExpression).Type == UtilConstants.BoolType))
|
||||||
{
|
{
|
||||||
methodValue = methodValue + "=1 ";
|
var isContainsTrue = MethodValueIsTrue(methodValue);
|
||||||
|
if (isContainsTrue)
|
||||||
|
{
|
||||||
|
methodValue = methodValue + "=true ";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
methodValue = methodValue + "=1 ";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (isRoot && parameter.BaseExpression == null && this.Context.ResolveType.IsIn(ResolveExpressType.WhereMultiple, ResolveExpressType.WhereSingle) && (parameter.CurrentExpression is MethodCallExpression) && ((parameter.CurrentExpression as MethodCallExpression).Method.Name.IsIn("IIF")) && (parameter.CurrentExpression as MethodCallExpression).Method.ReturnType == UtilConstants.BoolType)
|
if (isRoot && parameter.BaseExpression == null && this.Context.ResolveType.IsIn(ResolveExpressType.WhereMultiple, ResolveExpressType.WhereSingle) && (parameter.CurrentExpression is MethodCallExpression) && ((parameter.CurrentExpression as MethodCallExpression).Method.Name.IsIn("IIF")) && (parameter.CurrentExpression as MethodCallExpression).Method.ReturnType == UtilConstants.BoolType)
|
||||||
{
|
{
|
||||||
@ -437,6 +445,11 @@ namespace SqlSugar
|
|||||||
base.AppendValue(parameter, isLeft, methodValue);
|
base.AppendValue(parameter, isLeft, methodValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static bool MethodValueIsTrue(object methodValue)
|
||||||
|
{
|
||||||
|
return methodValue != null && methodValue.ToString().Contains("THEN true ELSE false END");
|
||||||
|
}
|
||||||
|
|
||||||
private object packIfElse(object methodValue)
|
private object packIfElse(object methodValue)
|
||||||
{
|
{
|
||||||
methodValue = this.Context.DbMehtods.CaseWhen(new List<KeyValuePair<string, string>>() {
|
methodValue = this.Context.DbMehtods.CaseWhen(new List<KeyValuePair<string, string>>() {
|
||||||
@ -485,7 +498,41 @@ namespace SqlSugar
|
|||||||
}
|
}
|
||||||
else if (isIFFBoolBinary && !isFirst)
|
else if (isIFFBoolBinary && !isFirst)
|
||||||
{
|
{
|
||||||
AppendModelByIIFBinary(parameter, model, item);
|
var binaryExp = item as BinaryExpression;
|
||||||
|
var binaryExpEqual = binaryExp != null && ExpressionTool.IsComparisonOperatorBool(binaryExp);
|
||||||
|
if (binaryExpEqual)
|
||||||
|
{
|
||||||
|
var expValue = GetNewExpressionValue(item);
|
||||||
|
expValue= this.Context.DbMehtods.IIF(new MethodCallExpressionModel()
|
||||||
|
{
|
||||||
|
Name = "IIF",
|
||||||
|
Args = new List<MethodCallExpressionArgs>()
|
||||||
|
{
|
||||||
|
new MethodCallExpressionArgs(){
|
||||||
|
IsMember=true,
|
||||||
|
MemberName=expValue
|
||||||
|
},
|
||||||
|
new MethodCallExpressionArgs(){
|
||||||
|
IsMember=true,
|
||||||
|
MemberName= Context.DbMehtods.TrueValue()
|
||||||
|
},
|
||||||
|
new MethodCallExpressionArgs(){
|
||||||
|
IsMember=true,
|
||||||
|
MemberName= Context.DbMehtods.FalseValue()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
model.Args.Add(new MethodCallExpressionArgs()
|
||||||
|
{
|
||||||
|
IsMember = false,
|
||||||
|
MemberName = expValue,
|
||||||
|
MemberValue = expValue
|
||||||
|
});
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
AppendModelByIIFBinary(parameter, model, item);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
else if (isIFFBoolMethod && !isFirst)
|
else if (isIFFBoolMethod && !isFirst)
|
||||||
@ -522,7 +569,6 @@ namespace SqlSugar
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private void AppendModelByIIFMember(ExpressionParameter parameter, MethodCallExpressionModel model, Expression item)
|
private void AppendModelByIIFMember(ExpressionParameter parameter, MethodCallExpressionModel model, Expression item)
|
||||||
{
|
{
|
||||||
parameter.CommonTempData = CommonTempDataType.Result;
|
parameter.CommonTempData = CommonTempDataType.Result;
|
||||||
|
@ -133,6 +133,14 @@ namespace SqlSugar
|
|||||||
}
|
}
|
||||||
public class PostgreSQLMethod : DefaultDbMethod, IDbMethods
|
public class PostgreSQLMethod : DefaultDbMethod, IDbMethods
|
||||||
{
|
{
|
||||||
|
public override string TrueValue()
|
||||||
|
{
|
||||||
|
return "true";
|
||||||
|
}
|
||||||
|
public override string FalseValue()
|
||||||
|
{
|
||||||
|
return "false";
|
||||||
|
}
|
||||||
public override string DateDiff(MethodCallExpressionModel model)
|
public override string DateDiff(MethodCallExpressionModel model)
|
||||||
{
|
{
|
||||||
var parameter = (DateType)(Enum.Parse(typeof(DateType), model.Args[0].MemberValue.ObjToString()));
|
var parameter = (DateType)(Enum.Parse(typeof(DateType), model.Args[0].MemberValue.ObjToString()));
|
||||||
|
Loading…
Reference in New Issue
Block a user