Skip to content

Commit

Permalink
Improved reporting of error when using SELECT * in scalar subquery
Browse files Browse the repository at this point in the history
  • Loading branch information
MarkMpn committed Jun 25, 2024
1 parent 4328472 commit b666450
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
17 changes: 17 additions & 0 deletions MarkMpn.Sql4Cds.Engine.Tests/AdoProviderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2088,5 +2088,22 @@ SELECT STRING_AGG(CAST(ID AS NVARCHAR(MAX)), ',')
Assert.AreEqual("1,2,3", result);
}
}

[TestMethod]
public void InSelectStarError()
{
using (var con = new Sql4CdsConnection(_localDataSources))
{
try
{
con.Execute("SELECT * FROM contact WHERE contactid IN (SELECT * FROM account)");
Assert.Fail();
}
catch (Sql4CdsException ex)
{
Assert.AreEqual(116, ex.Number);
}
}
}
}
}
2 changes: 2 additions & 0 deletions MarkMpn.Sql4Cds.Engine/ExecutionPlanBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2927,6 +2927,8 @@ private IDataExecutionPlanNodeInternal ConvertInSubquery(IDataExecutionPlanNodeI
var innerQuery = ConvertSelectStatement(inSubquery.Subquery.QueryExpression, hints, schema, references, innerContext);

// Scalar subquery must return exactly one column and one row
innerQuery.ExpandWildcardColumns(innerContext);

if (innerQuery.ColumnSet.Count != 1)
throw new NotSupportedQueryFragmentException(Sql4CdsError.MultiColumnScalarSubquery(inSubquery.Subquery));

Expand Down

0 comments on commit b666450

Please sign in to comment.