Synchronization code

This commit is contained in:
sunkaixuan 2022-11-26 22:58:45 +08:00
parent 8b34736457
commit a3e182fb4c
7 changed files with 64 additions and 1 deletions

View File

@ -559,5 +559,21 @@ namespace SqlSugar
}
return false;
}
internal static bool IsIsNullSubQuery(Expression it)
{
if (it is MethodCallExpression)
{
var method = (MethodCallExpression)it;
if (method.Method.Name == "IsNull")
{
if (method.Arguments.Count==2&&IsSubQuery(method.Arguments[0]))
{
return true;
}
}
}
return false;
}
}
}

View File

@ -664,10 +664,21 @@ namespace SqlSugar
{
throw new NotImplementedException("Current database no support");
}
public string JsonLike(MethodCallExpressionModel model)
public virtual string JsonLike(MethodCallExpressionModel model)
{
model.Args[0].MemberName = ToString(model);
return Contains(model);
}
public virtual string Collate(MethodCallExpressionModel model)
{
var name=model.Args[0].MemberName;
return $" {name} collate Chinese_PRC_CS_AS ";
}
public virtual string AggregateSumNoNull(MethodCallExpressionModel model)
{
model.Args[0].MemberName = AggregateSum(model);
model.Args.Add(new MethodCallExpressionArgs() { MemberValue = 0, MemberName = 0 });
return IsNull(model);
}
}
}

View File

@ -98,5 +98,7 @@ namespace SqlSugar
string JsonArrayLength(MethodCallExpressionModel model);
string JsonParse(MethodCallExpressionModel model);
string JsonLike(MethodCallExpressionModel model);
string Collate(MethodCallExpressionModel model);
string AggregateSumNoNull(MethodCallExpressionModel model);
}
}

View File

@ -221,6 +221,8 @@ namespace SqlSugar
public static string Replace(object value, string oldChar, string newChar) { return value.ObjToString().Replace(oldChar, newChar); }
public static int Length(object value) { return value.ObjToString().Length; }
public static TResult AggregateSum<TResult>(TResult thisValue) { throw new NotSupportedException("Can only be used in expressions"); }
public static TResult AggregateSumNoNull<TResult>(TResult thisValue) { throw new NotSupportedException("Can only be used in expressions"); }
public static string Collate(string thisValue) { throw new NotSupportedException("Can only be used in expressions"); }
public static TResult AggregateAvg<TResult>(TResult thisValue) { throw new NotSupportedException("Can only be used in expressions"); }
public static TResult AggregateMin<TResult>(TResult thisValue) { throw new NotSupportedException("Can only be used in expressions"); }
public static TResult AggregateMax<TResult>(TResult thisValue) { throw new NotSupportedException("Can only be used in expressions"); }

View File

@ -116,6 +116,22 @@ namespace SqlSugar
}
}
}
else if (this.Context.IsSingle && args.Any(it => ExpressionTool.IsIsNullSubQuery(it)) )
{
var exp = base.BaseParameter?.BaseParameter?.BaseParameter?.CurrentExpression;
if (exp is LambdaExpression)
{
SetShortName(exp);
}
else if (exp is UnaryExpression)
{
exp = base.BaseParameter?.BaseParameter?.BaseParameter?.BaseParameter?.CurrentExpression;
if (exp is LambdaExpression)
{
SetShortName(exp);
}
}
}
var isBinaryExpression = item is BinaryExpression || item is MethodCallExpression;
var isConst = item is ConstantExpression;
var isIIF = name == "IIF";
@ -732,6 +748,10 @@ namespace SqlSugar
return this.Context.DbMehtods.JsonParse(model);
case "JsonLike":
return this.Context.DbMehtods.JsonLike(model);
case "Collate":
return this.Context.DbMehtods.Collate(model);
case "AggregateSumNoNull":
return this.Context.DbMehtods.AggregateSumNoNull(model);
default:
break;
}

View File

@ -176,6 +176,12 @@ namespace SqlSugar
return "rand()";
}
public override string Collate(MethodCallExpressionModel model)
{
var name = model.Args[0].MemberName;
return $" binary {name} ";
}
public override string CharIndex(MethodCallExpressionModel model)
{
return string.Format("instr ({0},{1})", model.Args[0].MemberName, model.Args[1].MemberName);

View File

@ -296,6 +296,12 @@ namespace SqlSugar
return "dbms_random.value";
}
public override string Collate(MethodCallExpressionModel model)
{
var name = model.Args[0].MemberName;
return $" NLSSORT({0}, 'NLS_SORT = Latin_CI') ";
}
public override string CharIndex(MethodCallExpressionModel model)
{
return string.Format("instr ({0},{1},1,1) ", model.Args[0].MemberName, model.Args[1].MemberName);