public override IList <SqlRuleProblem> Analyze(SqlRuleExecutionContext ruleExecutionContext)
        {
            var problems = new List <SqlRuleProblem>();
            var sqlObj   = ruleExecutionContext.ModelElement;

            if (sqlObj == null || sqlObj.IsWhiteListed())
            {
                return(problems);
            }

            var fragment = ruleExecutionContext.ScriptFragment.GetFragment(ProgrammingSchemaTypes);

            var openCursorVisitor = new OpenCursorVisitor();

            fragment.Accept(openCursorVisitor);

            if (openCursorVisitor.Count > 0)
            {
                var deallocateCursorVisitor = new DeallocateCursorVisitor();
                fragment.Accept(deallocateCursorVisitor);

                var localOpenCursors       = openCursorVisitor.Statements.Where(c => !c.Cursor.IsGlobal);
                var localDeallocateCursors = deallocateCursorVisitor.Statements.Where(c => !c.Cursor.IsGlobal);

                var unDeallocatedCursors = localOpenCursors.Where(c =>
                                                                  !localDeallocateCursors.Any(c2 => _comparer.Equals(c.Cursor.Name.Value, c2.Cursor.Name.Value)));

                foreach (var cursor in unDeallocatedCursors)
                {
                    problems.Add(new SqlRuleProblem(Message, sqlObj, cursor));
                }
            }

            return(problems);
        }
        /// <summary>
        /// Performs analysis and returns a list of problems detected
        /// </summary>
        /// <param name="ruleExecutionContext">Contains the schema model and model element to analyze</param>
        /// <returns>
        /// The problems detected by the rule in the given element
        /// </returns>
        public override IList <SqlRuleProblem> Analyze(SqlRuleExecutionContext ruleExecutionContext)
        {
            var problems = new List <SqlRuleProblem>();
            var sqlObj   = ruleExecutionContext.ModelElement;

            if (sqlObj == null || sqlObj.IsWhiteListed())
            {
                return(problems);
            }

            var fragment = ruleExecutionContext.ScriptFragment.GetFragment(ProgrammingSchemaTypes);

            var visitor = new OpenCursorVisitor();

            fragment.Accept(visitor);

            var offenders =
                from c in visitor.NotIgnoredStatements(RuleId)
                select c.Cursor;

            problems.AddRange(offenders.Select(c => new SqlRuleProblem(Message, sqlObj, c)));

            return(problems);
        }