Exemplo n.º 1
0
        internal ElseIfChainer(Chainer prev, INonSelectView nonSelectView, bool sign)
            : base(prev)
        {
            chainMethod = Text.Method.ElseIfExists;
            CheckNullAndThrow(Arg(() => nonSelectView, nonSelectView));

            SelectChainer select = new SelectChainer((Chainer)nonSelectView, new Column[] { Designer.Null }, false);
            var           view   = new View(select, select.Query);

            Build = BuildViewMethod(view, sign);
        }
Exemplo n.º 2
0
        // main chain build method
        internal string BuildChain(BuildContext buildContext, BuildArgs buildArgs)
        {
            var sql = Wall.Text.GenerateSql(250);

            foreach (var statement in GetRoot().Statements)
            {
                if (statement.SkipBuild)
                {
                    continue;
                }

                var firstObject = statement.First;

                // add .Select after .OrderBy (if missing)
                var orderBy = firstObject.GetNext <OrderByChainer>();
                if (orderBy != null && !(orderBy.Next is SelectChainer))
                {
                    var next    = orderBy.Next;
                    var cselect = new SelectChainer(orderBy, new Column[] { }, false);
                    cselect.SetNext(next);
                }

                if (statement.Build != null)
                {
                    buildContext.Current = firstObject;
                    var append = statement.Build(buildContext, buildArgs);
                    sql.Append(append).S();
                }
                else
                {
                    BuildSimpleStatement(buildContext, buildArgs, sql, firstObject);
                }
            }

            Terminate(sql);

            if (sql.Length == 1 && sql[0] == Text.TerminatorChar)
            {
                return(String.Empty);
            }

            return(sql.ToString());
        }