示例#1
0
        internal override void AppendTo(SqlStringBuilder builder)
        {
            builder.Append("SELECT ");
            if (Distinct)
            {
                builder.Append("DISTINCT ");
            }

            var columns = SelectColumns.ToArray();
            var sz      = columns.Length;

            for (int i = 0; i < sz; i++)
            {
                columns[i].AppendTo(builder);

                if (i < sz - 1)
                {
                    builder.Append(", ");
                }
            }

            builder.Append(" ");

            if (FromClause != null)
            {
                FromClause.AppendTo(builder);
            }

            if (WhereExpression != null)
            {
                builder.Append(" WHERE ");
                WhereExpression.AppendTo(builder);
            }

            if (GroupBy != null)
            {
                var groupBy = GroupBy.ToList();
                builder.Append(" GROUP BY ");

                for (int i = 0; i < groupBy.Count; i++)
                {
                    groupBy[i].AppendTo(builder);

                    if (i < groupBy.Count - 1)
                    {
                        builder.Append(", ");
                    }
                }

                if (HavingExpression != null)
                {
                    builder.Append(" HVAING ");
                    HavingExpression.AppendTo(builder);
                }
            }

            if (GroupMax != null)
            {
                builder.Append(" GROUP MAX ");
                GroupMax.AppendTo(builder);
            }

            // TODO: COMPOSITE ...
        }