Пример #1
0
        internal static void BuildNode(this Chainer node, QueryPart queryPart,
                                       BuildContext buildContext, BuildArgs buildArgs, StringBuilder sql)
        {
            if (node == null)
            {
                return;
            }

            var root = node.GetRoot();

            // snippet check
            if (root.CompilableType == Compilable.ObjectType.Snippet && node is ISnippetDisallowed)
            {
                node.Throw(QueryTalkExceptionType.InvalidSnippet, null, node.Method);
            }

            string append = null;

            if (node.Build != null && !node.SkipBuild)
            {
                // important: assign current object
                buildContext.Current = node;

                // important: store query part into the current object
                buildContext.Current.QueryPart = queryPart;

                // build
                append = node.Build(buildContext, buildArgs);

                TryThrow(node.Exception);
                TryThrow(buildContext.Exception);
            }

            if (append != null)
            {
                if (append == Text.Terminator)
                {
                    sql.TrimEnd();
                }

                sql.Append(append);

                // assure that there is always a spacing between the sql parts/clauses
                sql.S();
            }

            // check view
            if (root.CompilableType == Compilable.ObjectType.View &&
                (root.Statements.Count > 1 ||           // view can have only a single statement
                 !(node is IViewAllowed)))              // only clauses related to select statement can be contained in the view
            {
                root.CheckNodeReuseAndThrow();
                node.Throw(QueryTalkExceptionType.InvalidView, null, node.Method);
            }
        }