コード例 #1
0
 private void FormatInputData()
 {
     if (_statement.Values.Any())
     {
         NewLine();
         using (new IndentScope(this))
         {
             foreach (var values in _statement.Values)
             {
                 IndentAppendFormat(
                     "{0} {1}{2}",
                     values == _statement.Values.First() ? " " + Constants.Values : new string( ' ', Constants.Values.Length + 1 ),
                     FormatBrackets(String.Join(", ", values.ToArray())),
                     values == _statement.Values.Last() ? "" : ",\n"
                     );
             }
         }
     }
     else if (_statement.SourceStatement != null)
     {
         using (new IndentScope(this))
         {
             var formatter = new SelectStatementFormatter(this, _sql, _statement.SourceStatement);
             formatter.Execute();
         }
     }
     //else if ( _statement.ExecuteProcudure != null )
     //{
     //    using ( new IndentScope( this ) )
     //    {
     //        var formatter = new ExecuteProcedureFormatter( this, _sql, _statement.ExecuteProcudure );
     //        formatter.Execute();
     //    }
     //}
 }
コード例 #2
0
        public void Execute()
        {
            _sql.Append("WITH ");

            foreach (var commonTableExpression in _statement.CommonTableExpressions)
            {
                if (commonTableExpression.ColumnNames.Any())
                {
                    var fields = commonTableExpression.ColumnNames.ToCsv();
                    _sql.AppendFormat("{0} ({1}) AS ({2}{2}", commonTableExpression.Name, fields, Environment.NewLine);
                }
                else
                {
                    _sql.AppendFormat("{0} AS ({1}{1}", commonTableExpression.Name, Environment.NewLine);
                }

                using (new IndentScope(this))
                {
                    var cteFormatter = new SelectStatementFormatter(this, _sql, commonTableExpression);
                    cteFormatter.Execute();

                    _sql.AppendFormat(
                        "{1}){0}{1}",
                        (commonTableExpression != _statement.CommonTableExpressions.Last() ? "," : String.Empty),
                        Environment.NewLine
                        );
                }
            }

            var formatter = new SelectStatementFormatter(this, _sql, _statement.Statement);

            formatter.Execute();
        }
コード例 #3
0
        public override string Execute()
        {
            var sql       = new StringBuilder();
            var formatter = new SelectStatementFormatter(this, sql, _expression.Statement);

            formatter.Execute();
            return(sql.ToString());
        }
コード例 #4
0
        protected void FormatFrom()
        {
            bool multipleFroms = _statement.From.Count > 1;

            if (_statement.From == null || !_statement.From.Any())
            {
                return;
            }

            bool canCompactFormat = CanCompactFormat();

            NewLine(canCompactFormat ? 0 : 1);
            int fromIndex = 0;

            foreach (var from in _statement.From)
            {
                string fromText = !multipleFroms || from == _statement.From.First() ? "FROM " : "";

                DerivedTable derivedTable = from as DerivedTable;
                if (derivedTable != null)
                {
                    NewLine();
                    IndentAppend(String.Format("{0}(", fromText));
                    NewLine(canCompactFormat ? 1 : 2);

                    using (new IndentScope(this))
                    {
                        var formatter = new SelectStatementFormatter(this, _sql, derivedTable.SelectStatement);
                        formatter.Execute();
                    }
                    NewLine(canCompactFormat ? 1 : 2);
                    IndentAppend(String.Format("){0}", from.Alias.Value));
                }
                else
                {
                    bool isLast = from == _statement.From.Last();
                    NewLine(1);
                    IndentAppendFormat(
                        "{0}{1}{2}{3}{4}{5}",
                        fromIndex > 0 ? Indent + " " : "", fromText,
                        from.Name,
                        from.Alias.Value,
                        FormatHints(from),
                        !isLast && !from.Joins.Any() ? Constants.Comma + "\n" : ""
                        );
                }
                FormatJoins(from, multipleFroms, from == _statement.From.Last());
                fromIndex++;
            }
        }
コード例 #5
0
        public void Execute()
        {
            _sql.AppendFormat("{0} VIEW {1}\n", _statement.IsAlter ? "ALTER" : "CREATE", _statement.Name);
            _sql.AppendLine("AS");

            if (_statement.Definition is SelectStatement)
            {
                var formatter = new SelectStatementFormatter(this, _sql, (SelectStatement)_statement.Definition);
                formatter.Execute();
            }
            else if (_statement.Definition is CommonTableExpressionStatement)
            {
                var formatter = new CommonTableExpressionStatementFormatter(this, _sql, (CommonTableExpressionStatement)_statement.Definition);
                formatter.Execute();
            }
        }
コード例 #6
0
 private void FormatDerivedJoin(DerivedJoin derivedJoin)
 {
     NewLine(2);
     IndentAppend(derivedJoin.Value);
     NewLine(2);
     using (new IndentScope(this))
     {
         var formatter = new SelectStatementFormatter(this, _sql, derivedJoin.SelectStatement);
         formatter.Execute();
     }
     NewLine(2);
     IndentAppend(String.Format("){0}", derivedJoin.Alias.Value));
     NewLine();
     IndentAppendFormat(
         "  ON {0}",
         derivedJoin.Condition.FormattedValue(4, this)
         );
 }
コード例 #7
0
        private void FormatInputData()
        {
            if (_statement.Values.Any())
            {
                using (new IndentScope(this))
                {
                    var first = _statement.Values.First();
                    var last  = _statement.Values.Last();

                    foreach (var values in _statement.Values)
                    {
                        IndentAppendFormat(
                            "{0} {1}{2}",
                            values == first ? (" " + Constants.Values) : new string(' ', Constants.Values.Length),
                            FormatBrackets(GetValues(values)),
                            values == last ? String.Empty : ",\n"
                            );
                    }
                }
            }
            else if (_statement.SourceStatement != null)
            {
                using (new IndentScope(this))
                {
                    var formatter = new SelectStatementFormatter(this, _sql, _statement.SourceStatement);
                    formatter.Execute();
                }
            }
            //else if ( _statement.ExecuteProcudure != null )
            //{
            //    using ( new IndentScope( this ) )
            //    {
            //        var formatter = new ExecuteProcedureFormatter( this, _sql, _statement.ExecuteProcudure );
            //        formatter.Execute();
            //    }
            //}
        }