diff --git a/Src/Asp.NetCore2/SqlSeverTest/PgSqlTest/Config.cs b/Src/Asp.NetCore2/SqlSeverTest/PgSqlTest/Config.cs index f6e313fb4..f526fa969 100644 --- a/Src/Asp.NetCore2/SqlSeverTest/PgSqlTest/Config.cs +++ b/Src/Asp.NetCore2/SqlSeverTest/PgSqlTest/Config.cs @@ -8,8 +8,8 @@ namespace OrmTest { public class Config { - public static string ConnectionString = "PORT=5432;DATABASE=SqlSugar4xTest;HOST=localhost;PASSWORD=haosql;USER ID=postgres"; - public static string ConnectionString2 = "PORT=5432;DATABASE=SqlSugar4xTest;HOST=localhost;PASSWORD=haosql;USER ID=postgres"; - public static string ConnectionString3 = "PORT=5432;DATABASE=SqlSugar4xTest;HOST=localhost;PASSWORD=haosql;USER ID=postgres"; + public static string ConnectionString = "PORT=5432;DATABASE=SqlSugar4xTest;HOST=localhost;PASSWORD=jhl52771;USER ID=postgres"; + public static string ConnectionString2 = "PORT=5432;DATABASE=SqlSugar4xTest;HOST=localhost;PASSWORD=jhl52771;USER ID=postgres"; + public static string ConnectionString3 = "PORT=5432;DATABASE=SqlSugar4xTest;HOST=localhost;PASSWORD=jhl52771;USER ID=postgres"; } } diff --git a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Abstract/DeleteProvider/DeleteableProvider.cs b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Abstract/DeleteProvider/DeleteableProvider.cs index 873a5ef36..6eeb7df85 100644 --- a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Abstract/DeleteProvider/DeleteableProvider.cs +++ b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Abstract/DeleteProvider/DeleteableProvider.cs @@ -21,6 +21,7 @@ namespace SqlSugar public bool IsEnableDiffLogEvent { get; set; } public DiffLogModel diffModel { get; set; } public List tempPrimaryKeys { get; set; } + private Action RemoveCacheFunc { get; set; } public EntityInfo EntityInfo { get @@ -213,8 +214,11 @@ namespace SqlSugar public IDeleteable RemoveDataCache() { - var cacheService = this.Context.CurrentConnectionConfig.ConfigureExternalServices.DataInfoCacheService; - CacheSchemeMain.RemoveCache(cacheService, this.Context.EntityMaintenance.GetTableName()); + this.RemoveCacheFunc = () => + { + var cacheService = this.Context.CurrentConnectionConfig.ConfigureExternalServices.DataInfoCacheService; + CacheSchemeMain.RemoveCache(cacheService, this.Context.EntityMaintenance.GetTableName()); + }; return this; } @@ -398,6 +402,9 @@ namespace SqlSugar if (this.Context.Ado.DiffLogEvent != null) this.Context.Ado.DiffLogEvent(diffModel); } + if (this.RemoveCacheFunc != null) { + this.RemoveCacheFunc(); + } } private void Before(string sql) diff --git a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Abstract/InsertableProvider/InsertableProvider.cs b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Abstract/InsertableProvider/InsertableProvider.cs index 9f9d4c6de..e4387bb2f 100644 --- a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Abstract/InsertableProvider/InsertableProvider.cs +++ b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Abstract/InsertableProvider/InsertableProvider.cs @@ -29,6 +29,7 @@ namespace SqlSugar public bool IsAs { get; set; } public bool IsEnableDiffLogEvent { get; set; } public DiffLogModel diffModel { get; set; } + private Action RemoveCacheFunc { get; set; } #region Core @@ -214,8 +215,11 @@ namespace SqlSugar public IInsertable RemoveDataCache() { - var cacheService = this.Context.CurrentConnectionConfig.ConfigureExternalServices.DataInfoCacheService; - CacheSchemeMain.RemoveCache(cacheService, this.Context.EntityMaintenance.GetTableName()); + this.RemoveCacheFunc = () => + { + var cacheService = this.Context.CurrentConnectionConfig.ConfigureExternalServices.DataInfoCacheService; + CacheSchemeMain.RemoveCache(cacheService, this.Context.EntityMaintenance.GetTableName()); + }; return this; } public IInsertable EnableDiffLogEvent(object businessData = null) @@ -436,6 +440,9 @@ namespace SqlSugar if (this.Context.Ado.DiffLogEvent != null) this.Context.Ado.DiffLogEvent(diffModel); } + if (this.RemoveCacheFunc != null) { + this.RemoveCacheFunc(); + } } private void Before(string sql) { diff --git a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Abstract/QueryableProvider/QueryableProvider.cs b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Abstract/QueryableProvider/QueryableProvider.cs index e5fd623c3..4cd1558bd 100644 --- a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Abstract/QueryableProvider/QueryableProvider.cs +++ b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Abstract/QueryableProvider/QueryableProvider.cs @@ -484,7 +484,7 @@ namespace SqlSugar } public virtual ISugarQueryable MergeTable() { - Check.Exception(this.MapperAction != null, "'Mapper’ needs to be written after ‘MergeTable’ "); + Check.Exception(this.MapperAction != null||this.MapperActionWithCache!=null, "'Mapper’ needs to be written after ‘MergeTable’ "); Check.Exception(this.QueryBuilder.SelectValue.IsNullOrEmpty(), "MergeTable need to use Queryable.Select Method ."); Check.Exception(this.QueryBuilder.Skip > 0 || this.QueryBuilder.Take > 0 || this.QueryBuilder.OrderByValue.HasValue(), "MergeTable Queryable cannot Take Skip OrderBy PageToList "); ToSqlBefore(); @@ -1006,9 +1006,19 @@ namespace SqlSugar { QueryBuilder.CheckExpression(expression, "OrderBy"); var isSingle = QueryBuilder.IsSingle(); - var lamResult = QueryBuilder.GetExpressionValue(expression, isSingle ? ResolveExpressType.FieldSingle : ResolveExpressType.FieldMultiple); - OrderBy(lamResult.GetResultString() + UtilConstants.Space + type.ToString().ToUpper()); - return this; + if ((expression as LambdaExpression).Body is NewExpression) + { + var lamResult = QueryBuilder.GetExpressionValue(expression, isSingle ? ResolveExpressType.ArraySingle : ResolveExpressType.ArrayMultiple); + var items = lamResult.GetResultString().Split(',').Where(it => it.HasValue()).Select(it=> it + UtilConstants.Space + type.ToString().ToUpper()).ToList(); + OrderBy(string.Join(",",items)); + return this; + } + else + { + var lamResult = QueryBuilder.GetExpressionValue(expression, isSingle ? ResolveExpressType.FieldSingle : ResolveExpressType.FieldMultiple); + OrderBy(lamResult.GetResultString() + UtilConstants.Space + type.ToString().ToUpper()); + return this; + } } protected ISugarQueryable _GroupBy(Expression expression) { @@ -1313,6 +1323,7 @@ namespace SqlSugar asyncQueryableBuilder.PartitionByValue = this.QueryBuilder.PartitionByValue; asyncQueryableBuilder.JoinExpression = this.QueryBuilder.JoinExpression; asyncQueryableBuilder.WhereIndex = this.QueryBuilder.WhereIndex; + asyncQueryableBuilder.HavingInfos = this.QueryBuilder.HavingInfos; asyncQueryableBuilder.LambdaExpressions.ParameterIndex = this.QueryBuilder.LambdaExpressions.ParameterIndex; } #endregion diff --git a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Abstract/SqlBuilderProvider/SqlBuilderProvider.cs b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Abstract/SqlBuilderProvider/SqlBuilderProvider.cs index d81d548d3..40b183acd 100644 --- a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Abstract/SqlBuilderProvider/SqlBuilderProvider.cs +++ b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Abstract/SqlBuilderProvider/SqlBuilderProvider.cs @@ -98,11 +98,11 @@ namespace SqlSugar } public virtual string GetUnionAllSql(List sqlList) { - return string.Join("UNION ALL \r\n", sqlList); + return string.Join(" UNION ALL \r\n", sqlList); } public virtual string GetUnionSql(List sqlList) { - return string.Join("UNION \r\n", sqlList); + return string.Join(" UNION \r\n", sqlList); } public virtual void RepairReplicationParameters(ref string appendSql, SugarParameter[] parameters, int addIndex) { diff --git a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Abstract/UpdateProvider/UpdateableProvider.cs b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Abstract/UpdateProvider/UpdateableProvider.cs index 347a0b8ab..52d1e86b1 100644 --- a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Abstract/UpdateProvider/UpdateableProvider.cs +++ b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Abstract/UpdateProvider/UpdateableProvider.cs @@ -17,18 +17,21 @@ namespace SqlSugar public UpdateBuilder UpdateBuilder { get; set; } public IAdo Ado { get { return Context.Ado; } } public T[] UpdateObjs { get; set; } + public bool UpdateParameterIsNull { get; set; } public bool IsMappingTable { get { return this.Context.MappingTables != null && this.Context.MappingTables.Any(); } } public bool IsMappingColumns { get { return this.Context.MappingColumns != null && this.Context.MappingColumns.Any(); } } public bool IsSingle { get { return this.UpdateObjs.Length == 1; } } public List MappingColumnList { get; set; } private List IgnoreColumnNameList { get; set; } private List WhereColumnList { get; set; } + private bool IsWhereColumns { get; set; } private bool IsOffIdentity { get; set; } private bool IsVersionValidation { get; set; } public MappingTableList OldMappingTableList { get; set; } public bool IsAs { get; set; } public bool IsEnableDiffLogEvent { get; set; } public DiffLogModel diffModel { get; set; } + private Action RemoveCacheFunc { get; set; } public virtual int ExecuteCommand() { @@ -152,6 +155,8 @@ namespace SqlSugar public IUpdateable WhereColumns(Expression> columns) { + this.IsWhereColumns = true; + Check.Exception(UpdateParameterIsNull==true, "Updateable().Updateable is error,Use Updateable(obj).WhereColumns"); var whereColumns = UpdateBuilder.GetExpressionValue(columns, ResolveExpressType.ArraySingle).GetResultArray().Select(it => this.SqlBuilder.GetNoTranslationColumnName(it)).ToList(); if (this.WhereColumnList == null) this.WhereColumnList = new List(); foreach (var item in whereColumns) @@ -314,8 +319,11 @@ namespace SqlSugar public IUpdateable RemoveDataCache() { - var cacheService = this.Context.CurrentConnectionConfig.ConfigureExternalServices.DataInfoCacheService; - CacheSchemeMain.RemoveCache(cacheService, this.Context.EntityMaintenance.GetTableName()); + this.RemoveCacheFunc = () => + { + var cacheService = this.Context.CurrentConnectionConfig.ConfigureExternalServices.DataInfoCacheService; + CacheSchemeMain.RemoveCache(cacheService, this.Context.EntityMaintenance.GetTableName()); + }; return this; } @@ -392,6 +400,13 @@ namespace SqlSugar private void PreToSql() { UpdateBuilder.PrimaryKeys = GetPrimaryKeys(); + if (this.IsWhereColumns) { + foreach (var pkName in UpdateBuilder.PrimaryKeys) + { + var isContains=this.UpdateBuilder.DbColumnInfoList.Select(it => it.DbColumnName.ToLower()).Contains(pkName.ToLower()); + Check.Exception(isContains == false, "Use UpdateColumns().WhereColumn() ,UpdateColumns need {0}", pkName); + } + } #region IgnoreColumns if (this.Context.IgnoreColumns != null && this.Context.IgnoreColumns.Any()) { @@ -586,6 +601,9 @@ namespace SqlSugar if (this.Context.Ado.DiffLogEvent != null) this.Context.Ado.DiffLogEvent(diffModel); } + if (this.RemoveCacheFunc != null) { + this.RemoveCacheFunc(); + } } private void Before(string sql) diff --git a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/CacheScheme/CacheKeyBuider.cs b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/CacheScheme/CacheKeyBuider.cs index 4b6155ccc..3168d87b3 100644 --- a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/CacheScheme/CacheKeyBuider.cs +++ b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/CacheScheme/CacheKeyBuider.cs @@ -28,7 +28,7 @@ namespace SqlSugar result.IdentificationList.Add(queryBuilder.Take.ObjToString()); result.IdentificationList.Add(queryBuilder.Skip.ObjToString()); result.IdentificationList.Add(queryBuilder.IsCount.ObjToString()); - result.IdentificationList.Add(queryBuilder.GetSelectValue.ObjToString().Length.ObjToString()); + result.IdentificationList.Add(UtilMethods.GetMD5(queryBuilder.GetSelectValue.ObjToString())); if (queryBuilder.Parameters.HasValue()) { foreach (var item in queryBuilder.Parameters) diff --git a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/ExpressionsToSql/Common/SugarParameter.cs b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/ExpressionsToSql/Common/SugarParameter.cs index a9e9484b4..f6dbbf4b3 100644 --- a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/ExpressionsToSql/Common/SugarParameter.cs +++ b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/ExpressionsToSql/Common/SugarParameter.cs @@ -25,14 +25,14 @@ namespace SqlSugar this.ParameterName = name; SettingDataType(type); } - public SugarParameter(string name, object value, Type type,ParameterDirection direction) + public SugarParameter(string name, object value, Type type, ParameterDirection direction) { this.Value = value; this.ParameterName = name; this.Direction = direction; SettingDataType(type); } - public SugarParameter(string name, object value, Type type, ParameterDirection direction,int size) + public SugarParameter(string name, object value, Type type, ParameterDirection direction, int size) { this.Value = value; this.ParameterName = name; @@ -95,6 +95,10 @@ namespace SqlSugar { this.DbType = System.Data.DbType.DateTimeOffset; } + else if (type == UtilConstants.TimeSpanType) + { + this.Value = this.Value.ToString(); + } } public SugarParameter(string name, object value, bool isOutput) diff --git a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/ExpressionsToSql/ResolveItems/BaseResolve.cs b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/ExpressionsToSql/ResolveItems/BaseResolve.cs index f4849ae58..19a3e547b 100644 --- a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/ExpressionsToSql/ResolveItems/BaseResolve.cs +++ b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/ExpressionsToSql/ResolveItems/BaseResolve.cs @@ -445,5 +445,38 @@ namespace SqlSugar Check.ThrowNotSupportedException(item.GetType().Name); } } + protected static Dictionary MethodMapping = new Dictionary() { + { "ToString","ToString"}, + { "ToInt32","ToInt32"}, + { "ToInt16","ToInt32"}, + { "ToInt64","ToInt64"}, + { "ToDecimal","ToDecimal"}, + { "ToDateTime","ToDate"}, + { "ToBoolean","ToBool"}, + { "ToDouble","ToDouble"}, + { "Length","Length"}, + { "Replace","Replace"}, + { "Contains","Contains"}, + { "ContainsArray","ContainsArray"}, + { "EndsWith","EndsWith"}, + { "StartsWith","StartsWith"}, + { "HasValue","HasValue"}, + { "Trim","Trim"}, + { "Equals","Equals"}, + { "ToLower","ToLower"}, + { "ToUpper","ToUpper"}, + { "Substring","Substring"}, + { "DateAdd","DateAdd"} + }; + + protected static Dictionary MethodTimeMapping = new Dictionary() { + { "AddYears",DateType.Year}, + { "AddMonths",DateType.Month}, + { "AddDays",DateType.Day}, + { "AddHours",DateType.Hour}, + { "AddMinutes",DateType.Minute}, + { "AddSeconds",DateType.Second}, + { "AddMilliseconds",DateType.Millisecond} + }; } } diff --git a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/ExpressionsToSql/ResolveItems/MemberExpressionResolve.cs b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/ExpressionsToSql/ResolveItems/MemberExpressionResolve.cs index 782126956..25c4c5e67 100644 --- a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/ExpressionsToSql/ResolveItems/MemberExpressionResolve.cs +++ b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/ExpressionsToSql/ResolveItems/MemberExpressionResolve.cs @@ -60,6 +60,7 @@ namespace SqlSugar string fieldName = string.Empty; switch (parameter.Context.ResolveType) { + case ResolveExpressType.Update: case ResolveExpressType.SelectSingle: fieldName = GetSingleName(parameter, expression, isLeft); if (isSetTempData) diff --git a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/ExpressionsToSql/ResolveItems/MemberInitExpressionResolve.cs b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/ExpressionsToSql/ResolveItems/MemberInitExpressionResolve.cs index 333410016..2bcce18a8 100644 --- a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/ExpressionsToSql/ResolveItems/MemberInitExpressionResolve.cs +++ b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/ExpressionsToSql/ResolveItems/MemberInitExpressionResolve.cs @@ -61,7 +61,17 @@ namespace SqlSugar { if (item is UnaryExpression) item = (item as UnaryExpression).Operand; - MethodCall(parameter, memberName, item); + var callMethod = item as MethodCallExpression; + if (MethodTimeMapping.Any(it => it.Key == callMethod.Method.Name) || MethodMapping.Any(it=>it.Key==callMethod.Method.Name)||IsExtMethod(callMethod.Method.Name)||IsSubMethod(callMethod)|| callMethod.Method.DeclaringType.FullName.StartsWith(UtilConstants.AssemblyName+UtilConstants.Dot)) + { + MethodCall(parameter, memberName, item); + } + else + { + var paramterValue = ExpressionTool.DynamicInvoke(item); + string parameterName = AppendParameter(paramterValue); + this.Context.Result.Append(base.Context.GetEqString(memberName, parameterName)); + } } else if (IsConst(item)) { @@ -147,5 +157,19 @@ namespace SqlSugar { return SubTools.SubItemsConst.Any(it =>express.Object != null && express.Object.Type.Name == "Subqueryable`1"); } + private bool IsExtMethod(string methodName) + { + if (this.Context.SqlFuncServices == null) return false; + return this.Context.SqlFuncServices.Select(it => it.UniqueMethodName).Contains(methodName); + } + private bool CheckMethod(MethodCallExpression expression) + { + if (IsExtMethod(expression.Method.Name)) + return true; + if (expression.Method.ReflectedType().FullName != ExpressionConst.SqlFuncFullName) + return false; + else + return true; + } } } diff --git a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/ExpressionsToSql/ResolveItems/MethodCallExpressionResolve.cs b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/ExpressionsToSql/ResolveItems/MethodCallExpressionResolve.cs index 9248880f7..289a573fa 100644 --- a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/ExpressionsToSql/ResolveItems/MethodCallExpressionResolve.cs +++ b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/ExpressionsToSql/ResolveItems/MethodCallExpressionResolve.cs @@ -513,40 +513,6 @@ namespace SqlSugar return null; } - private static Dictionary MethodMapping = new Dictionary() { - { "ToString","ToString"}, - { "ToInt32","ToInt32"}, - { "ToInt16","ToInt32"}, - { "ToInt64","ToInt64"}, - { "ToDecimal","ToDecimal"}, - { "ToDateTime","ToDate"}, - { "ToBoolean","ToBool"}, - { "ToDouble","ToDouble"}, - { "Length","Length"}, - { "Replace","Replace"}, - { "Contains","Contains"}, - { "ContainsArray","ContainsArray"}, - { "EndsWith","EndsWith"}, - { "StartsWith","StartsWith"}, - { "HasValue","HasValue"}, - { "Trim","Trim"}, - { "Equals","Equals"}, - { "ToLower","ToLower"}, - { "ToUpper","ToUpper"}, - { "Substring","Substring"}, - { "DateAdd","DateAdd"} - }; - - private static Dictionary MethodTimeMapping = new Dictionary() { - { "AddYears",DateType.Year}, - { "AddMonths",DateType.Month}, - { "AddDays",DateType.Day}, - { "AddHours",DateType.Hour}, - { "AddMinutes",DateType.Minute}, - { "AddSeconds",DateType.Second}, - { "AddMilliseconds",DateType.Millisecond} - }; - private bool IsContainsArray(MethodCallExpression express, string methodName, bool isValidNativeMethod) { return !isValidNativeMethod && express.Method.DeclaringType.Namespace.IsIn("System.Linq", "System.Collections.Generic") && methodName == "Contains"; diff --git a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/ExpressionsToSql/Subquery/Items/SubAndIF.cs b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/ExpressionsToSql/Subquery/Items/SubAndIF.cs new file mode 100644 index 000000000..15e2e2473 --- /dev/null +++ b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/ExpressionsToSql/Subquery/Items/SubAndIF.cs @@ -0,0 +1,62 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Linq.Expressions; +using System.Text; + +namespace SqlSugar +{ + public class SubAndIF : ISubOperation + { + public bool HasWhere + { + get; set; + } + + public string Name + { + get { return "WhereIF"; } + } + + public Expression Expression + { + get; set; + } + + public int Sort + { + get + { + return 400; + } + } + + public ExpressionContext Context + { + get; set; + } + + public string GetValue(Expression expression) + { + var exp = expression as MethodCallExpression; + object value = null; + try + { + value = ExpressionTool.DynamicInvoke(exp.Arguments[0]); + } + catch + { + Check.Exception(true, ErrorMessage.WhereIFCheck,exp.Arguments[0].ToString()); + } + var isWhere= Convert.ToBoolean(value); + if (!Convert.ToBoolean(isWhere)) { + return ""; + } + var argExp = exp.Arguments[1]; + var result = "AND " + SubTools.GetMethodValue(Context, argExp, ResolveExpressType.WhereMultiple); ; + var selfParameterName = Context.GetTranslationColumnName((argExp as LambdaExpression).Parameters.First().Name) + UtilConstants.Dot; + result = result.Replace(selfParameterName, SubTools.GetSubReplace(this.Context)); + return result; + } + } +} diff --git a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/ExpressionsToSql/Subquery/SubResolve.cs b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/ExpressionsToSql/Subquery/SubResolve.cs index 46a246547..41a184fd7 100644 --- a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/ExpressionsToSql/Subquery/SubResolve.cs +++ b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/ExpressionsToSql/Subquery/SubResolve.cs @@ -87,6 +87,16 @@ namespace SqlSugar { item = items.First(s => s is SubAnd); } + + if (item is SubWhereIF && hasWhere == false) + { + hasWhere = true; + } + else if (item is SubWhereIF) + { + item = items.First(s => s is SubAndIF); + } + item.Context = this.context; item.Expression = exp; return item; diff --git a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/ExpressionsToSql/Subquery/SubTools.cs b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/ExpressionsToSql/Subquery/SubTools.cs index e90cb5557..5928d5719 100644 --- a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/ExpressionsToSql/Subquery/SubTools.cs +++ b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/ExpressionsToSql/Subquery/SubTools.cs @@ -17,6 +17,7 @@ namespace SqlSugar new SubWhere(){ Context=Context }, new SubWhereIF(){ Context=Context }, new SubAnd(){ Context=Context }, + new SubAndIF(){ Context=Context }, new SubAny(){ Context=Context }, new SubNotAny(){ Context=Context }, new SubBegin(){ Context=Context }, diff --git a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Interface/IUpdateable.cs b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Interface/IUpdateable.cs index fa2705e39..72efe9a52 100644 --- a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Interface/IUpdateable.cs +++ b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Interface/IUpdateable.cs @@ -10,6 +10,8 @@ namespace SqlSugar public interface IUpdateable where T : class, new() { UpdateBuilder UpdateBuilder { get; set; } + bool UpdateParameterIsNull { get; set; } + int ExecuteCommand(); bool ExecuteCommandHasChange(); Task ExecuteCommandAsync(); diff --git a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Realization/Oracle/SqlBuilder/OracleBuilder.cs b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Realization/Oracle/SqlBuilder/OracleBuilder.cs index 6a605dde5..c0e9026b8 100644 --- a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Realization/Oracle/SqlBuilder/OracleBuilder.cs +++ b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Realization/Oracle/SqlBuilder/OracleBuilder.cs @@ -34,8 +34,11 @@ namespace SqlSugar public override string SqlTranslationRight { get { return "\""; } } public override string GetTranslationTableName(string name) { - var result= base.GetTranslationTableName(name); - return result.ToUpper(); + var result = base.GetTranslationTableName(name); + if (result.Contains("(") && result.Contains(")")) + return result; + else + return result.ToUpper(); } public override string GetTranslationColumnName(string entityName, string propertyName) { diff --git a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Realization/SqlServer/DbMaintenance/SqlServerDbMaintenance.cs b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Realization/SqlServer/DbMaintenance/SqlServerDbMaintenance.cs index 4996d6ca1..b2f80d683 100644 --- a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Realization/SqlServer/DbMaintenance/SqlServerDbMaintenance.cs +++ b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Realization/SqlServer/DbMaintenance/SqlServerDbMaintenance.cs @@ -280,5 +280,15 @@ namespace SqlSugar } return true; } + + public override bool RenameColumn(string tableName, string oldColumnName, string newColumnName) + { + tableName = this.SqlBuilder.GetTranslationTableName(tableName); + oldColumnName = this.SqlBuilder.GetTranslationColumnName(oldColumnName); + newColumnName = this.SqlBuilder.GetNoTranslationColumnName(newColumnName); + string sql = string.Format(this.RenameColumnSql, tableName, oldColumnName, newColumnName); + this.Context.Ado.ExecuteCommand(sql); + return true; + } } } diff --git a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/SqlSugarClient.cs b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/SqlSugarClient.cs index 7fd4259bc..203da40e3 100644 --- a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/SqlSugarClient.cs +++ b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/SqlSugarClient.cs @@ -532,7 +532,9 @@ namespace SqlSugar } public virtual IUpdateable Updateable() where T : class, new() { - return this.Context.Updateable(new T[] { new T() }); + var result= this.Context.Updateable(new T[] { new T() }); + result.UpdateParameterIsNull=true; + return result; } public virtual IUpdateable Updateable(Dictionary columnDictionary) where T : class, new() { diff --git a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Utilities/UtilConstants.cs b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Utilities/UtilConstants.cs index b37082eac..f0a7f6a61 100644 --- a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Utilities/UtilConstants.cs +++ b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Utilities/UtilConstants.cs @@ -29,6 +29,7 @@ namespace SqlSugar internal static Type StringType = typeof(string); internal static Type DateType = typeof(DateTime); internal static Type DateTimeOffsetType = typeof(DateTimeOffset); + internal static Type TimeSpanType = typeof(TimeSpan); internal static Type ByteArrayType = typeof(byte[]); internal static Type ModelType= typeof(ModelContext); internal static Type DynamicType = typeof(ExpandoObject); diff --git a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Utilities/UtilMethods.cs b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Utilities/UtilMethods.cs index 945aaf8c3..dc20c7321 100644 --- a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Utilities/UtilMethods.cs +++ b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Utilities/UtilMethods.cs @@ -4,6 +4,7 @@ using System.Data; using System.Data.SqlClient; using System.Linq; using System.Reflection; +using System.Security.Cryptography; using System.Text; using System.Text.RegularExpressions; @@ -114,5 +115,20 @@ namespace SqlSugar return Convert.ToInt64(string.Join("", bytes).PadRight(20, '0')); } + internal static string GetMD5(string myString) + { + MD5 md5 = new MD5CryptoServiceProvider(); + byte[] fromData = System.Text.Encoding.Unicode.GetBytes(myString); + byte[] targetData = md5.ComputeHash(fromData); + string byte2String = null; + + for (int i = 0; i < targetData.Length; i++) + { + byte2String += targetData[i].ToString("x"); + } + + return byte2String; + } + } } diff --git a/Src/Asp.NetCore2/SqlSeverTest/SqliteTest/DataBase/SqlSugar4xTest.sqlite b/Src/Asp.NetCore2/SqlSeverTest/SqliteTest/DataBase/SqlSugar4xTest.sqlite index cfaa0a21a..6b17e7cba 100644 Binary files a/Src/Asp.NetCore2/SqlSeverTest/SqliteTest/DataBase/SqlSugar4xTest.sqlite and b/Src/Asp.NetCore2/SqlSeverTest/SqliteTest/DataBase/SqlSugar4xTest.sqlite differ