Skip to content

Commit

Permalink
Provide hook for SQL composability checks
Browse files Browse the repository at this point in the history
Fixes #19224
  • Loading branch information
roji committed Jun 3, 2020
1 parent 14f13ef commit 11d0281
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions src/EFCore.Relational/Query/QuerySqlGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -413,10 +413,7 @@ protected override Expression VisitFromSql(FromSqlExpression fromSqlExpression)

_relationalCommandBuilder.AppendLine("(");

if (!_composableSql.IsMatch(fromSqlExpression.Sql))
{
throw new InvalidOperationException(RelationalStrings.FromSqlNonComposable);
}
CheckComposableSql(fromSqlExpression.Sql);

using (_relationalCommandBuilder.Indent())
{
Expand All @@ -430,6 +427,22 @@ protected override Expression VisitFromSql(FromSqlExpression fromSqlExpression)
return fromSqlExpression;
}

/// <summary>
/// Checks whether a given SQL string is composable, i.e. can be embedded as a subquery within a
/// larger SQL query.
/// </summary>
/// <param name="sql"> An SQL string to be checked for composability. </param>
/// <exception cref="InvalidOperationException"> The given SQL isn't composable. </exception>
protected virtual void CheckComposableSql([NotNull] string sql)
{
Check.NotNull(sql, nameof(sql));

if (!_composableSql.IsMatch(sql))
{
throw new InvalidOperationException(RelationalStrings.FromSqlNonComposable);
}
}

/// <inheritdoc />
protected override Expression VisitSqlBinary(SqlBinaryExpression sqlBinaryExpression)
{
Expand Down

0 comments on commit 11d0281

Please sign in to comment.