Browse Source

Update exp to sql

pull/25/head
sunkaixuan 2 years ago
parent
commit
7b6f844c48
  1. 11
      Src/Asp.Net/SqlSugar/ExpressionsToSql/DbMethods/DefaultDbMethod.cs
  2. 16
      Src/Asp.Net/SqlSugar/Realization/MySql/SqlBuilder/MySqlExpressionContext.cs

11
Src/Asp.Net/SqlSugar/ExpressionsToSql/DbMethods/DefaultDbMethod.cs

@ -3,6 +3,7 @@ using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace SqlSugar namespace SqlSugar
{ {
@ -510,8 +511,14 @@ namespace SqlSugar
public virtual string Format(MethodCallExpressionModel model) public virtual string Format(MethodCallExpressionModel model)
{ {
var str = model.Args[0].MemberValue.ObjToString();
var array = model.Args.Skip(1).Select(it => it.IsMember?it.MemberName:it.MemberValue).ToArray(); var str ="'"+ model.Args[0].MemberValue.ObjToString()+"'";
var revalue = MergeString("'", "$1", "'");
str =Regex.Replace(str, @"(\{\d+?\})", revalue);
var array = model.Args.Skip(1).Select(it => it.IsMember?it.MemberName:it.MemberValue)
.Select(it=>ToString(new MethodCallExpressionModel() { Args=new List<MethodCallExpressionArgs>() {
new MethodCallExpressionArgs(){ IsMember=true, MemberName=it }
} })).ToArray();
return string.Format(""+str+ "", array); return string.Format(""+str+ "", array);
} }

16
Src/Asp.Net/SqlSugar/Realization/MySql/SqlBuilder/MySqlExpressionContext.cs

@ -1,5 +1,8 @@
using System; using System;
using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text.RegularExpressions;
namespace SqlSugar namespace SqlSugar
{ {
public class MySqlExpressionContext : ExpressionContext, ILambdaExpressions public class MySqlExpressionContext : ExpressionContext, ILambdaExpressions
@ -66,7 +69,20 @@ namespace SqlSugar
var parameter2 = model.Args[1]; var parameter2 = model.Args[1];
return string.Format(" (TIMESTAMPDIFF(day,date({0}),date({1}))=0) ", parameter.MemberName, parameter2.MemberName); ; return string.Format(" (TIMESTAMPDIFF(day,date({0}),date({1}))=0) ", parameter.MemberName, parameter2.MemberName); ;
} }
public virtual string Format(MethodCallExpressionModel model)
{
var str = "concat('" + model.Args[0].MemberValue.ObjToString() + "')";
str = Regex.Replace(str, @"(\{\d+?\})", "',$1,'");
var array = model.Args.Skip(1).Select(it => it.IsMember ? it.MemberName : it.MemberValue)
.Select(it => ToString(new MethodCallExpressionModel()
{
Args = new List<MethodCallExpressionArgs>() {
new MethodCallExpressionArgs(){ IsMember=true, MemberName=it }
}
})).ToArray();
return string.Format("" + str + "", array);
}
public override string DateIsSameByType(MethodCallExpressionModel model) public override string DateIsSameByType(MethodCallExpressionModel model)
{ {
var parameter = model.Args[0]; var parameter = model.Args[0];

Loading…
Cancel
Save