Skip to content

Commit

Permalink
Ignore case when comparing store types for set operation validation
Browse files Browse the repository at this point in the history
Partial fix for #29020
  • Loading branch information
ajcvickers committed Sep 14, 2022
1 parent 4a2d7a3 commit 8b5fb28
Show file tree
Hide file tree
Showing 7 changed files with 96 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2253,7 +2253,10 @@ private void ApplySetOperation(SetOperationType setOperationType, SelectExpressi
var innerColumn2 = (SqlExpression)expression2;
// For now, make sure that both sides output the same store type, otherwise the query may fail.
// TODO: with #15586 we'll be able to also allow different store types which are implicitly convertible to one another.
if (innerColumn1.TypeMapping!.StoreType != innerColumn2.TypeMapping!.StoreType)
if (!string.Equals(
innerColumn1.TypeMapping!.StoreType,
innerColumn2.TypeMapping!.StoreType,
StringComparison.OrdinalIgnoreCase))
{
throw new InvalidOperationException(RelationalStrings.SetOperationsOnDifferentStoreTypes);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ public virtual Task Select_Union_unrelated(bool async)
=> AssertQuery(
async,
ss => ss.Set<Customer>()
.Select(c => c.ContactName)
.Select(c => c.CompanyName)
.Union(ss.Set<Product>().Select(p => p.ProductName))
.Where(x => x.StartsWith("C"))
.OrderBy(x => x),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ public override async Task<string> FromSqlRaw_queryable_with_parameters_and_clos

AssertSql(
@"p0='London' (Size = 4000)
@__contactTitle_1='Sales Representative' (Size = 4000)
@__contactTitle_1='Sales Representative' (Size = 30)
SELECT [m].[CustomerID], [m].[Address], [m].[City], [m].[CompanyName], [m].[ContactName], [m].[ContactTitle], [m].[Country], [m].[Fax], [m].[Phone], [m].[PostalCode], [m].[Region]
FROM (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ public override async Task String_Contains_parameter_with_whitespace(bool async)
await base.String_Contains_parameter_with_whitespace(async);

AssertSql(
@"@__pattern_0=' ' (Size = 4000)
@"@__pattern_0=' ' (Size = 30)
SELECT [c].[CustomerID], [c].[Address], [c].[City], [c].[CompanyName], [c].[ContactName], [c].[ContactTitle], [c].[Country], [c].[Fax], [c].[Phone], [c].[PostalCode], [c].[Region]
FROM [Customers] AS [c]
Expand Down Expand Up @@ -1691,21 +1691,21 @@ public override async Task Indexof_with_one_constant_arg(bool async)
AssertSql(
@"SELECT [c].[CustomerID], [c].[Address], [c].[City], [c].[CompanyName], [c].[ContactName], [c].[ContactTitle], [c].[Country], [c].[Fax], [c].[Phone], [c].[PostalCode], [c].[Region]
FROM [Customers] AS [c]
WHERE (CAST(CHARINDEX(N'a', [c].[ContactName]) AS int) - 1) = 1");
WHERE (CHARINDEX(N'a', [c].[ContactName]) - 1) = 1");
}

public override async Task Indexof_with_one_parameter_arg(bool async)
{
await base.Indexof_with_one_parameter_arg(async);

AssertSql(
@"@__pattern_0='a' (Size = 4000)
@"@__pattern_0='a' (Size = 30)
SELECT [c].[CustomerID], [c].[Address], [c].[City], [c].[CompanyName], [c].[ContactName], [c].[ContactTitle], [c].[Country], [c].[Fax], [c].[Phone], [c].[PostalCode], [c].[Region]
FROM [Customers] AS [c]
WHERE CASE
WHEN @__pattern_0 = N'' THEN 0
ELSE CAST(CHARINDEX(@__pattern_0, [c].[ContactName]) AS int) - 1
ELSE CHARINDEX(@__pattern_0, [c].[ContactName]) - 1
END = 1");
}

Expand All @@ -1716,7 +1716,7 @@ public override async Task Indexof_with_constant_starting_position(bool async)
AssertSql(
@"SELECT [c].[CustomerID], [c].[Address], [c].[City], [c].[CompanyName], [c].[ContactName], [c].[ContactTitle], [c].[Country], [c].[Fax], [c].[Phone], [c].[PostalCode], [c].[Region]
FROM [Customers] AS [c]
WHERE (CAST(CHARINDEX(N'a', [c].[ContactName], 3) AS int) - 1) = 4");
WHERE (CHARINDEX(N'a', [c].[ContactName], 3) - 1) = 4");
}

public override async Task Indexof_with_parameter_starting_position(bool async)
Expand All @@ -1728,7 +1728,7 @@ public override async Task Indexof_with_parameter_starting_position(bool async)
SELECT [c].[CustomerID], [c].[Address], [c].[City], [c].[CompanyName], [c].[ContactName], [c].[ContactTitle], [c].[Country], [c].[Fax], [c].[Phone], [c].[PostalCode], [c].[Region]
FROM [Customers] AS [c]
WHERE (CAST(CHARINDEX(N'a', [c].[ContactName], @__start_0 + 1) AS int) - 1) = 4");
WHERE (CHARINDEX(N'a', [c].[ContactName], @__start_0 + 1) - 1) = 4");
}

public override async Task Replace_with_emptystring(bool async)
Expand Down Expand Up @@ -1830,7 +1830,7 @@ public override async Task Substring_with_two_args_with_Index_of(bool async)
await base.Substring_with_two_args_with_Index_of(async);

AssertSql(
@"SELECT SUBSTRING([c].[ContactName], (CAST(CHARINDEX(N'a', [c].[ContactName]) AS int) - 1) + 1, 3)
@"SELECT SUBSTRING([c].[ContactName], (CHARINDEX(N'a', [c].[ContactName]) - 1) + 1, 3)
FROM [Customers] AS [c]
WHERE [c].[CustomerID] = N'ALFKI'");
}
Expand Down
Loading

0 comments on commit 8b5fb28

Please sign in to comment.