Browse Source

Add SqlFunc.MergeString

pull/12/MERGE
sunkaixuan 7 years ago
parent
commit
183bc4d94e
  1. 1
      Src/Asp.Net/MySqlTest/Demos/1_Query.cs
  2. 1
      Src/Asp.Net/SqlServerTest/Demos/1_Query.cs
  3. 2
      Src/Asp.Net/SqlSugar/ExpressionsToSql/DbMethods/DefaultDbMethod.cs
  4. 6
      Src/Asp.Net/SqlSugar/ExpressionsToSql/DbMethods/SqlFunc.cs
  5. 4
      Src/Asp.Net/SqlSugar/ExpressionsToSql/ResolveItems/MemberExpressionResolve.cs
  6. 2
      Src/Asp.Net/SqlSugar/ExpressionsToSql/ResolveItems/MethodCallExpressionResolve.cs
  7. 4
      Src/Asp.Net/SqlSugar/Realization/Oracle/SqlBuilder/OracleExpressionContext.cs
  8. BIN
      Src/Asp.Net/SqliteTest/DataBase/SqlSugar4xTest.sqlite

1
Src/Asp.Net/MySqlTest/Demos/1_Query.cs

@ -333,6 +333,7 @@ namespace OrmTest.Demo
var db = GetInstance();
var t1 = db.Queryable<Student>().Where(it => SqlFunc.ToLower(it.Name) == SqlFunc.ToLower("JACK")).ToList();
var t2 = db.Queryable<Student>().Where(it => SqlFunc.IsNull(it.Name, "nullvalue") == "nullvalue").ToList();
var t3 = db.Queryable<Student>().Where(it => SqlFunc.MergeString("a", it.Name) == "nullvalue").ToList();
//SELECT [Id],[SchoolId],[Name],[CreateTime] FROM [Student] WHERE ((LOWER([Name])) = (LOWER(@MethodConst0)) )
/***More Functions***/

1
Src/Asp.Net/SqlServerTest/Demos/1_Query.cs

@ -434,6 +434,7 @@ namespace OrmTest.Demo
var db = GetInstance();
var t1 = db.Queryable<Student>().Where(it => SqlFunc.ToLower(it.Name) == SqlFunc.ToLower("JACK")).ToList();
var t2 = db.Queryable<Student>().Where(it => SqlFunc.IsNull(it.Name,"nullvalue")=="nullvalue").ToList();
var t3 = db.Queryable<Student>().Where(it => SqlFunc.MergeString("a",it.Name) == "nullvalue").ToList();
//SELECT [Id],[SchoolId],[Name],[CreateTime] FROM [Student] WHERE ((LOWER([Name])) = (LOWER(@MethodConst0)) )
/***More Functions***/

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

@ -302,7 +302,7 @@ namespace SqlSugar
public virtual string MergeString(params string[] strings)
{
return string.Join("", strings);
return string.Join("+", strings);
}
public virtual string Pack(string sql)

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

@ -68,6 +68,12 @@ namespace SqlSugar
public static bool Between(object value, object start, object end) { throw new NotSupportedException("Can only be used in expressions"); }
public static TResult IIF<TResult>(bool Expression, TResult thenValue, TResult elseValue) { throw new NotSupportedException("Can only be used in expressions"); }
public static TResult IsNull<TResult>(TResult thisValue, TResult ifNullValue) { throw new NotSupportedException("Can only be used in expressions"); }
public static string MergeString(string value1,string value2) { throw new NotSupportedException("Can only be used in expressions"); }
public static string MergeString(string value1, string value2,string value3) { throw new NotSupportedException("Can only be used in expressions"); }
public static string MergeString(string value1, string value2,string value3,string value4) { throw new NotSupportedException("Can only be used in expressions"); }
public static string MergeString(string value1, string value2, string value3, string value4,string value5) { throw new NotSupportedException("Can only be used in expressions"); }
public static string MergeString(string value1, string value2, string value3, string value4, string value5,string value6) { throw new NotSupportedException("Can only be used in expressions"); }
public static string MergeString(string value1, string value2, string value3, string value4, string value5, string value6,string value7) { throw new NotSupportedException("Can only be used in expressions"); }
public static int ToInt32(object value) { return value.ObjToInt(); }
public static long ToInt64(object value) { return Convert.ToInt64(value); }
/// <summary>

4
Src/Asp.Net/SqlSugar/ExpressionsToSql/ResolveItems/MemberExpressionResolve.cs

@ -204,9 +204,9 @@ namespace SqlSugar
};
AppendMember(parameter, isLeft, GetToDate(this.Context.DbMehtods.MergeString(
this.GetDateValue(parameter.CommonTempData, DateType.Year),
"+'-'+",
"'-'",
this.GetDateValue(parameter.CommonTempData, DateType.Month),
"+'-'+",
"'-'",
this.GetDateValue(parameter.CommonTempData, DateType.Day))));
}
parameter.CommonTempData = oldCommonTempDate;

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

@ -409,6 +409,8 @@ namespace SqlSugar
return mappingColumnResult;
case "IsNull":
return this.Context.DbMehtods.IsNull(model);
case "MergeString":
return this.Context.DbMehtods.MergeString(model.Args.Select(it=>it.MemberName.ObjToString()).ToArray());
case "GetSelfAndAutoFill":
this.Context.Parameters.RemoveAll(it => it.ParameterName == model.Args[0].MemberName.ObjToString());
return this.Context.DbMehtods.GetSelfAndAutoFill(model.Args[0].MemberValue.ObjToString(), this.Context.IsSingle);

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

@ -164,5 +164,9 @@ namespace SqlSugar
return string.Format("NVL({0},{1})", parameter.MemberName, parameter1.MemberName);
}
public override string MergeString(params string[] strings)
{
return string.Join("||", strings).Replace("+", "");
}
}
}

BIN
Src/Asp.Net/SqliteTest/DataBase/SqlSugar4xTest.sqlite

Binary file not shown.
Loading…
Cancel
Save