From e67860e0afed0070f9f0dfc7e7ad62f4a6be4f11 Mon Sep 17 00:00:00 2001 From: sunkaixuan <610262374@qq.com> Date: Thu, 7 Dec 2023 04:19:11 +0800 Subject: [PATCH] Synchronization code --- Src/Asp.Net/SqlSugar/Infrastructure/StaticConfig.cs | 8 +++++--- .../MySql/DbMaintenance/MySqlDbMaintenance.cs | 13 ++++++++++++- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/Src/Asp.Net/SqlSugar/Infrastructure/StaticConfig.cs b/Src/Asp.Net/SqlSugar/Infrastructure/StaticConfig.cs index 092e5b8c5..27bac9b3a 100644 --- a/Src/Asp.Net/SqlSugar/Infrastructure/StaticConfig.cs +++ b/Src/Asp.Net/SqlSugar/Infrastructure/StaticConfig.cs @@ -9,11 +9,13 @@ namespace SqlSugar public class StaticConfig { public static bool EnableAot { get; set; } - public static Func Encode { get; set; } - public static Func Decode{ get; set; } - public static bool AppContext_ConvertInfinityDateTime { get; set; } + public static Func Encode { get; set; } + public static Func Decode { get; set; } + public static bool AppContext_ConvertInfinityDateTime { get; set; } public const string CodeFirst_BigString = "varcharmax,longtext,text,clob"; + public static string CodeFirst_MySqlCollate{get;set;} + public static Func CustomSnowFlakeFunc; public static Func CustomSnowFlakeTimeErrorFunc; public static Func CustomGuidFunc; diff --git a/Src/Asp.Net/SqlSugar/Realization/MySql/DbMaintenance/MySqlDbMaintenance.cs b/Src/Asp.Net/SqlSugar/Realization/MySql/DbMaintenance/MySqlDbMaintenance.cs index 2449ce86d..2b42bb1ee 100644 --- a/Src/Asp.Net/SqlSugar/Realization/MySql/DbMaintenance/MySqlDbMaintenance.cs +++ b/Src/Asp.Net/SqlSugar/Realization/MySql/DbMaintenance/MySqlDbMaintenance.cs @@ -372,7 +372,7 @@ WHERE EVENT_OBJECT_TABLE = '"+tableName+"'"); public override bool CreateDatabase(string databaseName, string databaseDirectory = null) { - if (this.Context.Ado.IsValidConnection()) + if (this.Context.Ado.IsValidConnection()) { return true; } @@ -415,6 +415,17 @@ WHERE EVENT_OBJECT_TABLE = '"+tableName+"'"); { createSql = createSql.Replace("utf8 COLLATE utf8_general_ci", "utf8mb4"); } + if (!string.IsNullOrEmpty(StaticConfig.CodeFirst_MySqlCollate)) + { + if (createSql.Contains(" COLLATE ")) + { + createSql = $" {Regex.Split(createSql, " COLLATE ").First()} COLLATE {StaticConfig.CodeFirst_MySqlCollate} "; + } + else + { + createSql += $" COLLATE {StaticConfig.CodeFirst_MySqlCollate} "; + } + } newDb.Ado.ExecuteCommand(string.Format(createSql, databaseName, databaseDirectory)); } return true;