|
|
@ -375,7 +375,12 @@ namespace SqlSugar |
|
|
|
}); |
|
|
|
if (!GetDataBaseList(newDb).Any(it => it.Equals(databaseName, StringComparison.CurrentCultureIgnoreCase))) |
|
|
|
{ |
|
|
|
newDb.Ado.ExecuteCommand(string.Format(CreateDataBaseSql, databaseName, databaseDirectory)); |
|
|
|
var createSql = CreateDataBaseSql; |
|
|
|
if (ContainsCharSet("utf8mb4")) |
|
|
|
{ |
|
|
|
createSql = createSql.Replace("utf8 COLLATE utf8_general_ci", "utf8mb4"); |
|
|
|
} |
|
|
|
newDb.Ado.ExecuteCommand(string.Format(createSql, databaseName, databaseDirectory)); |
|
|
|
} |
|
|
|
return true; |
|
|
|
} |
|
|
@ -405,7 +410,6 @@ namespace SqlSugar |
|
|
|
} |
|
|
|
sql = sql.Replace("$PrimaryKey", primaryKeyInfo); |
|
|
|
this.Context.Ado.ExecuteCommand(sql); |
|
|
|
SetCharSet(tableName, "utf8mb4"); |
|
|
|
return true; |
|
|
|
} |
|
|
|
public override bool AddRemark(EntityInfo entity) |
|
|
@ -593,12 +597,15 @@ namespace SqlSugar |
|
|
|
|
|
|
|
#endregion
|
|
|
|
#region Helper
|
|
|
|
private void SetCharSet(string tableName, string charset) |
|
|
|
private bool ContainsCharSet(string charset) |
|
|
|
{ |
|
|
|
if (this.Context.CurrentConnectionConfig.ConnectionString.ObjToString().ToLower().Contains(charset)) |
|
|
|
{ |
|
|
|
var name = this.SqlBuilder.GetTranslationTableName(tableName); |
|
|
|
this.Context.Ado.ExecuteCommand($"ALTER TABLE {name} CONVERT TO CHARACTER SET utf8mb4;"); |
|
|
|
return true; |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
return false; |
|
|
|
} |
|
|
|
} |
|
|
|
#endregion
|
|
|
|