Browse Source

Add SqlFunc.WeekOfYear

pull/40/head
sunkaixuan 1 year ago
parent
commit
b313b3680e
  1. 6
      Src/Asp.NetCore2/SqlSugar/ExpressionsToSql/DbMethods/DefaultDbMethod.cs
  2. 1
      Src/Asp.NetCore2/SqlSugar/ExpressionsToSql/DbMethods/IDbMethods.cs
  3. 4
      Src/Asp.NetCore2/SqlSugar/ExpressionsToSql/DbMethods/SqlFunc.cs
  4. 4
      Src/Asp.NetCore2/SqlSugar/ExpressionsToSql/ResolveItems/MethodCallExpressionResolve_Helper.cs
  5. 5
      Src/Asp.NetCore2/SqlSugar/Realization/Dm/SqlBuilder/DmExpressionContext.cs
  6. 5
      Src/Asp.NetCore2/SqlSugar/Realization/MySql/SqlBuilder/MySqlExpressionContext.cs
  7. 5
      Src/Asp.NetCore2/SqlSugar/Realization/Oracle/SqlBuilder/OracleExpressionContext.cs
  8. 5
      Src/Asp.NetCore2/SqlSugar/Realization/SqlServer/SqlBuilder/SqlServerExpressionContext.cs
  9. 5
      Src/Asp.NetCore2/SqlSugar/Realization/Sqlite/SqlBuilder/SqliteExpressionContext.cs

6
Src/Asp.NetCore2/SqlSugar/ExpressionsToSql/DbMethods/DefaultDbMethod.cs

@ -968,5 +968,11 @@ namespace SqlSugar
return result;
}
}
public virtual string WeekOfYear(MethodCallExpressionModel mode)
{
var parameterNameA = mode.Args[0].MemberName;
return $" DATE_PART('week', {parameterNameA}) ";
}
}
}

1
Src/Asp.NetCore2/SqlSugar/ExpressionsToSql/DbMethods/IDbMethods.cs

@ -113,5 +113,6 @@ namespace SqlSugar
string Modulo(MethodCallExpressionModel mode);
string Like(MethodCallExpressionModel mode);
string ToSingle(MethodCallExpressionModel mode);
string WeekOfYear(MethodCallExpressionModel mode);
}
}

4
Src/Asp.NetCore2/SqlSugar/ExpressionsToSql/DbMethods/SqlFunc.cs

@ -9,6 +9,10 @@ namespace SqlSugar
{
public partial class SqlFunc
{
public static int WeekOfYear(DateTime fieldName)
{
throw new NotSupportedException("Can only be used in expressions");
}
public static bool Like(string fieldName, string likeValue)
{
throw new NotSupportedException("Can only be used in expressions");

4
Src/Asp.NetCore2/SqlSugar/ExpressionsToSql/ResolveItems/MethodCallExpressionResolve_Helper.cs

@ -855,6 +855,10 @@ namespace SqlSugar
case "ToSingle":
return this.Context.DbMehtods.ToSingle(model);
default:
if (typeof(IDbMethods).GetMethods().Any(it => it.Name == name))
{
return this.Context.DbMehtods.GetType().GetMethod(name).Invoke(this.Context.DbMehtods,new object[] { model});
}
break;
}
}

5
Src/Asp.NetCore2/SqlSugar/Realization/Dm/SqlBuilder/DmExpressionContext.cs

@ -54,6 +54,11 @@ namespace SqlSugar
}
public partial class DmMethod : DefaultDbMethod, IDbMethods
{
public override string WeekOfYear(MethodCallExpressionModel mode)
{
var parameterNameA = mode.Args[0].MemberName;
return $"TO_NUMBER(TO_CHAR({parameterNameA}, 'WW')) ";
}
public override string ParameterKeyWord { get; set; } = ":";
public override string GetStringJoinSelector(string result, string separator)
{

5
Src/Asp.NetCore2/SqlSugar/Realization/MySql/SqlBuilder/MySqlExpressionContext.cs

@ -17,6 +17,11 @@ namespace SqlSugar
}
public class MySqlMethod : DefaultDbMethod, IDbMethods
{
public override string WeekOfYear(MethodCallExpressionModel mode)
{
var parameterNameA = mode.Args[0].MemberName;
return $" WEEK({parameterNameA}) ";
}
public override string GetStringJoinSelector(string result, string separator)
{
return $"group_concat({result} separator '{separator}') ";

5
Src/Asp.NetCore2/SqlSugar/Realization/Oracle/SqlBuilder/OracleExpressionContext.cs

@ -76,6 +76,11 @@ namespace SqlSugar
}
public partial class OracleMethod : DefaultDbMethod, IDbMethods
{
public override string WeekOfYear(MethodCallExpressionModel mode)
{
var parameterNameA = mode.Args[0].MemberName;
return $"TO_NUMBER(TO_CHAR({parameterNameA}, 'WW')) ";
}
public override string BitwiseAnd(MethodCallExpressionModel model)
{
var parameter = model.Args[0];

5
Src/Asp.NetCore2/SqlSugar/Realization/SqlServer/SqlBuilder/SqlServerExpressionContext.cs

@ -20,6 +20,11 @@ namespace SqlSugar
}
public partial class SqlServerMethod : DefaultDbMethod, IDbMethods
{
public override string WeekOfYear(MethodCallExpressionModel mode)
{
var parameterNameA = mode.Args[0].MemberName;
return $"DATEPART(WEEK, {parameterNameA}) ";
}
public override string GetTableWithDataBase(string dataBaseName, string tableName)
{
return $"{dataBaseName}.dbo.{tableName}";

5
Src/Asp.NetCore2/SqlSugar/Realization/Sqlite/SqlBuilder/SqliteExpressionContext.cs

@ -17,6 +17,11 @@ namespace SqlSugar
}
public class SqliteMethod : DefaultDbMethod, IDbMethods
{
public override string WeekOfYear(MethodCallExpressionModel mode)
{
var parameterNameA = mode.Args[0].MemberName;
return $"STRFTIME('%W', {parameterNameA}) ";
}
public override string Equals(MethodCallExpressionModel model)
{
var result= base.Equals(model);

Loading…
Cancel
Save