Skip to content

Commit

Permalink
[improvment] 反向工程中,On级别支持扩大字符串长度,这是常用操作,并且不会丢失数据
Browse files Browse the repository at this point in the history
  • Loading branch information
nnhy committed Nov 1, 2023
1 parent 6792371 commit c6bdaf2
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 7 deletions.
8 changes: 6 additions & 2 deletions XCode/DataAccessLayer/MetaData/DbMetaData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -208,18 +208,22 @@ protected static DbTable Select(DbTable ds, String name, Object value)

static StringBuilder Append(StringBuilder sb, String separator, String value)
{
if (value.IsNullOrEmpty()) return sb;

if (sb.Length > 0) sb.Append(separator);

if (value != null) sb.Append(value);
sb.Append(value);

return sb;
}

static StringBuilder Append(StringBuilder sb, Char separator, String value)
{
if (value.IsNullOrEmpty()) return sb;

if (sb.Length > 0) sb.Append(separator);

if (value != null) sb.Append(value);
sb.Append(value);

return sb;
}
Expand Down
18 changes: 15 additions & 3 deletions XCode/DataAccessLayer/MetaData/DbMetaData_Negative.cs
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ protected virtual String CheckColumnsChange(IDataTable entitytable, IDataTable d
PerformSchema(sb, @readonly || onlyCreate, DDLSchema.AlterColumn, item, dbf);
}
else if (IsColumnLengthChanged(item, dbf, entityDb))
PerformSchema(sb, @readonly || onlyCreate, DDLSchema.AlterColumn, item, dbf);
PerformSchema(sb, @readonly, DDLSchema.AlterColumn, item, dbf);
else if (IsColumnChanged(item, dbf, entityDb))
PerformSchema(sb, @readonly || onlyCreate, DDLSchema.AlterColumn, item, dbf);

Expand Down Expand Up @@ -441,10 +441,22 @@ protected virtual Boolean IsColumnChanged(IDataColumn entityColumn, IDataColumn
// 是否已改变
var isChanged = false;

// 仅针对字符串类型比较长度
if (!isChanged && entityColumn.DataType == typeof(String) && entityColumn.Length != dbColumn.Length)
{
isChanged = true;

// 如果是大文本类型,长度可能不等
if ((entityColumn.Length > Database.LongTextLength || entityColumn.Length <= 0)
&& (entityDb != null && dbColumn.Length > entityDb.LongTextLength || dbColumn.Length <= 0)
|| dbColumn.RawType.EqualIgnoreCase("ntext", "text", "sysname"))
isChanged = false;
}

return isChanged;
}

/// <summary>检查字段是否有改变,除了默认值和备注以外</summary>
/// <summary>检查字段长度是否扩大</summary>
/// <param name="entityColumn"></param>
/// <param name="dbColumn"></param>
/// <param name="entityDb"></param>
Expand All @@ -455,7 +467,7 @@ protected virtual Boolean IsColumnLengthChanged(IDataColumn entityColumn, IDataC
var isChanged = false;

// 仅针对字符串类型比较长度
if (!isChanged && entityColumn.DataType == typeof(String) && entityColumn.Length != dbColumn.Length)
if (!isChanged && entityColumn.DataType == typeof(String) && entityColumn.Length > dbColumn.Length)
{
isChanged = true;

Expand Down
4 changes: 2 additions & 2 deletions XCode/DataAccessLayer/MetaData/DbMetaData_Positive.cs
Original file line number Diff line number Diff line change
Expand Up @@ -330,9 +330,9 @@ protected virtual void FixIndex(IDataIndex index, DataRow dr) { }

#region 数据类型
/// <summary>类型映射</summary>
protected IDictionary<Type, String[]> Types { get; set; }
protected IDictionary<Type, String[]> Types { get; set; } = null!;

protected List<KeyValuePair<Type, Type>> _FieldTypeMaps;
protected List<KeyValuePair<Type, Type>>? _FieldTypeMaps;
/// <summary>字段类型映射</summary>
protected virtual List<KeyValuePair<Type, Type>> FieldTypeMaps
{
Expand Down

0 comments on commit c6bdaf2

Please sign in to comment.