public string ReBuild(bool reparse)
        {
            string sql = "SELECT \r\n\t";

            for (int i = 0; i < SelectList.Count; i++)
            {
                sql += SelectList[i];
                if (AsList[i] != null && !string.IsNullOrEmpty(AsList[i]))
                {
                    sql += " \tAS " + "\"" + AsList[i] + "\"";
                }
                if (i < SelectList.Count - 1)
                {
                    sql += ",\r\n\t";
                }
            }
            sql += "\r\n";

            sql += " FROM " + FromClause.TrimEnd() + "\r\n";
#if WHAT_WRONG
            if (string.IsNullOrEmpty(WhereClause) == false)
            {
                sql += " WHERE " + WhereClause.Trim() + "\r\n";
            }

            string groupby = GroupByClause.Trim().ToString();
            if (!string.IsNullOrEmpty(groupby))
            {
                sql += " GROUP BY " + groupby.TrimEnd() + "\r\n";
            }

            string orderby = OrderByClause.Trim().ToString();
            if (!string.IsNullOrEmpty(orderby))
            {
                sql += " ORDER BY " + orderby.TrimEnd() + "\r\n";
            }
            if (reparse)
            {
                Parse(sql);
            }
            return(sql.TrimEnd());
#else
            sql += " WHERE " + WhereClause.TrimEnd() + "\r\n";
            string groupby = GroupByClause.ToString();
            if (!string.IsNullOrEmpty(groupby))
            {
                sql += " GROUP BY " + groupby.TrimEnd() + "\r\n";
            }
            string orderby = OrderByClause.ToString();
            if (!string.IsNullOrEmpty(orderby))
            {
                sql += " ORDER BY " + orderby.TrimEnd() + "\r\n";
            }
            if (reparse)
            {
                Parse(sql);
            }
            return(sql.TrimEnd());
#endif
        }
Exemple #2
0
        public void GroupByClause(string result, params string[] exprs)
        {
            var clause = new GroupByClause(exprs);

            var sql = clause.ToString();

            Output.WriteLine(sql);

            sql.ShouldBeEquivalentTo(result);
        }
Exemple #3
0
        internal override string ToString(string indent)
        {
            var sb = new StringBuilder(1024);

            if (WithPathClause2 != null)
            {
                sb.Append(WithPathClause2.ToString(indent));
            }

            sb.AppendFormat("{0}SELECT ", indent);

            if (TopRowFilter != null)
            {
                if (TopRowFilter.OneLine())
                {
                    sb.AppendFormat("{0} ", TopRowFilter.ToString(""));
                }
                else
                {
                    sb.Append("\r\n");
                    sb.AppendFormat("{0} ", TopRowFilter.ToString(indent));
                }
            }

            switch (UniqueRowFilter)
            {
            case UniqueRowFilter.All:
                sb.Append("ALL ");
                break;

            case UniqueRowFilter.Distinct:
                sb.Append("DISTINCT ");
                break;
            }

            for (var i = 0; i < SelectElements.Count; i++)
            {
                if (i > 0)
                {
                    sb.Append(", ");
                }

                if (SelectElements[i].OneLine())
                {
                    sb.Append(SelectElements[i].ToString(""));
                }
                else
                {
                    sb.Append("\r\n");
                    sb.Append(SelectElements[i].ToString(indent + " "));
                }
            }

            if (Into != null)
            {
                sb.AppendFormat(" INTO {0} ", Into);
            }

            if (FromClause != null)
            {
                sb.Append("\r\n");
                sb.Append(FromClause.ToString(indent));
            }

            if (MatchClause != null)
            {
                sb.Append("\r\n");
                sb.Append(MatchClause.ToString(indent));
            }

            if (WhereClause != null && (WhereClause.SearchCondition != null || !string.IsNullOrEmpty(WhereClause.GhostString)))
            {
                sb.Append("\r\n");
                sb.Append(WhereClause.ToString(indent));
            }

            if (GroupByClause != null)
            {
                sb.Append("\r\n");
                sb.Append(GroupByClause.ToString(indent));
            }

            if (HavingClause != null)
            {
                sb.Append("\r\n");
                sb.Append(HavingClause.ToString(indent));
            }

            if (OrderByClause != null)
            {
                sb.Append("\r\n");
                sb.Append(OrderByClause.ToString(indent));
            }

            return(sb.ToString());
        }