diff --git a/Src/Asp.Net/SqlSugar/Abstract/DbMaintenanceProvider/Methods.cs b/Src/Asp.Net/SqlSugar/Abstract/DbMaintenanceProvider/Methods.cs index 09018307f..c29784c3d 100644 --- a/Src/Asp.Net/SqlSugar/Abstract/DbMaintenanceProvider/Methods.cs +++ b/Src/Asp.Net/SqlSugar/Abstract/DbMaintenanceProvider/Methods.cs @@ -298,6 +298,7 @@ namespace SqlSugar { pkName = "PK_" + pkName.GetNonNegativeHashCodeString(); } + columnName = string.Join(",", columnNames.Select(it=>SqlBuilder.GetTranslationColumnName(it))); string sql = string.Format(this.AddPrimaryKeySql, tableName,pkName, columnName); this.Context.Ado.ExecuteCommand(sql); return true; diff --git a/Src/Asp.Net/SqlSugar/Abstract/DeleteProvider/DeleteableProvider.cs b/Src/Asp.Net/SqlSugar/Abstract/DeleteProvider/DeleteableProvider.cs index 9032e2317..81e6b1162 100644 --- a/Src/Asp.Net/SqlSugar/Abstract/DeleteProvider/DeleteableProvider.cs +++ b/Src/Asp.Net/SqlSugar/Abstract/DeleteProvider/DeleteableProvider.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections; using System.Collections.Generic; using System.Data; @@ -23,7 +23,7 @@ namespace SqlSugar public DiffLogModel diffModel { get; set; } public List tempPrimaryKeys { get; set; } internal Action RemoveCacheFunc { get; set; } - internal List DeleteObjects { get; set; } + public List DeleteObjects { get; set; } public EntityInfo EntityInfo { get @@ -690,7 +690,7 @@ namespace SqlSugar } - private void After(string sql) + protected virtual void After(string sql) { if (this.IsEnableDiffLogEvent) { @@ -711,7 +711,7 @@ namespace SqlSugar DataChangesAop(this.DeleteObjects); } - private void Before(string sql) + protected virtual void Before(string sql) { if (this.IsEnableDiffLogEvent) { @@ -727,7 +727,7 @@ namespace SqlSugar } } - private List GetDiffTable(string sql, List parameters) + protected virtual List GetDiffTable(string sql, List parameters) { List result = new List(); var whereSql = Regex.Replace(sql, ".* WHERE ", "", RegexOptions.Singleline); @@ -756,7 +756,7 @@ namespace SqlSugar } return result; } - private void DataAop(object deleteObj) + protected virtual void DataAop(object deleteObj) { var dataEvent = this.Context.CurrentConnectionConfig.AopEvents?.DataExecuting; if (deleteObj != null&& dataEvent!=null) @@ -770,7 +770,7 @@ namespace SqlSugar dataEvent(deleteObj,model); } } - private void DataChangesAop(List deleteObjs) + protected virtual void DataChangesAop(List deleteObjs) { var dataEvent = this.Context.CurrentConnectionConfig.AopEvents?.DataChangesExecuted; if(dataEvent != null&&deleteObjs != null) diff --git a/Src/Asp.Net/SqlSugar/Abstract/ExecuteNavProvider/UpdateNavProvider.cs b/Src/Asp.Net/SqlSugar/Abstract/ExecuteNavProvider/UpdateNavProvider.cs index e27cf0658..e53829cef 100644 --- a/Src/Asp.Net/SqlSugar/Abstract/ExecuteNavProvider/UpdateNavProvider.cs +++ b/Src/Asp.Net/SqlSugar/Abstract/ExecuteNavProvider/UpdateNavProvider.cs @@ -181,12 +181,24 @@ namespace SqlSugar } else { - this._Context.Updateable(_Roots) - .EnableDiffLogEventIF(_RootOptions.IsDiffLogEvent,_RootOptions.DiffLogBizData) - .UpdateColumns(_RootOptions.UpdateColumns) - .IgnoreColumns(_RootOptions.IgnoreColumns) - .IgnoreNullColumns(_RootOptions.IsIgnoreAllNullColumns) - .ExecuteCommandWithOptLockIF(_RootOptions?.IsOptLock, _RootOptions?.IsOptLock); + if (_Roots.Count() == 1 && _RootOptions?.IsOptLock==true) + { + this._Context.Updateable(_Roots.First()) + .EnableDiffLogEventIF(_RootOptions.IsDiffLogEvent, _RootOptions.DiffLogBizData) + .UpdateColumns(_RootOptions.UpdateColumns) + .IgnoreColumns(_RootOptions.IgnoreColumns) + .IgnoreNullColumns(_RootOptions.IsIgnoreAllNullColumns) + .ExecuteCommandWithOptLockIF(_RootOptions?.IsOptLock, _RootOptions?.IsOptLock); + } + else + { + this._Context.Updateable(_Roots) + .EnableDiffLogEventIF(_RootOptions.IsDiffLogEvent, _RootOptions.DiffLogBizData) + .UpdateColumns(_RootOptions.UpdateColumns) + .IgnoreColumns(_RootOptions.IgnoreColumns) + .IgnoreNullColumns(_RootOptions.IsIgnoreAllNullColumns) + .ExecuteCommandWithOptLockIF(_RootOptions?.IsOptLock, _RootOptions?.IsOptLock); + } } } else if (_RootOptions != null && _RootOptions?.IsDiffLogEvent == true) diff --git a/Src/Asp.Net/SqlSugar/Abstract/QueryableProvider/QueryableProvider.cs b/Src/Asp.Net/SqlSugar/Abstract/QueryableProvider/QueryableProvider.cs index c1c9f5a15..fc261f885 100644 --- a/Src/Asp.Net/SqlSugar/Abstract/QueryableProvider/QueryableProvider.cs +++ b/Src/Asp.Net/SqlSugar/Abstract/QueryableProvider/QueryableProvider.cs @@ -1703,6 +1703,7 @@ namespace SqlSugar var unionall = this.Context._UnionAll(tableQueryables.ToArray()); unionall.QueryBuilder.Includes = this.QueryBuilder.Includes; unionall.QueryBuilder.EntityType = typeof(T); + unionall.QueryBuilder.IsDisabledGobalFilter = this.QueryBuilder.IsDisabledGobalFilter; if (unionall.QueryBuilder.Includes?.Any()==true) { unionall.QueryBuilder.NoCheckInclude = true; diff --git a/Src/Asp.Net/SqlSugar/Abstract/SaveableProvider/Storageable.cs b/Src/Asp.Net/SqlSugar/Abstract/SaveableProvider/Storageable.cs index 3d258e656..a5f2e1655 100644 --- a/Src/Asp.Net/SqlSugar/Abstract/SaveableProvider/Storageable.cs +++ b/Src/Asp.Net/SqlSugar/Abstract/SaveableProvider/Storageable.cs @@ -551,6 +551,10 @@ namespace SqlSugar foreach (var item in whereColumns) { var value = item.PropertyInfo.GetValue(dataItem.Item, null); + if (value is string str&&str=="null") + { + value = $"[null]"; + } if (value != null&&value.GetType().IsEnum()) { if (this.Context.CurrentConnectionConfig.MoreSettings?.TableEnumIsString == true) diff --git a/Src/Asp.Net/SqlSugar/Abstract/SqlBuilderProvider/QueryBuilder.cs b/Src/Asp.Net/SqlSugar/Abstract/SqlBuilderProvider/QueryBuilder.cs index 3cb38fd7a..83414cd78 100644 --- a/Src/Asp.Net/SqlSugar/Abstract/SqlBuilderProvider/QueryBuilder.cs +++ b/Src/Asp.Net/SqlSugar/Abstract/SqlBuilderProvider/QueryBuilder.cs @@ -528,6 +528,13 @@ namespace SqlSugar } if (item.IsJoinQuery == false||isMain||isSingle|| isEasyJoin) { + if (item.IsJoinQuery == false&& ChildType.IsInterface) + { + foreach (var joinInfo in this.JoinQueryInfos) + { + sql = ReplaceFilterColumnName(sql, joinInfo.EntityType, Builder.GetTranslationColumnName(joinInfo.ShortName)); + } + } WhereInfos.Add(sql); } else @@ -993,7 +1000,7 @@ namespace SqlSugar } if (IsSingle() && result.Contains("MergeTable") && result.Trim().EndsWith(" MergeTable") && TableShortName != null) { - result = result.Replace(") MergeTable ", ") " + TableShortName+UtilConstants.Space); + result = result.Replace(") MergeTable ", ") " +this.Builder.GetTranslationColumnName(TableShortName)+UtilConstants.Space); TableShortName = null; } if (IsSingle() && result.Contains("unionTable") && result.Trim().EndsWith(" unionTable")&& TableShortName!=null) diff --git a/Src/Asp.Net/SqlSugar/Abstract/SqlBuilderProvider/SqlBuilderProvider_Condition.cs b/Src/Asp.Net/SqlSugar/Abstract/SqlBuilderProvider/SqlBuilderProvider_Condition.cs index 2d7daa13f..629dccb6b 100644 --- a/Src/Asp.Net/SqlSugar/Abstract/SqlBuilderProvider/SqlBuilderProvider_Condition.cs +++ b/Src/Asp.Net/SqlSugar/Abstract/SqlBuilderProvider/SqlBuilderProvider_Condition.cs @@ -373,7 +373,14 @@ namespace SqlSugar } else { - inValue1 = ("(" + inArray.Select(it => it == "" ? "null" : it).Distinct().ToArray().ToJoinSqlInVals() + ")"); + if (item.CSharpTypeName.EqualCase("nstring")) + { + inValue1 = ("(" + inArray.Select(it => it == "" ? "null" : it).Distinct().ToArray().ToJoinSqlInValsByVarchar() + ")"); + } + else + { + inValue1 = ("(" + inArray.Select(it => it == "" ? "null" : it).Distinct().ToArray().ToJoinSqlInVals() + ")"); + } } return inValue1; @@ -389,7 +396,7 @@ namespace SqlSugar { if (item.FieldValue == "[null]") { - item.FieldValue = "'null'"; + item.FieldValue = "null"; } builder.AppendFormat(temp, type, item.FieldName.ToSqlFilter(), "=", parameterName); parameters.Add(new SugarParameter(parameterName, GetFieldValue(item))); diff --git a/Src/Asp.Net/SqlSugar/Abstract/SugarProvider/SqlSugarAccessory.cs b/Src/Asp.Net/SqlSugar/Abstract/SugarProvider/SqlSugarAccessory.cs index eb8291d8f..3c774ac26 100644 --- a/Src/Asp.Net/SqlSugar/Abstract/SugarProvider/SqlSugarAccessory.cs +++ b/Src/Asp.Net/SqlSugar/Abstract/SugarProvider/SqlSugarAccessory.cs @@ -497,6 +497,10 @@ namespace SqlSugar Check.Exception(SugarCompatible.IsFramework, "OceanBaseForOracle only support .net core"); InstanceFactory.CustomDllName = SugarCompatible.IsFramework ? "SqlSugar.OceanBaseForOracle" : "SqlSugar.OceanBaseForOracleCore"; break; + case DbType.TDSQLForPGODBC: + Check.Exception(SugarCompatible.IsFramework, "TDSQLForPGODBC only support .net core"); + InstanceFactory.CustomDllName = SugarCompatible.IsFramework ? "SqlSugar.TDSQLForPGODBC" : "SqlSugar.TDSQLForPGODBC"; + break; case DbType.GaussDB: config.DbType = DbType.PostgreSQL; if (this.CurrentConnectionConfig.MoreSettings == null) @@ -518,6 +522,9 @@ namespace SqlSugar case DbType.PolarDB: config.DbType = DbType.MySql; break; + case DbType.TDSQL: + config.DbType = DbType.MySql; + break; case DbType.Doris: config.DbType = DbType.MySql; if (this.CurrentConnectionConfig.MoreSettings == null) diff --git a/Src/Asp.Net/SqlSugar/Abstract/SugarProvider/SqlSugarScopeProvider.cs b/Src/Asp.Net/SqlSugar/Abstract/SugarProvider/SqlSugarScopeProvider.cs index 03b4a29f8..06ed7440c 100644 --- a/Src/Asp.Net/SqlSugar/Abstract/SugarProvider/SqlSugarScopeProvider.cs +++ b/Src/Asp.Net/SqlSugar/Abstract/SugarProvider/SqlSugarScopeProvider.cs @@ -97,7 +97,7 @@ namespace SqlSugar } return result; } - private dynamic GetKey() + private string GetKey() { if (!string.IsNullOrEmpty(this.initkey) &&this.initThreadMainId == GetCurrentThreadId()) { diff --git a/Src/Asp.Net/SqlSugar/Abstract/UpdateProvider/UpdateableHelper.cs b/Src/Asp.Net/SqlSugar/Abstract/UpdateProvider/UpdateableHelper.cs index 6daa912f0..b084f17ff 100644 --- a/Src/Asp.Net/SqlSugar/Abstract/UpdateProvider/UpdateableHelper.cs +++ b/Src/Asp.Net/SqlSugar/Abstract/UpdateProvider/UpdateableHelper.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.Data; using System.Linq; @@ -614,7 +614,7 @@ namespace SqlSugar return mappInfo == null ? propertyName : mappInfo.DbColumnName; } } - private List GetPrimaryKeys() + protected List GetPrimaryKeys() { if (this.WhereColumnList.HasValue()) { diff --git a/Src/Asp.Net/SqlSugar/Entities/ConnMoreSettings.cs b/Src/Asp.Net/SqlSugar/Entities/ConnMoreSettings.cs index bc1effcf2..92eba05e9 100644 --- a/Src/Asp.Net/SqlSugar/Entities/ConnMoreSettings.cs +++ b/Src/Asp.Net/SqlSugar/Entities/ConnMoreSettings.cs @@ -36,5 +36,6 @@ namespace SqlSugar public int MaxParameterNameLength { get; set; } public bool DisableQueryWhereColumnRemoveTrim { get; set; } public DbType? DatabaseModel { get;set; } + public bool ClickHouseEnableFinal { get; set; } } } diff --git a/Src/Asp.Net/SqlSugar/Enum/DbType.cs b/Src/Asp.Net/SqlSugar/Enum/DbType.cs index 969a4eac3..f44d7f495 100644 --- a/Src/Asp.Net/SqlSugar/Enum/DbType.cs +++ b/Src/Asp.Net/SqlSugar/Enum/DbType.cs @@ -33,6 +33,8 @@ namespace SqlSugar Doris, Xugu, GoldenDB, + TDSQLForPGODBC, + TDSQL, Custom =900 } } diff --git a/Src/Asp.Net/SqlSugar/ExpressionsToSql/DbMethods/DefaultDbMethod.cs b/Src/Asp.Net/SqlSugar/ExpressionsToSql/DbMethods/DefaultDbMethod.cs index 1417d40de..0849774a3 100644 --- a/Src/Asp.Net/SqlSugar/ExpressionsToSql/DbMethods/DefaultDbMethod.cs +++ b/Src/Asp.Net/SqlSugar/ExpressionsToSql/DbMethods/DefaultDbMethod.cs @@ -1228,5 +1228,9 @@ namespace SqlSugar return queryCondition; } + public virtual string SelectFields(MethodCallExpressionModel model) + { + return string.Join(",", model.Args.Select(it => it.MemberName)); + } } } diff --git a/Src/Asp.Net/SqlSugar/ExpressionsToSql/DbMethods/IDbMethods.cs b/Src/Asp.Net/SqlSugar/ExpressionsToSql/DbMethods/IDbMethods.cs index 113292137..0561caf12 100644 --- a/Src/Asp.Net/SqlSugar/ExpressionsToSql/DbMethods/IDbMethods.cs +++ b/Src/Asp.Net/SqlSugar/ExpressionsToSql/DbMethods/IDbMethods.cs @@ -128,5 +128,6 @@ namespace SqlSugar string NewUid(MethodCallExpressionModel mode); string FullTextContains(MethodCallExpressionModel mode); string PgsqlArrayContains(MethodCallExpressionModel model); + string SelectFields(MethodCallExpressionModel model); } } diff --git a/Src/Asp.Net/SqlSugar/ExpressionsToSql/DbMethods/SqlFunc.cs b/Src/Asp.Net/SqlSugar/ExpressionsToSql/DbMethods/SqlFunc.cs index e732d0f1a..0062a5f05 100644 --- a/Src/Asp.Net/SqlSugar/ExpressionsToSql/DbMethods/SqlFunc.cs +++ b/Src/Asp.Net/SqlSugar/ExpressionsToSql/DbMethods/SqlFunc.cs @@ -431,5 +431,25 @@ namespace SqlSugar { throw new NotSupportedException("Can only be used in expressions"); } + public static void SelectFields(string fieldName1) + { + throw new NotSupportedException("Can only be used in expressions"); + } + public static void SelectFields(string fieldName1,string fieldName2) + { + throw new NotSupportedException("Can only be used in expressions"); + } + public static void SelectFields(string fieldName1, string fieldName2, string fieldName3) + { + throw new NotSupportedException("Can only be used in expressions"); + } + public static void SelectFields(string fieldName1, string fieldName2, string fieldName3, string fieldName4) + { + throw new NotSupportedException("Can only be used in expressions"); + } + public static void SelectFields(string fieldName1, string fieldName2, string fieldName3, string fieldName4, string fieldName5) + { + throw new NotSupportedException("Can only be used in expressions"); + } } } diff --git a/Src/Asp.Net/SqlSugar/Infrastructure/StaticConfig.cs b/Src/Asp.Net/SqlSugar/Infrastructure/StaticConfig.cs index c57078958..5cb438a76 100644 --- a/Src/Asp.Net/SqlSugar/Infrastructure/StaticConfig.cs +++ b/Src/Asp.Net/SqlSugar/Infrastructure/StaticConfig.cs @@ -16,6 +16,7 @@ namespace SqlSugar public const string CodeFirst_BigString = "varcharmax,longtext,text,clob"; public static string CodeFirst_MySqlCollate{get;set;} public static string CodeFirst_MySqlTableEngine { get; set; } + public static Type Backup_MySqlBackupType { get; set; } public static Func CustomSnowFlakeFunc; public static Func CustomSnowFlakeTimeErrorFunc; diff --git a/Src/Asp.Net/SqlSugar/Utilities/DbExtensions.cs b/Src/Asp.Net/SqlSugar/Utilities/DbExtensions.cs index 00d39e0d2..e148bcb45 100644 --- a/Src/Asp.Net/SqlSugar/Utilities/DbExtensions.cs +++ b/Src/Asp.Net/SqlSugar/Utilities/DbExtensions.cs @@ -18,6 +18,17 @@ namespace SqlSugar return string.Join(",", array.Where(c => c != null).Select(it => it.ToSqlValue())); } } + public static string ToJoinSqlInValsByVarchar(this T[] array) + { + if (array == null || array.Length == 0) + { + return ToSqlValue(string.Empty); + } + else + { + return string.Join(",", array.Where(c => c != null).Select(it => "N"+it.ToSqlValue())); + } + } public static string ToJoinSqlInValsN(this T[] array) { if (array == null || array.Length == 0) diff --git a/Src/Asp.Net/SqlSugar/Utilities/UtilMethods.cs b/Src/Asp.Net/SqlSugar/Utilities/UtilMethods.cs index 91b75dc64..39970cc80 100644 --- a/Src/Asp.Net/SqlSugar/Utilities/UtilMethods.cs +++ b/Src/Asp.Net/SqlSugar/Utilities/UtilMethods.cs @@ -711,7 +711,8 @@ namespace SqlSugar MaxParameterNameLength=it.MoreSettings.MaxParameterNameLength, DisableQueryWhereColumnRemoveTrim=it.MoreSettings.DisableQueryWhereColumnRemoveTrim, DatabaseModel=it.MoreSettings.DatabaseModel, - EnableILike=it.MoreSettings.EnableILike + EnableILike=it.MoreSettings.EnableILike, + ClickHouseEnableFinal=it.MoreSettings.ClickHouseEnableFinal }, SqlMiddle = it.SqlMiddle == null ? null : new SqlMiddle @@ -1392,6 +1393,14 @@ namespace SqlSugar { return Convert.ToInt64(item.FieldValue); } + else if (item.CSharpTypeName.EqualCase("float")) + { + return Convert.ToSingle(item.FieldValue); + } + else if (item.CSharpTypeName.EqualCase("single")) + { + return Convert.ToSingle(item.FieldValue); + } else if (item.CSharpTypeName.EqualCase("short")) { return Convert.ToInt16(item.FieldValue);