Skip to content

Commit

Permalink
Correctly map unsigned database types with precision, scale, size o…
Browse files Browse the repository at this point in the history
…r display width to CLR types.
  • Loading branch information
lauxjpn committed Oct 24, 2019
1 parent e7aca63 commit e5a6e21
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions src/EFCore.MySql/Storage/Internal/MySqlTypeMappingSource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -440,5 +440,47 @@ private RelationalTypeMapping FindRawMapping(RelationalTypeMappingInfo mappingIn

return null;
}

protected override string ParseStoreTypeName(string storeTypeName, out bool? unicode, out int? size, out int? precision, out int? scale)
{
unicode = null;
size = null;
precision = null;
scale = null;

if (storeTypeName != null)
{
var openParen = storeTypeName.IndexOf("(", StringComparison.Ordinal);
if (openParen > 0)
{
var closeParen = storeTypeName.IndexOf(")", openParen + 1, StringComparison.Ordinal);
if (closeParen > openParen)
{
var comma = storeTypeName.IndexOf(",", openParen + 1, StringComparison.Ordinal);
if (comma > openParen && comma < closeParen)
{
if (int.TryParse(storeTypeName.Substring(openParen + 1, comma - openParen - 1), out var parsedPrecision))
{
precision = parsedPrecision;
}

if (int.TryParse(storeTypeName.Substring(comma + 1, closeParen - comma - 1), out var parsedScale))
{
scale = parsedScale;
}
}
else if (int.TryParse(storeTypeName.Substring(openParen + 1, closeParen - openParen - 1).Trim(), out var parsedSize))
{
size = parsedSize;
precision = parsedSize;
}

return (storeTypeName.Substring(0, openParen) + storeTypeName.Substring(closeParen + 1)).Trim();
}
}
}

return storeTypeName;
}
}
}

0 comments on commit e5a6e21

Please sign in to comment.