Skip to content

Commit

Permalink
Correctly handle bit default values that use the b'01' syntax. (#956)
Browse files Browse the repository at this point in the history
  • Loading branch information
lauxjpn authored Nov 22, 2019
1 parent a65a3ce commit f9c67dc
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions src/EFCore.MySql/Scaffolding/Internal/MySqlDatabaseModelFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -315,20 +315,26 @@ private static string FilterClrDefaults(string dataTypeName, bool nullable, stri

private string CreateDefaultValueString(string defaultValue, string dataType)
{
if (defaultValue == null)
{
return null;
}

// Pending the MySqlConnector implement MySqlCommandBuilder class
if (string.Equals(dataType, "timestamp", StringComparison.OrdinalIgnoreCase)
&& string.Equals(defaultValue, "CURRENT_TIMESTAMP", StringComparison.OrdinalIgnoreCase))
{
return defaultValue;
}
else if (defaultValue != null)
{
return "'" + defaultValue.Replace(@"\", @"\\").Replace("'", "''") + "'";
}
else

// Handle bit values.
if (string.Equals(dataType, "bit", StringComparison.OrdinalIgnoreCase)
&& defaultValue.StartsWith("b'"))
{
return null;
return defaultValue;
}

return "'" + defaultValue.Replace(@"\", @"\\").Replace("'", "''") + "'";
}

private const string GetPrimaryQuery = @"SELECT `INDEX_NAME`,
Expand Down

0 comments on commit f9c67dc

Please sign in to comment.