Add SqlFunc.CharIndexNew

This commit is contained in:
sunkaixuan 2023-09-14 18:12:19 +08:00
parent b1370c6d7e
commit 27f8069c7e
6 changed files with 20 additions and 1 deletions

View File

@ -514,11 +514,15 @@ namespace SqlSugar
} }
} }
return reslut.ToString(); return reslut.ToString();
} }
public virtual string CharIndex(MethodCallExpressionModel model) public virtual string CharIndex(MethodCallExpressionModel model)
{ {
return string.Format("CHARINDEX ({0},{1})", model.Args[0].MemberName, model.Args[1].MemberName); return string.Format("CHARINDEX ({0},{1})", model.Args[0].MemberName, model.Args[1].MemberName);
} }
public virtual string CharIndexNew(MethodCallExpressionModel model)
{
return CharIndex(model);
}
public virtual string ToVarchar(MethodCallExpressionModel model) public virtual string ToVarchar(MethodCallExpressionModel model)
{ {

View File

@ -69,6 +69,7 @@ namespace SqlSugar
string GetDate(); string GetDate();
string GetRandom(); string GetRandom();
string CharIndex(MethodCallExpressionModel model); string CharIndex(MethodCallExpressionModel model);
string CharIndexNew(MethodCallExpressionModel model);
string BitwiseAnd(MethodCallExpressionModel model); string BitwiseAnd(MethodCallExpressionModel model);
string BitwiseInclusiveOR(MethodCallExpressionModel model); string BitwiseInclusiveOR(MethodCallExpressionModel model);

View File

@ -345,7 +345,9 @@ namespace SqlSugar
/// <returns></returns> /// <returns></returns>
public static Subqueryable<T> Subqueryable<T>() where T:class,new(){ throw new NotSupportedException("Can only be used in expressions");} public static Subqueryable<T> Subqueryable<T>() where T:class,new(){ throw new NotSupportedException("Can only be used in expressions");}
public static CaseThen IF(bool condition) { throw new NotSupportedException("Can only be used in expressions"); } public static CaseThen IF(bool condition) { throw new NotSupportedException("Can only be used in expressions"); }
[Obsolete("多库下参数顺序不一至,为了保证多库下更好体验请使用 SqlFunc.CharIndexNew")]
public static int CharIndex(string findChar,string searchValue) { throw new NotSupportedException("Can only be used in expressions"); } public static int CharIndex(string findChar,string searchValue) { throw new NotSupportedException("Can only be used in expressions"); }
public static int CharIndexNew(string stringValue, string charValue) { throw new NotSupportedException("Can only be used in expressions"); }
public static int BitwiseAnd(int left, int right) { throw new NotSupportedException("Can only be used in expressions"); } public static int BitwiseAnd(int left, int right) { throw new NotSupportedException("Can only be used in expressions"); }
public static int BitwiseInclusiveOR(int left, int right) { throw new NotSupportedException("Can only be used in expressions"); } public static int BitwiseInclusiveOR(int left, int right) { throw new NotSupportedException("Can only be used in expressions"); }
public static int BitwiseAnd(long left, long right) { throw new NotSupportedException("Can only be used in expressions"); } public static int BitwiseAnd(long left, long right) { throw new NotSupportedException("Can only be used in expressions"); }

View File

@ -104,6 +104,10 @@ namespace SqlSugar
} }
public class KdbndpMethod : DefaultDbMethod, IDbMethods public class KdbndpMethod : DefaultDbMethod, IDbMethods
{ {
public override string CharIndexNew(MethodCallExpressionModel model)
{
return string.Format(" (strpos ({0},{1}))", model.Args[0].MemberName, model.Args[1].MemberName);
}
public override string CharIndex(MethodCallExpressionModel model) public override string CharIndex(MethodCallExpressionModel model)
{ {
return string.Format(" (strpos ({1},{0})-1)", model.Args[0].MemberName, model.Args[1].MemberName); return string.Format(" (strpos ({1},{0})-1)", model.Args[0].MemberName, model.Args[1].MemberName);

View File

@ -137,6 +137,10 @@ namespace SqlSugar
{ {
return string.Format(" (strpos ({1},{0})-1)", model.Args[0].MemberName, model.Args[1].MemberName); return string.Format(" (strpos ({1},{0})-1)", model.Args[0].MemberName, model.Args[1].MemberName);
} }
public override string CharIndexNew(MethodCallExpressionModel model)
{
return string.Format(" (strpos ({0},{1}))", model.Args[0].MemberName, model.Args[1].MemberName);
}
public override string TrueValue() public override string TrueValue()
{ {
return "true"; return "true";

View File

@ -20,6 +20,10 @@ namespace SqlSugar
} }
public partial class SqlServerMethod : DefaultDbMethod, IDbMethods public partial class SqlServerMethod : DefaultDbMethod, IDbMethods
{ {
public override string CharIndexNew(MethodCallExpressionModel model)
{
return string.Format("CHARINDEX ({1},{0})", model.Args[0].MemberName, model.Args[1].MemberName);
}
public override string WeekOfYear(MethodCallExpressionModel mode) public override string WeekOfYear(MethodCallExpressionModel mode)
{ {
var parameterNameA = mode.Args[0].MemberName; var parameterNameA = mode.Args[0].MemberName;