Beispiel #1
0
        private void Initialize(DT dt, TableArgument sysObject)
        {
            var root = GetRoot();

            chainMethod = Text.Method.Declare;

            CheckAndThrow();
            CheckNullAndThrow(Arg(() => sysObject, sysObject));
            TryThrow(sysObject.Exception);

            var param = new Variable(0, _variableName, dt, sysObject, IdentifierType.SqlVariable);

            root.TryAddVariableOrThrow(param, chainMethod, false);

            Build = (buildContext, buildArgs) =>
            {
                var sql = Text.GenerateSql(30)
                          .NewLine(Text.Declare).S()
                          .Append(_variableName).S()
                          .Append(Text.As).S()
                          .Append(sysObject.Build(buildContext, buildArgs))
                          .Terminate();

                TryThrow(buildContext);

                return(sql.ToString());
            };
        }
Beispiel #2
0
        internal string BaseBuildMethod(BuildContext buildContext, BuildArgs buildArgs)
        {
            string tableSql = TableArgument.Build(buildContext, buildArgs);

            TryThrow(buildContext);

            StringBuilder sql = Text.GenerateSql(30)
                                .NewLine(Keyword);

            // subquery:
            if (TableArgument.Original is View)
            {
                sql.S().Append(Text.LeftBracket)
                .Append(tableSql)
                .NewLine(Text.RightBracket);
            }
            // table:
            else
            {
                sql.S().Append(tableSql);
            }

            // table with alias
            if (_alias != null)
            {
                return(sql
                       .S().Append(Text.As)
                       .S().Append(Filter.Delimit(_alias.Name))
                       .ToString());
            }
            else
            {
                return(sql.ToString());
            }
        }
        internal TruncateTableChainer(Chainer prev, TableArgument table)
            : base(prev)
        {
            CheckNullAndThrow(Arg(() => table, table));

            Build = (buildContext, buildArgs) =>
            {
                return(Text.GenerateSql(50)
                       .NewLine(Text.TruncateTable).S()
                       .Append(table.Build(buildContext, buildArgs))
                       .Terminate()
                       .ToString());
            };
        }
Beispiel #4
0
        private void ProcessTable(
            BuildContext buildContext,
            BuildArgs buildArgs,
            TableArgument table,
            StringBuilder sql)
        {
            sql.AppendLine()
            .Append(Text.Select).S()
            .Append(Text.Asterisk).S()
            .Append(Text.From).S()
            .Append(table.Build(buildContext, buildArgs))
            .Terminate();

            TryThrow(table.Exception);
        }
Beispiel #5
0
        internal SetIdentityInsertChainer(Chainer prev, TableArgument table, bool setOn)
            : base(prev)
        {
            CheckNullAndThrow(Arg(() => table, table));

            Build = (buildContext, buildArgs) =>
            {
                var sql = Text.GenerateSql(70)
                          .NewLine(Text.SetIdentityInsert).S()
                          .Append(table.Build(buildContext, buildArgs)).S()
                          .Append((bool)setOn ? Text.On : Text.Off)
                          .Terminate()
                          .ToString();

                TryThrow(buildContext);

                return(sql);
            };
        }
Beispiel #6
0
        internal string BuildCte(BuildContext buildContext, BuildArgs buildArgs, bool isFirstCte)
        {
            var sql = Text.GenerateSql(500);

            if (isFirstCte)
            {
                sql.NewLine(Text.With).S();
            }
            else
            {
                sql.NewLine(Text.Comma);
            }

            sql.Append(Filter.Delimit(Alias.Name))
            .Append(Text._As_)
            .NewLine(Text.LeftBracket)
            .Append(TableArgument.Build(buildContext, buildArgs))
            .NewLine(Text.RightBracket);

            return(sql.ToString());
        }