-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix to #19178 - Invalid SQL with CROSS APPLY generated on SQLite
Adding logic that checks for APPLY and throws meaningful exception Fixes #19178
- Loading branch information
Showing
18 changed files
with
343 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
81 changes: 81 additions & 0 deletions
81
src/EFCore.Sqlite.Core/Query/Internal/SqliteQueryTranslationPostprocessor.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||
|
||
using System; | ||
using System.Linq; | ||
using System.Linq.Expressions; | ||
using Microsoft.EntityFrameworkCore.Query; | ||
using Microsoft.EntityFrameworkCore.Query.SqlExpressions; | ||
using Microsoft.EntityFrameworkCore.Sqlite.Internal; | ||
|
||
namespace Microsoft.EntityFrameworkCore.Sqlite.Query.Internal | ||
{ | ||
/// <summary> | ||
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to | ||
/// the same compatibility standards as public APIs. It may be changed or removed without notice in | ||
/// any release. You should only use it directly in your code with extreme caution and knowing that | ||
/// doing so can result in application failures when updating to a new Entity Framework Core release. | ||
/// </summary> | ||
public class SqliteQueryTranslationPostprocessor : RelationalQueryTranslationPostprocessor | ||
{ | ||
/// <summary> | ||
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to | ||
/// the same compatibility standards as public APIs. It may be changed or removed without notice in | ||
/// any release. You should only use it directly in your code with extreme caution and knowing that | ||
/// doing so can result in application failures when updating to a new Entity Framework Core release. | ||
/// </summary> | ||
public SqliteQueryTranslationPostprocessor( | ||
QueryTranslationPostprocessorDependencies dependencies, | ||
RelationalQueryTranslationPostprocessorDependencies relationalDependencies, | ||
QueryCompilationContext queryCompilationContext) | ||
: base(dependencies, relationalDependencies, queryCompilationContext) | ||
{ | ||
} | ||
|
||
/// <summary> | ||
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to | ||
/// the same compatibility standards as public APIs. It may be changed or removed without notice in | ||
/// any release. You should only use it directly in your code with extreme caution and knowing that | ||
/// doing so can result in application failures when updating to a new Entity Framework Core release. | ||
/// </summary> | ||
public override Expression Process(Expression query) | ||
{ | ||
var result = base.Process(query); | ||
|
||
if (result is ShapedQueryExpression shapedQueryExpression) | ||
{ | ||
var applyValidator = new ApplyValidatingVisitor(); | ||
applyValidator.Visit(shapedQueryExpression.QueryExpression); | ||
if (!applyValidator.ApplyFound) | ||
{ | ||
applyValidator.Visit(shapedQueryExpression.ShaperExpression); | ||
} | ||
|
||
if (applyValidator.ApplyFound) | ||
{ | ||
throw new InvalidOperationException(SqliteStrings.ApplyNotSupported); | ||
} | ||
} | ||
|
||
return result; | ||
} | ||
|
||
private class ApplyValidatingVisitor : ExpressionVisitor | ||
{ | ||
public bool ApplyFound { get; private set; } = false; | ||
|
||
protected override Expression VisitExtension(Expression extensionExpression) | ||
{ | ||
if (extensionExpression is SelectExpression selectExpression | ||
&& selectExpression.Tables.Any(t => t is CrossApplyExpression || t is OuterApplyExpression)) | ||
{ | ||
ApplyFound = true; | ||
|
||
return extensionExpression; | ||
} | ||
|
||
return base.VisitExtension(extensionExpression); | ||
} | ||
} | ||
} | ||
} |
52 changes: 52 additions & 0 deletions
52
src/EFCore.Sqlite.Core/Query/Internal/SqliteQueryTranslationPostprocessorFactory.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||
|
||
using JetBrains.Annotations; | ||
using Microsoft.EntityFrameworkCore.Query; | ||
using Microsoft.EntityFrameworkCore.Utilities; | ||
|
||
namespace Microsoft.EntityFrameworkCore.Sqlite.Query.Internal | ||
{ | ||
/// <summary> | ||
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to | ||
/// the same compatibility standards as public APIs. It may be changed or removed without notice in | ||
/// any release. You should only use it directly in your code with extreme caution and knowing that | ||
/// doing so can result in application failures when updating to a new Entity Framework Core release. | ||
/// </summary> | ||
public class SqliteQueryTranslationPostprocessorFactory : IQueryTranslationPostprocessorFactory | ||
{ | ||
private readonly QueryTranslationPostprocessorDependencies _dependencies; | ||
private readonly RelationalQueryTranslationPostprocessorDependencies _relationalDependencies; | ||
|
||
/// <summary> | ||
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to | ||
/// the same compatibility standards as public APIs. It may be changed or removed without notice in | ||
/// any release. You should only use it directly in your code with extreme caution and knowing that | ||
/// doing so can result in application failures when updating to a new Entity Framework Core release. | ||
/// </summary> | ||
public SqliteQueryTranslationPostprocessorFactory( | ||
[NotNull] QueryTranslationPostprocessorDependencies dependencies, | ||
[NotNull] RelationalQueryTranslationPostprocessorDependencies relationalDependencies) | ||
{ | ||
_dependencies = dependencies; | ||
_relationalDependencies = relationalDependencies; | ||
} | ||
|
||
/// <summary> | ||
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to | ||
/// the same compatibility standards as public APIs. It may be changed or removed without notice in | ||
/// any release. You should only use it directly in your code with extreme caution and knowing that | ||
/// doing so can result in application failures when updating to a new Entity Framework Core release. | ||
/// </summary> | ||
public virtual QueryTranslationPostprocessor Create([NotNull] QueryCompilationContext queryCompilationContext) | ||
{ | ||
Check.NotNull(queryCompilationContext, nameof(queryCompilationContext)); | ||
|
||
return new SqliteQueryTranslationPostprocessor( | ||
_dependencies, | ||
_relationalDependencies, | ||
queryCompilationContext); | ||
} | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.