public override IList <SqlRuleProblem> Analyze(XtendSqlRuleExecutionContext context)
        {
            IList <SqlRuleProblem> problems = new List <SqlRuleProblem>();

            // Use a visitor to see if the procedure has a nocount set
            SetConcatNullYieldsNullVisitor visitor = new SetConcatNullYieldsNullVisitor();

            context.ScriptFragment.Accept(visitor);
            if (visitor.SetConcatNullYieldsNullEnabled)
            {
                foreach (PredicateSetStatement element in visitor.SetCalls)
                {
                    SqlRuleProblem problem = new SqlRuleProblem(
                        String.Format(
                            CultureInfo.CurrentCulture,
                            context.RuleDescriptor.DisplayDescription,
                            context.ElementName),
                        context.ModelElement,
                        element);
                    problems.Add(problem);
                }
            }

            return(problems);
        }
        /// <summary>
        /// For element-scoped rules the Analyze method is executed once for every matching object in the model.
        /// </summary>
        /// <param name="ruleExecutionContext">The context object contains the TSqlObject being analyzed, a TSqlFragment
        /// that's the AST representation of the object, the current rule's descriptor, and a reference to the model being
        /// analyzed.
        /// </param>
        /// <returns>A list of problems should be returned. These will be displayed in the Visual Studio error list</returns>
        public override IList <SqlRuleProblem> Analyze(XtendSqlRuleExecutionContext context)
        {
            IList <SqlRuleProblem> problems = new List <SqlRuleProblem>();

            CursorVisitor visitor = new CursorVisitor(false, true);

            context.ScriptFragment.Accept(visitor);
            foreach (var element in visitor.IncorrectFetchCursorStatements)
            {
                var            fetch      = element.Key;
                int            fetchCount = fetch.IntoVariables.Count;
                string         cursorName = element.Value;
                SqlRuleProblem problem    = new SqlRuleProblem(
                    String.Format(
                        CultureInfo.CurrentCulture,
                        context.RuleDescriptor.DisplayDescription,
                        cursorName,
                        fetchCount),
                    context.ModelElement,
                    fetch);
                problems.Add(problem);
            }

            return(problems);
        }
Exemple #3
0
        /// <summary>
        /// For element-scoped rules the Analyze method is executed once for every matching object in the model.
        /// </summary>
        /// <param name="ruleExecutionContext">The context object contains the TSqlObject being analyzed, a TSqlFragment
        /// that's the AST representation of the object, the current rule's descriptor, and a reference to the model being
        /// analyzed.
        /// </param>
        /// <returns>A list of problems should be returned. These will be displayed in the Visual Studio error list</returns>
        public override IList <SqlRuleProblem> Analyze(XtendSqlRuleExecutionContext context)
        {
            IList <SqlRuleProblem> problems = new List <SqlRuleProblem>();

            NullBooleanComparisonVisitor visitor = new NullBooleanComparisonVisitor();

            context.ScriptFragment.Accept(visitor);
            foreach (var element in visitor.InvalidBooleanComparisons)
            {
                string description = element.ComparisonType == BooleanComparisonType.NotEqualToBrackets || element.ComparisonType == BooleanComparisonType.NotEqualToExclamation
                        ? "use 'is not null' instead" : element.ComparisonType == BooleanComparisonType.Equals ? "use 'is null' instead" : element.ComparisonType.ToString();

                string statement = string.Join("", element.ScriptTokenStream
                                               .Skip(element.FirstTokenIndex)
                                               .Take(element.LastTokenIndex - element.FirstTokenIndex + 1)
                                               .Select(x => x.Text).ToArray());

                SqlRuleProblem problem = new SqlRuleProblem(
                    String.Format(
                        CultureInfo.CurrentCulture,
                        context.RuleDescriptor.DisplayDescription,
                        statement, description),
                    context.ModelElement,
                    element.SecondExpression);
                problems.Add(problem);
            }
            return(problems);
        }
Exemple #4
0
        /// <summary>
        /// For element-scoped rules the Analyze method is executed once for every matching object in the model.
        /// </summary>
        /// <param name="ruleExecutionContext">The context object contains the TSqlObject being analyzed, a TSqlFragment
        /// that's the AST representation of the object, the current rule's descriptor, and a reference to the model being
        /// analyzed.
        /// </param>
        /// <returns>A list of problems should be returned. These will be displayed in the Visual Studio error list</returns>
        public sealed override IList <SqlRuleProblem> Analyze(SqlRuleExecutionContext ruleExecutionContext)
        {
            var context = new XtendSqlRuleExecutionContext(ruleExecutionContext);

            if (context.Schema != null && context.ScriptFragment.FragmentLength > 0 && // valid procedure
                !IgnoreScriptFragment(context.ScriptFragment))
            {
                return(Analyze(context));
            }
            return(new List <SqlRuleProblem>());
        }
Exemple #5
0
        /// <summary>
        /// For element-scoped rules the Analyze method is executed once for every matching object in the model.
        /// </summary>
        /// <param name="ruleExecutionContext">The context object contains the TSqlObject being analyzed, a TSqlFragment
        /// that's the AST representation of the object, the current rule's descriptor, and a reference to the model being
        /// analyzed.
        /// </param>
        /// <returns>A list of problems should be returned. These will be displayed in the Visual Studio error list</returns>
        public override IList <SqlRuleProblem> Analyze(XtendSqlRuleExecutionContext context)
        {
            IList <SqlRuleProblem> problems = new List <SqlRuleProblem>();

            // Use a visitor to see if the procedure has a nocount set
            SetXActAbortVisitor visitor = new SetXActAbortVisitor();

            context.ScriptFragment.Accept(visitor);
            if (!visitor.SetXActAbortFound)
            {
                SqlRuleProblem problem = new SqlRuleProblem(
                    String.Format(
                        CultureInfo.CurrentCulture,
                        context.RuleDescriptor.DisplayDescription,
                        context.ElementName),
                    context.ModelElement);
                problems.Add(problem);
            }

            return(problems);
        }
Exemple #6
0
        /// <summary>
        /// For element-scoped rules the Analyze method is executed once for every matching object in the model.
        /// </summary>
        /// <param name="ruleExecutionContext">The context object contains the TSqlObject being analyzed, a TSqlFragment
        /// that's the AST representation of the object, the current rule's descriptor, and a reference to the model being
        /// analyzed.
        /// </param>
        /// <returns>A list of problems should be returned. These will be displayed in the Visual Studio error list</returns>
        public override IList <SqlRuleProblem> Analyze(XtendSqlRuleExecutionContext context)
        {
            IList <SqlRuleProblem> problems = new List <SqlRuleProblem>();

            // Use a visitor to see if the procedure has unused variables
            UnusedVariableVisitor visitor = new UnusedVariableVisitor(true);

            context.ScriptFragment.Accept(visitor);
            foreach (DeclareVariableElement element in visitor.DeclareVariableElements.Values)
            {
                SqlRuleProblem problem = new SqlRuleProblem(
                    String.Format(
                        CultureInfo.CurrentCulture,
                        context.RuleDescriptor.DisplayDescription,
                        element.VariableName.Value,
                        context.ElementName),
                    context.ModelElement,
                    element);
                problems.Add(problem);
            }

            return(problems);
        }
        /// <summary>
        /// For element-scoped rules the Analyze method is executed once for every matching object in the model.
        /// </summary>
        /// <param name="ruleExecutionContext">The context object contains the TSqlObject being analyzed, a TSqlFragment
        /// that's the AST representation of the object, the current rule's descriptor, and a reference to the model being
        /// analyzed.
        /// </param>
        /// <returns>A list of problems should be returned. These will be displayed in the Visual Studio error list</returns>
        public override IList <SqlRuleProblem> Analyze(XtendSqlRuleExecutionContext context)
        {
            IList <SqlRuleProblem> problems = new List <SqlRuleProblem>();

            // Use a visitor to see if the procedure has unused variables
            MandatoryParameterVisitor visitor = new MandatoryParameterVisitor(context.SchemaModel);

            context.ScriptFragment.Accept(visitor);
            foreach (ExecutableProcedureReference element in visitor.ProcedureCalls)
            {
                SqlRuleProblem problem = new SqlRuleProblem(
                    String.Format(
                        CultureInfo.CurrentCulture,
                        context.RuleDescriptor.DisplayDescription,
                        element.ProcedureReference.ProcedureReference.Name.SchemaIdentifier.Value,
                        element.ProcedureReference.ProcedureReference.Name.BaseIdentifier.Value,
                        visitor.MissingParameters[element]),
                    context.ModelElement,
                    element);
                problems.Add(problem);
            }

            return(problems);
        }
Exemple #8
0
 /// <summary>
 /// For element-scoped rules the Analyze method is executed once for every matching object in the model.
 /// </summary>
 /// <param name="context">The context object contains the TSqlObject being analyzed, a TSqlFragment
 /// that's the AST representation of the object, the current rule's descriptor, and a reference to the model being
 /// analyzed.
 /// </param>
 /// <returns>A list of problems should be returned. These will be displayed in the Visual Studio error list</returns>
 public abstract IList <SqlRuleProblem> Analyze(XtendSqlRuleExecutionContext context);