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

Fix non-lazy conditional evaluation #4533

Merged
merged 17 commits into from
Jun 29, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Cosmetic changes.
  • Loading branch information
sdanyliv committed Jun 28, 2024
commit 5306a2f22b303f32f058dd74ecd320aa774e8a68
Original file line number Diff line number Diff line change
Expand Up @@ -143,14 +143,14 @@ protected override ISqlExpression WrapColumnExpression(ISqlExpression expr)
{
var columnExpression = base.WrapColumnExpression(expr);

if (SqlProviderFlags != null && columnExpression.SystemType == typeof(bool) && QueryHelper.UnwrapNullablity(columnExpression) is not (SqlCastExpression or SqlColumn or SqlField))
if (SqlProviderFlags != null
&& columnExpression.SystemType == typeof(bool)
&& QueryHelper.UnwrapNullablity(columnExpression) is not (SqlCastExpression or SqlColumn or SqlField))
{
columnExpression = new SqlCastExpression(columnExpression, new DbDataType(columnExpression.SystemType!, DataType.Boolean), null, isMandatory: true);
}

return columnExpression;
}


}
}
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,12 @@ public bool IsSupportedSubquery(IBuildContext parent, IBuildContext context, out
evaluationContext : new EvaluationContext()
);

if (!SqlProviderHelper.IsValidQuery(optimizedQuery, parentQuery: null, fakeJoin: fakeJoin, forColumn: false, parent.Builder.DataContext.SqlProviderFlags, out errorMessage))
if (!SqlProviderHelper.IsValidQuery(optimizedQuery,
parentQuery: null,
fakeJoin: fakeJoin,
forColumn: false,
parent.Builder.DataContext.SqlProviderFlags,
out errorMessage))
{
return false;
}
Expand Down
27 changes: 18 additions & 9 deletions Source/LinqToDB/SqlQuery/Visitors/SqlQueryValidatorVisitor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -119,22 +119,31 @@ bool IsDependsOnOuterSources()
}
}

if (!_providerFlags.IsSubQueryTakeSupported && selectQuery.Select.TakeValue != null && IsDependsOnOuterSources())
if (!_providerFlags.IsSubQueryTakeSupported && selectQuery.Select.TakeValue != null)
{
errorMessage = ErrorHelper.Error_Take_in_Subquery;
return false;
if (_parentQuery?.From.Tables.Count > 0 || IsDependsOnOuterSources())
{
errorMessage = ErrorHelper.Error_Take_in_Subquery;
return false;
}
}

if (!_providerFlags.IsSubQuerySkipSupported && selectQuery.Select.SkipValue != null && IsDependsOnOuterSources())
if (!_providerFlags.IsSubQuerySkipSupported && selectQuery.Select.SkipValue != null)
{
errorMessage = ErrorHelper.Error_Skip_in_Subquery;
return false;
if (_parentQuery?.From.Tables.Count > 0 || IsDependsOnOuterSources())
{
errorMessage = ErrorHelper.Error_Skip_in_Subquery;
return false;
}
}

if (!_providerFlags.IsSubQueryOrderBySupported && !selectQuery.OrderBy.IsEmpty && IsDependsOnOuterSources())
if (!_providerFlags.IsSubQueryOrderBySupported && !selectQuery.OrderBy.IsEmpty)
{
errorMessage = ErrorHelper.Error_OrderBy_in_Subquery;
return false;
if (_parentQuery?.From.Tables.Count > 0 || IsDependsOnOuterSources())
{
errorMessage = ErrorHelper.Error_OrderBy_in_Subquery;
return false;
}
}

if (!_providerFlags.IsSubqueryWithParentReferenceInJoinConditionSupported)
Expand Down