Skip to content

Commit

Permalink
Generate better error when trying to insert values true or false
Browse files Browse the repository at this point in the history
  • Loading branch information
MarkMpn committed Jun 9, 2021
1 parent e5602c7 commit 456131a
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions MarkMpn.Sql4Cds.Engine/ExecutionPlan/ExpressionExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,9 @@ private static Expression ToExpression(ColumnReferenceExpression col, NodeSchema
{
var name = col.GetColumnName();

if (!schema.ContainsColumn(name, out var normalizedName))
if (schema == null || !schema.ContainsColumn(name, out var normalizedName))
{
if (!schema.Aliases.TryGetValue(name, out var normalized))
if (schema == null || !schema.Aliases.TryGetValue(name, out var normalized))
{
if (nonAggregateSchema != null && nonAggregateSchema.ContainsColumn(name, out _))
throw new NotSupportedQueryFragmentException("Column is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause", col);
Expand All @@ -144,6 +144,10 @@ private static Expression ToExpression(ColumnReferenceExpression col, NodeSchema

if (col.MultiPartIdentifier.Identifiers.Count == 1 && col.MultiPartIdentifier.Identifiers[0].QuoteType == QuoteType.DoubleQuote)
ex.Suggestion = $"Did you mean '{name}'?";
else if (name.Equals("false", StringComparison.OrdinalIgnoreCase))
ex.Suggestion = "Did you mean '0'?";
else if (name.Equals("true", StringComparison.OrdinalIgnoreCase))
ex.Suggestion = "Did you mean '1'?";

throw ex;
}
Expand Down

0 comments on commit 456131a

Please sign in to comment.