- 修复 Oracle CodeFirst clob/blob cast 转换问题;

This commit is contained in:
2881099
2025-02-10 19:00:14 +08:00
parent 2f32bb6165
commit 2695de562f
4 changed files with 13 additions and 17 deletions

View File

@@ -353,8 +353,9 @@ and not exists(select 1 from all_constraints where constraint_name = a.index_nam
insertvalue = _commonUtils.QuoteSqlName(tbstructcol.column); insertvalue = _commonUtils.QuoteSqlName(tbstructcol.column);
if (tbcol.Attribute.DbType.StartsWith(tbstructcol.sqlType, StringComparison.CurrentCultureIgnoreCase) == false) if (tbcol.Attribute.DbType.StartsWith(tbstructcol.sqlType, StringComparison.CurrentCultureIgnoreCase) == false)
{ {
var dbtypeNoneNotNull = Regex.Replace(tbcol.Attribute.DbType, @"(NOT\s+)?NULL", ""); var dbtypeNoneNotNull = Regex.Replace(tbcol.Attribute.DbType, @"(NOT\s+)?NULL", "").Trim();
insertvalue = $"cast({insertvalue} as {dbtypeNoneNotNull})"; if (dbtypeNoneNotNull != "CLOB" && dbtypeNoneNotNull != "BLOB")
insertvalue = $"cast({insertvalue} as {dbtypeNoneNotNull})";
} }
if (tbcol.Attribute.IsNullable != tbstructcol.is_nullable) if (tbcol.Attribute.IsNullable != tbstructcol.is_nullable)
insertvalue = $"nvl({insertvalue},{tbcol.DbDefaultValue})"; insertvalue = $"nvl({insertvalue},{tbcol.DbDefaultValue})";

View File

@@ -359,18 +359,11 @@ and not exists(select 1 from all_constraints where index_name = a.index_name and
if (tbcol.Attribute.DbType.StartsWith(tbstructcol.sqlType, StringComparison.CurrentCultureIgnoreCase) == false) if (tbcol.Attribute.DbType.StartsWith(tbstructcol.sqlType, StringComparison.CurrentCultureIgnoreCase) == false)
{ {
var dbtypeNoneNotNull = Regex.Replace(tbcol.Attribute.DbType, @"(NOT\s+)?NULL", ""); var dbtypeNoneNotNull = Regex.Replace(tbcol.Attribute.DbType, @"(NOT\s+)?NULL", "");
var charMatch = Regex.Match(dbtypeNoneNotNull, "(N?)VARCHAR(2?)\\((?<precision>[0-9]+)\\)"); var charMatch = Regex.Match(dbtypeNoneNotNull, "(N?)VARCHAR(2?)\\((?<precision>[0-9]+)\\)");
if (charMatch != null && ushort.TryParse(charMatch.Groups["precision"]?.Value, out var precision))
if(charMatch != null) dbtypeNoneNotNull = Regex.Replace(dbtypeNoneNotNull, $"\\(({precision})\\)", $"");
{ if (dbtypeNoneNotNull != "CLOB" && dbtypeNoneNotNull != "BLOB")
if (ushort.TryParse(charMatch.Groups["precision"]?.Value, out var precision)) insertvalue = $"cast({insertvalue} as {dbtypeNoneNotNull})";
{
dbtypeNoneNotNull = Regex.Replace(dbtypeNoneNotNull, $"\\(({precision})\\)", $"");
}
}
insertvalue = $"cast({insertvalue} as {dbtypeNoneNotNull})";
} }
if (tbcol.Attribute.IsNullable != tbstructcol.is_nullable) if (tbcol.Attribute.IsNullable != tbstructcol.is_nullable)
insertvalue = $"nvl({insertvalue},{tbcol.DbDefaultValue})"; insertvalue = $"nvl({insertvalue},{tbcol.DbDefaultValue})";

View File

@@ -355,8 +355,9 @@ and not exists(select 1 from all_constraints where constraint_name = a.index_nam
insertvalue = _commonUtils.QuoteSqlName(tbstructcol.column); insertvalue = _commonUtils.QuoteSqlName(tbstructcol.column);
if (tbcol.Attribute.DbType.StartsWith(tbstructcol.sqlType, StringComparison.CurrentCultureIgnoreCase) == false) if (tbcol.Attribute.DbType.StartsWith(tbstructcol.sqlType, StringComparison.CurrentCultureIgnoreCase) == false)
{ {
var dbtypeNoneNotNull = Regex.Replace(tbcol.Attribute.DbType, @"(NOT\s+)?NULL", ""); var dbtypeNoneNotNull = Regex.Replace(tbcol.Attribute.DbType, @"(NOT\s+)?NULL", "").Trim();
insertvalue = $"cast({insertvalue} as {dbtypeNoneNotNull})"; if (dbtypeNoneNotNull != "CLOB" && dbtypeNoneNotNull != "BLOB")
insertvalue = $"cast({insertvalue} as {dbtypeNoneNotNull})";
} }
if (tbcol.Attribute.IsNullable != tbstructcol.is_nullable) if (tbcol.Attribute.IsNullable != tbstructcol.is_nullable)
insertvalue = $"nvl({insertvalue},{tbcol.DbDefaultValue})"; insertvalue = $"nvl({insertvalue},{tbcol.DbDefaultValue})";

View File

@@ -390,8 +390,9 @@ and not exists(select 1 from all_constraints where constraint_name = a.index_nam
insertvalue = _commonUtils.QuoteSqlName(tbstructcol.column); insertvalue = _commonUtils.QuoteSqlName(tbstructcol.column);
if (tbcol.Attribute.DbType.StartsWith(tbstructcol.sqlType, StringComparison.CurrentCultureIgnoreCase) == false) if (tbcol.Attribute.DbType.StartsWith(tbstructcol.sqlType, StringComparison.CurrentCultureIgnoreCase) == false)
{ {
var dbtypeNoneNotNull = Regex.Replace(tbcol.Attribute.DbType, @"(NOT\s+)?NULL", ""); var dbtypeNoneNotNull = Regex.Replace(tbcol.Attribute.DbType, @"(NOT\s+)?NULL", "").Trim();
insertvalue = $"cast({insertvalue} as {dbtypeNoneNotNull})"; if (dbtypeNoneNotNull != "CLOB" && dbtypeNoneNotNull != "BLOB")
insertvalue = $"cast({insertvalue} as {dbtypeNoneNotNull})";
} }
if (tbcol.Attribute.IsNullable != tbstructcol.is_nullable) if (tbcol.Attribute.IsNullable != tbstructcol.is_nullable)
insertvalue = $"nvl({insertvalue},{tbcol.DbDefaultValue})"; insertvalue = $"nvl({insertvalue},{tbcol.DbDefaultValue})";