Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add more cast nodes in multi-line breaks during migrations #28064

Merged
1 commit merged into from
May 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ protected override string GenerateNonNullSqlLiteral(object value)
var lastConcatStartPoint = 0;
var concatCount = 1;
var concatStartList = new List<int>();
var castApplied = false;
var insideConcat = false;
for (i = 0; i < stringValue.Length; i++)
{
var lineFeed = stringValue[i] == '\n';
Expand Down Expand Up @@ -282,12 +282,7 @@ protected override string GenerateNonNullSqlLiteral(object value)

for (var j = concatStartList.Count - 1; j >= 0; j--)
{
if (castApplied && j == 0)
{
builder.Insert(concatStartList[j], "CAST(");
}

builder.Insert(concatStartList[j], "CONCAT(");
builder.Insert(concatStartList[j], "CONCAT(CAST(");
builder.Append(')');
}

Expand All @@ -307,7 +302,7 @@ void AddConcatOperatorIfNeeded()
{
if (builder.Length != 0)
{
if (!castApplied)
if (!insideConcat)
{
builder.Append(" AS ");
if (_isUtf16)
Expand All @@ -316,7 +311,7 @@ void AddConcatOperatorIfNeeded()
}

builder.Append("varchar(max))");
castApplied = true;
insideConcat = true;
}

builder.Append(", ");
Expand All @@ -331,6 +326,7 @@ void AddConcatOperatorIfNeeded()
{
lastConcatStartPoint = builder.Length;
concatCount = 1;
insideConcat = false;
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -694,6 +694,35 @@ public virtual void DefaultValue_with_line_breaks(bool isUnicode)
}
});

[ConditionalTheory]
[InlineData(false)]
[InlineData(true)]
public virtual void DefaultValue_with_line_breaks_2(bool isUnicode)
{
var defaultValue = Enumerable.Range(0, 300).Select(e => e.ToString())
.Select(e => e + "\r\n")
.Join("");

Generate(
new CreateTableOperation
{
Name = "TestLineBreaks",
Schema = "dbo",
Columns =
{
new AddColumnOperation
{
Name = "TestDefaultValue",
Table = "TestLineBreaks",
Schema = "dbo",
ClrType = typeof(string),
DefaultValue = defaultValue,
IsUnicode = isUnicode
}
}
});
}

private static void CreateGotModel(ModelBuilder b)
=> b.HasDefaultSchema("dbo").Entity(
"Person", pb =>
Expand Down
Loading