Update oracle

This commit is contained in:
sunkaixuan 2024-01-10 14:49:57 +08:00
parent 55d84bbbbe
commit 2efbf34166
3 changed files with 9 additions and 2 deletions

View File

@ -232,7 +232,7 @@ namespace SqlSugar
string sql = string.Format(this.AddPrimaryKeySql, tableName, string.Format("PK_{0}_{1}", this.SqlBuilder.GetNoTranslationColumnName(tableName), this.SqlBuilder.GetNoTranslationColumnName(columnName)), columnName);
if ((tableName+columnName).Length>25 &&this.Context?.CurrentConnectionConfig?.MoreSettings?.MaxParameterNameLength > 0)
{
sql = string.Format(this.AddPrimaryKeySql, tableName, string.Format("PK_{0}_{1}", this.SqlBuilder.GetNoTranslationColumnName(tableName).SafeSubstring(0,20), "Id"), columnName);
sql = string.Format(this.AddPrimaryKeySql, tableName, string.Format("PK_{0}_{1}", this.SqlBuilder.GetNoTranslationColumnName(tableName).GetNonNegativeHashCodeString(), "Id"), columnName);
}
this.Context.Ado.ExecuteCommand(sql);
return true;

View File

@ -11,6 +11,13 @@ namespace SqlSugar
{
public static class CommonExtensions
{
public static string GetNonNegativeHashCodeString(this string input)
{
// 获取哈希码,然后取绝对值,转换为字符串
string hashCode = "hs"+Math.Abs(input.GetHashCode());
return hashCode;
}
public static string SafeSubstring(this string str, int startIndex, int length)
{
if (str == null)

View File

@ -821,7 +821,7 @@ namespace SqlSugar
var maxLength = db.CurrentConnectionConfig.MoreSettings.MaxParameterNameLength;
if (newName.Length > maxLength)
{
newName = name.SafeSubstring(0,20) + "_" + addIndex;
newName = name.GetNonNegativeHashCodeString() + "_" + addIndex;
}
appendSql = ReplaceSqlParameter(appendSql, parameter, newName);
parameter.ParameterName = newName;