Browse Source

Add SqlFunc.TrimEnd TrimStart

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

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

@ -1011,5 +1011,19 @@ namespace SqlSugar
var parameterNameA = mode.Args[0].MemberName;
return $" DATE_PART('week', {parameterNameA})+1 ";
}
public virtual string TrimEnd(MethodCallExpressionModel mode)
{
var parameterNameA = mode.Args[0].MemberName;
var parameterNameB= mode.Args[1].MemberName;
return $" TRIM(BOTH "+ parameterNameB + " FROM "+ parameterNameA + ") ";
}
public virtual string TrimStart(MethodCallExpressionModel mode)
{
var parameterNameA = mode.Args[0].MemberName;
var parameterNameB = mode.Args[1].MemberName;
return $" LTRIM(BOTH " + parameterNameB + " FROM " + parameterNameA + ") ";
}
}
}

2
Src/Asp.Net/SqlSugar/ExpressionsToSql/DbMethods/IDbMethods.cs

@ -114,5 +114,7 @@ namespace SqlSugar
string Like(MethodCallExpressionModel mode);
string ToSingle(MethodCallExpressionModel mode);
string WeekOfYear(MethodCallExpressionModel mode);
string TrimEnd(MethodCallExpressionModel mode);
string TrimStart(MethodCallExpressionModel mode);
}
}

9
Src/Asp.Net/SqlSugar/ExpressionsToSql/DbMethods/SqlFunc.cs

@ -181,6 +181,14 @@ namespace SqlSugar
{
return thisValue == null ? null : thisValue.ToString().Trim();
}
public static string TrimEnd(object thisValue,string trimChar)
{
throw new NotSupportedException("Can only be used in expressions");
}
public static string TrimStart(object thisValue, string trimChar)
{
throw new NotSupportedException("Can only be used in expressions");
}
public static bool Contains(string thisValue, string parameterValue)
{
return thisValue.Contains(parameterValue);
@ -318,6 +326,7 @@ namespace SqlSugar
public static int BitwiseInclusiveOR(long left, long right) { throw new NotSupportedException("Can only be used in expressions"); }
public static DateTime Oracle_ToDate(string date,string format) { throw new NotSupportedException("Can only be used in expressions"); }
public static string Oracle_ToChar(DateTime date, string format) { throw new NotSupportedException("Can only be used in expressions"); }
public static string Oracle_ToChar(object objValue, string format) { throw new NotSupportedException("Can only be used in expressions"); }
public static int SqlServer_DateDiff(string dateType,DateTime date1,DateTime date2) { throw new NotSupportedException("Can only be used in expressions"); }
public static bool JsonListObjectAny(object jsonListObject, string fieldName, object value)

14
Src/Asp.Net/SqlSugar/Realization/Dm/SqlBuilder/DmExpressionContext.cs

@ -226,5 +226,19 @@ namespace SqlSugar
var parameter = model.Args[0];
return string.Format(" CAST({0} AS decimal(18,4))", parameter.MemberName);
}
public override string TrimEnd(MethodCallExpressionModel mode)
{
var parameterNameA = mode.Args[0].MemberName;
var parameterNameB = mode.Args[1].MemberName;
return $" RTRIM({parameterNameA}, {parameterNameB}) ";
}
public override string TrimStart(MethodCallExpressionModel mode)
{
var parameterNameA = mode.Args[0].MemberName;
var parameterNameB = mode.Args[1].MemberName;
return $" LTRIM({parameterNameA}, {parameterNameB}) ";
}
}
}

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

@ -245,5 +245,18 @@ namespace SqlSugar
return $" JSON_CONTAINS({model.Args[0].MemberName},'{{\"{model.Args[1].MemberValue}\":\"{model.Args[2].MemberValue.ObjToStringNoTrim().ToSqlFilter()}\"}}')";
}
}
public override string TrimEnd(MethodCallExpressionModel mode)
{
var parameterNameA = mode.Args[0].MemberName;
var parameterNameB = mode.Args[1].MemberName;
return $" TRIM(TRAILING {parameterNameA} FROM {parameterNameB}) ";
}
public override string TrimStart(MethodCallExpressionModel mode)
{
var parameterNameA = mode.Args[0].MemberName;
var parameterNameB = mode.Args[1].MemberName;
return $" TRIM(LEADING {parameterNameA} FROM {parameterNameB}) ";
}
}
}

13
Src/Asp.Net/SqlSugar/Realization/Oracle/SqlBuilder/OracleExpressionContext.cs

@ -353,5 +353,18 @@ namespace SqlSugar
{
return string.Format("instr ({0},{1},1,1) ", model.Args[0].MemberName, model.Args[1].MemberName);
}
public override string TrimEnd(MethodCallExpressionModel mode)
{
var parameterNameA = mode.Args[0].MemberName;
var parameterNameB = mode.Args[1].MemberName;
return $" RTRIM({parameterNameA}, {parameterNameB}) ";
}
public override string TrimStart(MethodCallExpressionModel mode)
{
var parameterNameA = mode.Args[0].MemberName;
var parameterNameB = mode.Args[1].MemberName;
return $" LTRIM({parameterNameA}, {parameterNameB}) ";
}
}
}

14
Src/Asp.Net/SqlSugar/Realization/SqlServer/SqlBuilder/SqlServerExpressionContext.cs

@ -109,6 +109,20 @@ namespace SqlSugar
, model.Args[1].MemberName
);
}
public override string TrimEnd(MethodCallExpressionModel mode)
{
var parameterNameA = mode.Args[0].MemberName;
var parameterNameB = mode.Args[1].MemberName;
return $" RTRIM(REPLACE({parameterNameA}, {parameterNameB}, '')) ";
}
public override string TrimStart(MethodCallExpressionModel mode)
{
var parameterNameA = mode.Args[0].MemberName;
var parameterNameB = mode.Args[1].MemberName;
return $" LTRIM(REPLACE({parameterNameA},{parameterNameB}, '')) ";
}
}
}

18
Src/Asp.Net/SqlSugar/Realization/Sqlite/SqlBuilder/SqliteExpressionContext.cs

@ -279,7 +279,23 @@ namespace SqlSugar
public override string CharIndex(MethodCallExpressionModel model)
{
throw new NotSupportedException("Slqite Not Supported CharIndex");
var parameterNameA = model.Args[0].MemberName;
var parameterNameB = model.Args[1].MemberName;
return $" INSTR(LOWER({parameterNameA}), LOWER({parameterNameB})) ";
}
public override string TrimEnd(MethodCallExpressionModel mode)
{
var parameterNameA = mode.Args[0].MemberName;
var parameterNameB = mode.Args[1].MemberName;
return $" RTRIM(REPLACE({parameterNameA}, {parameterNameB}, '')) ";
}
public override string TrimStart(MethodCallExpressionModel mode)
{
var parameterNameA = mode.Args[0].MemberName;
var parameterNameB = mode.Args[1].MemberName;
return $" LTRIM(REPLACE({parameterNameA}, {parameterNameB}, '')) ";
}
}
}

Loading…
Cancel
Save