MarkMpn / Sql4Cds

SQL 4 CDS core engine and XrmToolbox tool
MIT License
74 stars 22 forks source link

NullReferenceException on Exists #462

Closed SiPurdy closed 4 months ago

SiPurdy commented 4 months ago

Experiencing the following Exception with version 9.0

    Exception: MarkMpn.Sql4Cds.Engine.Sql4CdsException (0x80004005): Object reference not set to an instance of an object. ---> System.NullReferenceException: Object reference not set to an instance of an object.
       at MarkMpn.Sql4Cds.Engine.ExecutionPlanBuilder.ConvertTableReference(TableReference reference, IList`1 hints, TSqlFragment query, INodeSchema outerSchema, Dictionary`2 outerReferences, NodeCompilationContext context)
       at MarkMpn.Sql4Cds.Engine.ExecutionPlanBuilder.ConvertFromClause(FromClause fromClause, IList`1 hints, TSqlFragment query, INodeSchema outerSchema, Dictionary`2 outerReferences, NodeCompilationContext context)
       at MarkMpn.Sql4Cds.Engine.ExecutionPlanBuilder.ConvertSelectQuerySpec(QuerySpecification querySpec, IList`1 hints, INodeSchema outerSchema, Dictionary`2 outerReferences, NodeCompilationContext context)
       at MarkMpn.Sql4Cds.Engine.ExecutionPlanBuilder.ConvertExistsSubqueries(IDataExecutionPlanNodeInternal source, IList`1 hints, TSqlFragment query, NodeCompilationContext context, INodeSchema outerSchema, IDictionary`2 outerReferences)
       at MarkMpn.Sql4Cds.Engine.ExecutionPlanBuilder.ConvertSelectQuerySpec(QuerySpecification querySpec, IList`1 hints, INodeSchema outerSchema, Dictionary`2 outerReferences, NodeCompilationContext context)
       at MarkMpn.Sql4Cds.Engine.ExecutionPlanBuilder.ConvertPredicateQuery(BooleanExpression predicate, IDataExecutionPlanNodeInternal& predicateSource, String& sourceCol)
       at MarkMpn.Sql4Cds.Engine.ExecutionPlan.UnparsedGoToNode.Compile()
       at MarkMpn.Sql4Cds.Engine.Sql4CdsDataReader.Execute(Dictionary`2 parameterTypes, Dictionary`2 parameterValues)
       at MarkMpn.Sql4Cds.Engine.Sql4CdsDataReader.Execute(Dictionary`2 parameterTypes, Dictionary`2 parameterValues)
       at MarkMpn.Sql4Cds.Engine.Sql4CdsDataReader.ExecuteWithExceptionHandling(Dictionary`2 parameterTypes, Dictionary`2 parameterValues)
       at MarkMpn.Sql4Cds.Engine.Sql4CdsDataReader..ctor(Sql4CdsCommand command, IQueryExecutionOptions options, CommandBehavior behavior)
       at MarkMpn.Sql4Cds.Engine.Sql4CdsCommand.ExecuteDbDataReader(CommandBehavior behavior)
...

The foundation of the query is in the order of:

if exists(select solutionid from solution where uniquename='solution') begin
    print 'Solution Installed'
end
else begin
    print 'Solution Not Installed'
end

So the error was from c# code calling MarkMpn.Sql4Cds.Engine directly. I did originally get the error within XrmToolbox but I think my plugin setup has become corrupted downgrading to 8.0 to check for regression issues.