/// <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(ProgrammingAndViewSchemaTypes);
            var topVisitor = new TopRowFilterVisitor();

            fragment.Accept(topVisitor);

            if (topVisitor.Count > 0)
            {
                var orderByvisitor = new OrderByVisitor();
                fragment.Accept(orderByvisitor);
                if (orderByvisitor.Count < 1)
                {
                    problems.Add(new SqlRuleProblem(Message, sqlObj, topVisitor.Statements[0]));
                }
            }

            return(problems);
        }
Exemplo n.º 2
0
        public void SmokeTestWithVisitor()
        {
            var        visitor = new TopRowFilterVisitor();
            TSqlScript script  = Parse("TsqlSample1.sql");

            script.Accept(visitor);
            Assert.IsTrue(visitor.HasParenthesis);

            visitor = new TopRowFilterVisitor();
            script  = Parse("TsqlSample2.sql");
            script.Accept(visitor);
            Assert.IsFalse(visitor.HasParenthesis);
        }