From 8cca3dfad534ab34c8d426ee8bd0bf628bdef33e Mon Sep 17 00:00:00 2001 From: sunkaixuan <610262374@qq.com> Date: Mon, 21 Apr 2025 20:15:02 +0800 Subject: [PATCH] Synchronous code --- .../SqlSugar/Entities/ConnMoreSettings.cs | 1 + .../DbMaintenance/PostgreSQLDbMaintenance.cs | 40 ++++++++++++++----- Src/Asp.Net/SqlSugar/Utilities/UtilMethods.cs | 3 +- 3 files changed, 34 insertions(+), 10 deletions(-) diff --git a/Src/Asp.Net/SqlSugar/Entities/ConnMoreSettings.cs b/Src/Asp.Net/SqlSugar/Entities/ConnMoreSettings.cs index 92eba05e9..17ece3ae5 100644 --- a/Src/Asp.Net/SqlSugar/Entities/ConnMoreSettings.cs +++ b/Src/Asp.Net/SqlSugar/Entities/ConnMoreSettings.cs @@ -16,6 +16,7 @@ namespace SqlSugar public bool DisableMillisecond { get; set; } public bool PgSqlIsAutoToLower { get; set; } = true; public bool PgSqlIsAutoToLowerCodeFirst { get; set; } = true; + public bool PgSqlIsAutoToLowerSchema{ get; set; } = true; public bool EnableILike { get; set; } public bool IsAutoToUpper { get; set; } = true; public int DefaultCacheDurationInSeconds { get; set; } diff --git a/Src/Asp.Net/SqlSugar/Realization/PostgreSQL/DbMaintenance/PostgreSQLDbMaintenance.cs b/Src/Asp.Net/SqlSugar/Realization/PostgreSQL/DbMaintenance/PostgreSQLDbMaintenance.cs index 44627f5f9..b91227e58 100644 --- a/Src/Asp.Net/SqlSugar/Realization/PostgreSQL/DbMaintenance/PostgreSQLDbMaintenance.cs +++ b/Src/Asp.Net/SqlSugar/Realization/PostgreSQL/DbMaintenance/PostgreSQLDbMaintenance.cs @@ -603,23 +603,45 @@ WHERE tgrelid = '"+tableName+"'::regclass"); private string GetSchema() { var schema = "public"; - if (System.Text.RegularExpressions.Regex.IsMatch(this.Context.CurrentConnectionConfig.ConnectionString.ToLower(), "searchpath=")) + var pgSqlIsAutoToLowerSchema = this.Context?.CurrentConnectionConfig?.MoreSettings?.PgSqlIsAutoToLowerSchema == false; + if (pgSqlIsAutoToLowerSchema) { - var regValue = System.Text.RegularExpressions.Regex.Match(this.Context.CurrentConnectionConfig.ConnectionString.ToLower(), @"searchpath\=(\w+)").Groups[1].Value; - if (regValue.HasValue()) + if (System.Text.RegularExpressions.Regex.IsMatch(this.Context.CurrentConnectionConfig.ConnectionString, "searchpath=", RegexOptions.IgnoreCase)) { - schema = regValue; + var regValue = System.Text.RegularExpressions.Regex.Match(this.Context.CurrentConnectionConfig.ConnectionString, @"searchpath\=(\w+)").Groups[1].Value; + if (regValue.HasValue()) + { + schema = regValue; + } + } + else if (System.Text.RegularExpressions.Regex.IsMatch(this.Context.CurrentConnectionConfig.ConnectionString, "search path=", RegexOptions.IgnoreCase)) + { + var regValue = System.Text.RegularExpressions.Regex.Match(this.Context.CurrentConnectionConfig.ConnectionString.ToLower(), @"search path\=(\w+)").Groups[1].Value; + if (regValue.HasValue()) + { + schema = regValue; + } } } - else if (System.Text.RegularExpressions.Regex.IsMatch(this.Context.CurrentConnectionConfig.ConnectionString.ToLower(), "search path=")) + else { - var regValue = System.Text.RegularExpressions.Regex.Match(this.Context.CurrentConnectionConfig.ConnectionString.ToLower(), @"search path\=(\w+)").Groups[1].Value; - if (regValue.HasValue()) + if (System.Text.RegularExpressions.Regex.IsMatch(this.Context.CurrentConnectionConfig.ConnectionString.ToLower(), "searchpath=")) { - schema = regValue; + var regValue = System.Text.RegularExpressions.Regex.Match(this.Context.CurrentConnectionConfig.ConnectionString.ToLower(), @"searchpath\=(\w+)").Groups[1].Value; + if (regValue.HasValue()) + { + schema = regValue; + } + } + else if (System.Text.RegularExpressions.Regex.IsMatch(this.Context.CurrentConnectionConfig.ConnectionString.ToLower(), "search path=")) + { + var regValue = System.Text.RegularExpressions.Regex.Match(this.Context.CurrentConnectionConfig.ConnectionString.ToLower(), @"search path\=(\w+)").Groups[1].Value; + if (regValue.HasValue()) + { + schema = regValue; + } } } - return schema; } private static void ConvertCreateColumnInfo(DbColumnInfo x) diff --git a/Src/Asp.Net/SqlSugar/Utilities/UtilMethods.cs b/Src/Asp.Net/SqlSugar/Utilities/UtilMethods.cs index f6c0ef402..21248f1fa 100644 --- a/Src/Asp.Net/SqlSugar/Utilities/UtilMethods.cs +++ b/Src/Asp.Net/SqlSugar/Utilities/UtilMethods.cs @@ -728,7 +728,8 @@ namespace SqlSugar DisableQueryWhereColumnRemoveTrim=it.MoreSettings.DisableQueryWhereColumnRemoveTrim, DatabaseModel=it.MoreSettings.DatabaseModel, EnableILike=it.MoreSettings.EnableILike, - ClickHouseEnableFinal=it.MoreSettings.ClickHouseEnableFinal + ClickHouseEnableFinal=it.MoreSettings.ClickHouseEnableFinal, + PgSqlIsAutoToLowerSchema=it.MoreSettings.PgSqlIsAutoToLowerSchema }, SqlMiddle = it.SqlMiddle == null ? null : new SqlMiddle