Browse Source

-

pull/12/MERGE
sunkaixuan 7 years ago
parent
commit
9101915aab
  1. 20
      Src/Asp.Net/SqlServerTest/UnitTest/ExpressionTest/Method.cs
  2. 4
      Src/Asp.Net/SqlSugar/ExpressionsToSql/Method/DefaultDbMethod.cs
  3. 16
      Src/Asp.Net/SqlSugar/ExpressionsToSql/ResolveItems/MethodCallExpressionResolve.cs
  4. 4
      Src/Asp.Net/SqlSugar/Realization/MySql/SqlBuilder/MySqlExpressionContext.cs

20
Src/Asp.Net/SqlServerTest/UnitTest/ExpressionTest/Method.cs

@ -363,9 +363,9 @@ namespace OrmTest.UnitTest
expContext.Resolve(exp, ResolveExpressType.WhereSingle); expContext.Resolve(exp, ResolveExpressType.WhereSingle);
var value = expContext.Result.GetString(); var value = expContext.Result.GetString();
var pars = expContext.Parameters; var pars = expContext.Parameters;
base.Check(value, pars, "((DATEADD(@MethodConst2,@MethodConst1,@MethodConst0)) = @Const3 )", new List<SugarParameter>() { base.Check(value, pars, "((DATEADD(Millisecond,@MethodConst1,@MethodConst0)) = @Const3 )", new List<SugarParameter>() {
new SugarParameter("@MethodConst0",x2),new SugarParameter("@MethodConst1",11),new SugarParameter("@Const3",x2), new SugarParameter("@MethodConst0",x2),new SugarParameter("@MethodConst1",11),new SugarParameter("@Const3",x2)
new SugarParameter("@MethodConst2",DateType.Millisecond)
}, "DateAddByType error"); }, "DateAddByType error");
} }
private void DateAddDay() private void DateAddDay()
@ -392,8 +392,8 @@ namespace OrmTest.UnitTest
expContext.Resolve(exp, ResolveExpressType.WhereSingle); expContext.Resolve(exp, ResolveExpressType.WhereSingle);
var value = expContext.Result.GetString(); var value = expContext.Result.GetString();
var pars = expContext.Parameters; var pars = expContext.Parameters;
base.Check(value, pars, "((DATEADD(@Const0,@MethodConst1,[Datetime2])) = @Const2 )", new List<SugarParameter>() { base.Check(value, pars, "((DATEADD(Hour,@MethodConst1,[Datetime2])) = @Const2 )", new List<SugarParameter>() {
new SugarParameter("@Const0",DateType.Hour.ToString()),new SugarParameter("@MethodConst1",10) new SugarParameter("@MethodConst1",10)
,new SugarParameter("@Const2",x2) ,new SugarParameter("@Const2",x2)
}, "DateAddDay2 error"); }, "DateAddDay2 error");
} }
@ -406,8 +406,9 @@ namespace OrmTest.UnitTest
expContext.Resolve(exp, ResolveExpressType.WhereSingle); expContext.Resolve(exp, ResolveExpressType.WhereSingle);
var value = expContext.Result.GetString(); var value = expContext.Result.GetString();
var pars = expContext.Parameters; var pars = expContext.Parameters;
base.Check(value, pars, "((DATEADD(@Const0,@MethodConst2,@MethodConst1)) = @Const3 )", new List<SugarParameter>() { base.Check(value, pars, "((DATEADD(Hour,@MethodConst2,@MethodConst1)) = @Const3 )", new List<SugarParameter>() {
new SugarParameter("@Const0",DateType.Hour.ToString()),new SugarParameter("@MethodConst2",1),new SugarParameter("@MethodConst1",x2) new SugarParameter("@MethodConst2",1),
new SugarParameter("@MethodConst1",x2)
,new SugarParameter("@Const3",x2) ,new SugarParameter("@Const3",x2)
}, "DateAddDay3 error"); }, "DateAddDay3 error");
} }
@ -420,9 +421,8 @@ namespace OrmTest.UnitTest
expContext.Resolve(exp, ResolveExpressType.WhereSingle); expContext.Resolve(exp, ResolveExpressType.WhereSingle);
var value = expContext.Result.GetString(); var value = expContext.Result.GetString();
var pars = expContext.Parameters; var pars = expContext.Parameters;
base.Check(value, pars, " (DATEDIFF(@MethodConst2,@MethodConst0,@MethodConst1)=0) ", new List<SugarParameter>() { base.Check(value, pars, " (DATEDIFF(Millisecond,@MethodConst0,@MethodConst1)=0) ", new List<SugarParameter>() {
new SugarParameter("@MethodConst0",x2),new SugarParameter("@MethodConst1",x2), new SugarParameter("@MethodConst0",x2),new SugarParameter("@MethodConst1",x2)
new SugarParameter("@MethodConst2",DateType.Millisecond)
}, "DateIsSameByType error"); }, "DateIsSameByType error");
} }
private void DateIsSameByDay() private void DateIsSameByDay()

4
Src/Asp.Net/SqlSugar/ExpressionsToSql/Method/DefaultDbMethod.cs

@ -109,7 +109,7 @@ namespace SqlSugar
var parameter = model.Args[0]; var parameter = model.Args[0];
var parameter2 = model.Args[1]; var parameter2 = model.Args[1];
var parameter3 = model.Args[2]; var parameter3 = model.Args[2];
return string.Format(" (DATEDIFF({2},{0},{1})=0) ", parameter.MemberName, parameter2.MemberName, parameter3.MemberName); return string.Format(" (DATEDIFF({2},{0},{1})=0) ", parameter.MemberName, parameter2.MemberName, parameter3.MemberValue);
} }
public virtual string DateAddByType(MethodCallExpressionModel model) public virtual string DateAddByType(MethodCallExpressionModel model)
@ -117,7 +117,7 @@ namespace SqlSugar
var parameter = model.Args[0]; var parameter = model.Args[0];
var parameter2 = model.Args[1]; var parameter2 = model.Args[1];
var parameter3 = model.Args[2]; var parameter3 = model.Args[2];
return string.Format(" (DATEADD({2},{1},{0})) ", parameter.MemberName, parameter2.MemberName, parameter3.MemberName); return string.Format(" (DATEADD({2},{1},{0})) ", parameter.MemberName, parameter2.MemberName, parameter3.MemberValue);
} }
public virtual string DateAddDay(MethodCallExpressionModel model) public virtual string DateAddDay(MethodCallExpressionModel model)

16
Src/Asp.Net/SqlSugar/ExpressionsToSql/ResolveItems/MethodCallExpressionResolve.cs

@ -215,21 +215,29 @@ namespace SqlSugar
case "Contains": case "Contains":
return this.Context.DbMehtods.Contains(model); return this.Context.DbMehtods.Contains(model);
case "ContainsArray": case "ContainsArray":
var result = this.Context.DbMehtods.ContainsArray(model); var caResult = this.Context.DbMehtods.ContainsArray(model);
this.Context.Parameters.RemoveAll(it => it.ParameterName == model.Args[0].MemberName.ObjToString()); this.Context.Parameters.RemoveAll(it => it.ParameterName == model.Args[0].MemberName.ObjToString());
return result; return caResult;
case "Equals": case "Equals":
return this.Context.DbMehtods.Equals(model); return this.Context.DbMehtods.Equals(model);
case "DateIsSame": case "DateIsSame":
if (model.Args.Count == 2) if (model.Args.Count == 2)
return this.Context.DbMehtods.DateIsSameDay(model); return this.Context.DbMehtods.DateIsSameDay(model);
else else
return this.Context.DbMehtods.DateIsSameByType(model); {
var dsResult=this.Context.DbMehtods.DateIsSameByType(model);
this.Context.Parameters.RemoveAll(it => it.ParameterName == model.Args[2].MemberName.ObjToString());
return dsResult;
}
case "DateAdd": case "DateAdd":
if (model.Args.Count == 2) if (model.Args.Count == 2)
return this.Context.DbMehtods.DateAddDay(model); return this.Context.DbMehtods.DateAddDay(model);
else else
return this.Context.DbMehtods.DateAddByType(model); {
var daResult=this.Context.DbMehtods.DateAddByType(model);
this.Context.Parameters.RemoveAll(it => it.ParameterName == model.Args[2].MemberName.ObjToString());
return daResult;
}
case "DateValue": case "DateValue":
return this.Context.DbMehtods.DateValue(model); return this.Context.DbMehtods.DateValue(model);
case "Between": case "Between":

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

@ -88,7 +88,7 @@ namespace SqlSugar
var parameter = model.Args[0]; var parameter = model.Args[0];
var parameter2 = model.Args[1]; var parameter2 = model.Args[1];
var parameter3 = model.Args[2]; var parameter3 = model.Args[2];
return string.Format(" (TIMESTAMPDIFF({2},{0},{1})=0) ", parameter.MemberName, parameter2.MemberName, parameter3.MemberName); return string.Format(" (TIMESTAMPDIFF({2},{0},{1})=0) ", parameter.MemberName, parameter2.MemberName, parameter3.MemberValue);
} }
public override string DateAddByType(MethodCallExpressionModel model) public override string DateAddByType(MethodCallExpressionModel model)
@ -96,7 +96,7 @@ namespace SqlSugar
var parameter = model.Args[0]; var parameter = model.Args[0];
var parameter2 = model.Args[1]; var parameter2 = model.Args[1];
var parameter3 = model.Args[2]; var parameter3 = model.Args[2];
return string.Format(" (DATE_ADD({1} INTERVAL {2} {0})) ", parameter.MemberName, parameter2.MemberName, parameter3.MemberName); return string.Format(" (DATE_ADD({1} INTERVAL {2} {0})) ", parameter.MemberName, parameter2.MemberName, parameter3.MemberValue);
} }
public override string DateAddDay(MethodCallExpressionModel model) public override string DateAddDay(MethodCallExpressionModel model)

Loading…
Cancel
Save