Skip to content

Commit

Permalink
Merge pull request #628 from caleblloyd/bugfix_rename
Browse files Browse the repository at this point in the history
drop invalid unicode escape; add default to MODIFY COLUMN
  • Loading branch information
caleblloyd authored Jul 3, 2018
2 parents b6f57df + 83f448c commit cb5740a
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 19 deletions.
19 changes: 2 additions & 17 deletions src/EFCore.MySql/Migrations/MySqlMigrationsSqlGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -137,30 +137,15 @@ protected override void Generate(
operation.IsFixedLength,
operation.IsRowVersion,
operation.IsNullable,
/*defaultValue:*/ null,
/*defaultValueSql:*/ null,
operation.DefaultValue,
operation.DefaultValueSql,
operation.ComputedColumnSql,
/*identity:*/ false,
operation,
model,
builder);

builder.AppendLine(Dependencies.SqlGenerationHelper.StatementTerminator);

if (operation.DefaultValue != null
|| operation.DefaultValueSql != null)
{
builder
.Append("ALTER TABLE ")
.Append(Dependencies.SqlGenerationHelper.DelimitIdentifier(operation.Table, operation.Schema))
.Append(" ADD");
DefaultValue(operation.DefaultValue, operation.DefaultValueSql, builder);
builder
.Append(" FOR ")
.Append(Dependencies.SqlGenerationHelper.DelimitIdentifier(operation.Name))
.AppendLine(Dependencies.SqlGenerationHelper.StatementTerminator);
}

builder.EndCommand();
}

Expand Down
5 changes: 4 additions & 1 deletion src/EFCore.MySql/Storage/Internal/MySqlStringTypeMapping.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,9 @@ protected override void ConfigureParameter(DbParameter parameter)
: -1;
}

// eventually Unicode strings can be escaped with U'string'
// see https://dev.mysql.com/worklog/task/?id=3529
// until this change is made in MySQL, there is no way to escape unicode strings
/// <summary>
/// Generates the SQL representation of a literal value.
/// </summary>
Expand All @@ -100,7 +103,7 @@ protected override void ConfigureParameter(DbParameter parameter)
/// </returns>
protected override string GenerateNonNullSqlLiteral(object value)
=> IsUnicode
? $"N'{EscapeSqlLiteral((string)value)}'" // Interpolation okay; strings
? $"'{EscapeSqlLiteral((string)value)}'" // Interpolation okay; strings
: $"'{EscapeSqlLiteral((string)value)}'";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ public override void AddColumnOperation_with_defaultValue()
base.AddColumnOperation_with_defaultValue();

Assert.Equal(
@"ALTER TABLE `dbo`.`People` ADD `Name` varchar(30) NOT NULL DEFAULT N'John Doe';" + EOL,
@"ALTER TABLE `dbo`.`People` ADD `Name` varchar(30) NOT NULL DEFAULT 'John Doe';" + EOL,
Sql);
}

Expand Down

0 comments on commit cb5740a

Please sign in to comment.