Beispiel #1
0
        public static SqlQueryExpression Form(PlSqlParser.SubqueryContext context, out IntoClause into)
        {
            var query = Form(context.subqueryBasicElements(), out into);

            var opPart = context.subquery_operation_part();

            if (opPart.Length > 0) {
                if (into != null)
                    throw new InvalidOperationException("Cannot SELECT INTO in a composite query.");

                foreach (var part in opPart) {
                    CompositeFunction function;
                    if (part.MINUS() != null || part.EXCEPT() != null) {
                        function = CompositeFunction.Except;
                    } else if (part.UNION() != null) {
                        function = CompositeFunction.Union;
                    } else if (part.INTERSECT() != null) {
                        function = CompositeFunction.Intersect;
                    } else {
                        throw new ParseCanceledException("Invalid composite function.");
                    }

                    bool isAll = part.ALL() != null;

                    var next = Form(part.subqueryBasicElements());
                    var prev = query.NextComposite;

                    if (prev == null) {
                        prev = next;
                    } else {
                        prev.NextComposite = next;
                    }

                    query.IsCompositeAll = isAll;
                    query.CompositeFunction = function;
                    query.NextComposite = prev;
                }
            }

            return query;
        }