Exemplo n.º 1
0
        public override QueryNode VisitCommonTableExpressionQuery(CommonTableExpressionQuery query)
        {
            base.VisitCommonTableExpressionQuery(query);

            foreach (CommonTableExpression commonTableExpression in query.CommonTableExpressions)
            {
                EnsureQueryHasNoOrderByUnlessTopSpecified(commonTableExpression.QueryDeclaration);

                if (commonTableExpression.CommonTableBinding.IsRecursive)
                {
                    foreach (QueryNode recursiveMember in commonTableExpression.CommonTableBinding.RecursiveMembers)
                    {
                        CommonTableExpressionRecursiveMemberChecker checker = new CommonTableExpressionRecursiveMemberChecker(commonTableExpression.TableName);
                        checker.Visit(recursiveMember);

                        if (checker.RecursiveReferenceInSubquery)
                        {
                            _errorReporter.CteContainsRecursiveReferenceInSubquery(commonTableExpression.TableName);
                        }
                        else if (checker.RecursiveReferences == 0)
                        {
                            _errorReporter.CteContainsUnexpectedAnchorMember(commonTableExpression.TableName);
                        }
                        else if (checker.RecursiveReferences > 1)
                        {
                            _errorReporter.CteContainsMultipleRecursiveReferences(commonTableExpression.TableName);
                        }

                        if (checker.ContainsUnion)
                        {
                            _errorReporter.CteContainsUnion(commonTableExpression.TableName);
                        }

                        if (checker.ContainsDisctinct)
                        {
                            _errorReporter.CteContainsDistinct(commonTableExpression.TableName);
                        }

                        if (checker.ContainsTop)
                        {
                            _errorReporter.CteContainsTop(commonTableExpression.TableName);
                        }

                        if (checker.ContainsOuterJoin)
                        {
                            _errorReporter.CteContainsOuterJoin(commonTableExpression.TableName);
                        }

                        if (checker.ContainsGroupByHavingOrAggregate)
                        {
                            _errorReporter.CteContainsGroupByHavingOrAggregate(commonTableExpression.TableName);
                        }
                    }
                }
            }

            return(query);
        }
Exemplo n.º 2
0
        private static bool IsRecursive(QueryNode query, Identifier tableName)
        {
            CommonTableExpressionRecursiveMemberChecker checker = new CommonTableExpressionRecursiveMemberChecker(tableName);
            checker.Visit(query);

            return checker.RecursiveReferences > 0 ||
                   checker.RecursiveReferenceInSubquery;
        }
Exemplo n.º 3
0
        public override QueryNode VisitCommonTableExpressionQuery(CommonTableExpressionQuery query)
        {
            base.VisitCommonTableExpressionQuery(query);

            foreach (CommonTableExpression commonTableExpression in query.CommonTableExpressions)
            {
                EnsureQueryHasNoOrderByUnlessTopSpecified(commonTableExpression.QueryDeclaration);

                if (commonTableExpression.CommonTableBinding.IsRecursive)
                {
                    foreach (QueryNode recursiveMember in commonTableExpression.CommonTableBinding.RecursiveMembers)
                    {
                        CommonTableExpressionRecursiveMemberChecker checker = new CommonTableExpressionRecursiveMemberChecker(commonTableExpression.TableName);
                        checker.Visit(recursiveMember);

                        if (checker.RecursiveReferenceInSubquery)
                            _errorReporter.CteContainsRecursiveReferenceInSubquery(commonTableExpression.TableName);
                        else if (checker.RecursiveReferences == 0)
                            _errorReporter.CteContainsUnexpectedAnchorMember(commonTableExpression.TableName);
                        else if (checker.RecursiveReferences > 1)
                            _errorReporter.CteContainsMultipleRecursiveReferences(commonTableExpression.TableName);

                        if (checker.ContainsUnion)
                            _errorReporter.CteContainsUnion(commonTableExpression.TableName);

                        if (checker.ContainsDisctinct)
                            _errorReporter.CteContainsDistinct(commonTableExpression.TableName);

                        if (checker.ContainsTop)
                            _errorReporter.CteContainsTop(commonTableExpression.TableName);

                        if (checker.ContainsOuterJoin)
                            _errorReporter.CteContainsOuterJoin(commonTableExpression.TableName);

                        if (checker.ContainsGroupByHavingOrAggregate)
                            _errorReporter.CteContainsGroupByHavingOrAggregate(commonTableExpression.TableName);
                    }
                }
            }

            return query;
        }