Skip to content

Commit

Permalink
Merge pull request #1922 from EsonXie/master
Browse files Browse the repository at this point in the history
fix:修复升级达梦数据库的表结构时由于select中字符串精读问题,而导致字符串截取的问题
  • Loading branch information
2881099 authored Nov 13, 2024
2 parents c986a1d + e882269 commit 59e61e7
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 0 deletions.
69 changes: 69 additions & 0 deletions FreeSql.Tests/FreeSql.Tests/Dameng/DamengCodeFirstTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -454,5 +454,74 @@ class TableAllType

public enum TableAllTypeEnumType1 { e1, e2, e3, e5 }
[Flags] public enum TableAllTypeEnumType2 { f1, f2, f3 }



[Fact]
public void UpgradeTableStructure()
{
g.dameng.CodeFirst.SyncStructure<TableUpgradeTest>();

g.dameng.Delete<TableUpgradeTest>()
.Where(item => 1 == 1)
.ExecuteAffrows();

var text = new StringBuilder();
var temp = "1234567890哈";
for (int i = 0; i < 3000 - temp.Length; i+= temp.Length)
{
text.Append(temp);
}

var mode = new TableUpgradeTest
{
Name = "1234560123456012哈哈哈哈哈呵呵_123123",
Text = text.ToString(),
Text2 = "呵呵呵Test123123123"
};

mode.Id = g.dameng.Insert(mode)
.ExecuteIdentity();

// 第二次进行数据库结果同步
var sql = g.dameng.CodeFirst.GetComparisonDDLStatements<TableUpgradeTest>();
g.dameng.Ado.ExecuteNonQuery(sql);
//g.dameng.CodeFirst.SyncStructure<TableSubString>();

var resultMode = g.dameng.Select<TableUpgradeTest>()
.Where(item => item.Id == mode.Id)
.First();

Assert.Equal(mode.Name, resultMode?.Name);
Assert.Equal(mode.Text, resultMode?.Text);
Assert.Equal(mode.Text2, resultMode?.Text2);
Assert.Equal(mode.Text3, resultMode?.Text3);

}

[Table(Name = "tb_upgrade_test")]
public class TableUpgradeTest
{
[Column(Name = "id", IsPrimary = true, IsIdentity = true)]
public long Id { get; set; }


[Column(Name = "name", StringLength = 31, IsNullable = false)]
public string Name { get; set; }

[Column(Name = "text", StringLength = 32767, IsNullable = false)]
public string Text { get; set; }

[Column(Name = "number_test", IsNullable = false)]
public int TestNumber { get; set; }

[Column(Name = "text2", StringLength = 63)]
public string Text2 { get; set; }


[Column(Name = "text3")]
public string Text3 { get; set; }
}

}
}
11 changes: 11 additions & 0 deletions Providers/FreeSql.Provider.Dameng/DamengCodeFirst.cs
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,17 @@ and a.owner in ({0}) and a.table_name in ({1})
if (tbcol.Attribute.DbType.StartsWith(tbstructcol.sqlType, StringComparison.CurrentCultureIgnoreCase) == false)
{
var dbtypeNoneNotNull = Regex.Replace(tbcol.Attribute.DbType, @"(NOT\s+)?NULL", "");

var charMatch = Regex.Match(dbtypeNoneNotNull, "(N?)VARCHAR(2?)\\((?<precision>[0-9]+)\\)");

if(charMatch != null)
{
if (ushort.TryParse(charMatch.Groups["precision"]?.Value, out var precision))
{
dbtypeNoneNotNull = Regex.Replace(dbtypeNoneNotNull, $"\\(({precision})\\)", $"");
}
}

insertvalue = $"cast({insertvalue} as {dbtypeNoneNotNull})";
}
if (tbcol.Attribute.IsNullable != tbstructcol.is_nullable)
Expand Down

0 comments on commit 59e61e7

Please sign in to comment.