Beispiel #1
0
        /// <summary>
        /// Returns the statement as an SQL string.
        /// </summary>
        public override String ToString()
        {
            var stringBuilder = new StringBuilder("SELECT ");

            if (!Columns.Any())
            {
                Columns.Add("*");
            }

            stringBuilder.AppendLine(String.Join(QueryBuilder.ColumnSeparator, Columns));
            stringBuilder.AppendLine(FromBuilder.ToString());

            if (GroupByColumns.Any())
            {
                stringBuilder.AppendLine("GROUP BY " + String.Join(QueryBuilder.ColumnSeparator, GroupByColumns));
            }

            if (OrderByColumns.Any())
            {
                var orderByColumns = OrderByColumns
                                     .Select(pair => pair.Key + " " + (pair.Value == SortingDirection.Ascending ? "ASC" : "DESC"))
                                     .ToArray();

                stringBuilder.AppendLine("ORDER BY " + String.Join(QueryBuilder.ColumnSeparator, orderByColumns));
            }

            return(stringBuilder.ToString().Trim());
        }
Beispiel #2
0
        /// <summary>
        /// Converts this SoqlQuery into a string format suitable for use in a SODA call.
        /// </summary>
        /// <returns>The string representation of this SoqlQuery.</returns>
        public override string ToString()
        {
            var sb = new StringBuilder();

            sb.AppendFormat("{0}=", SelectKey);

            if (SelectColumns.Length == 1 && SelectColumns[0] == "*")
            {
                sb.Append(SelectColumns[0]);
            }
            else
            {
                //evaluate the provided aliases
                var finalColumns = SelectColumns.Zip(SelectColumnAliases, (c, a) => String.Format("{0} AS {1}", c, a)).ToList();

                if (SelectColumns.Length > SelectColumnAliases.Length)
                {
                    //some columns were left un-aliased
                    finalColumns.AddRange(SelectColumns.Skip(SelectColumnAliases.Length));
                }

                //form the select clause
                sb.Append(String.Join(Delimiter, finalColumns));
            }

            sb.AppendFormat("&{0}={1} {2}", OrderKey, String.Join(Delimiter, OrderByColumns), OrderDirection);

            if (!String.IsNullOrEmpty(WhereClause))
            {
                sb.AppendFormat("&{0}={1}", WhereKey, WhereClause);
            }

            if (GroupByColumns != null && GroupByColumns.Any())
            {
                sb.AppendFormat("&{0}={1}", GroupKey, String.Join(Delimiter, GroupByColumns));
            }

            if (OffsetValue > 0)
            {
                sb.AppendFormat("&{0}={1}", OffsetKey, OffsetValue);
            }

            if (LimitValue > 0)
            {
                sb.AppendFormat("&{0}={1}", LimitKey, LimitValue);
            }

            if (!String.IsNullOrEmpty(SearchText))
            {
                sb.AppendFormat("&{0}={1}", SearchKey, SearchText);
            }

            return(sb.ToString());
        }
Beispiel #3
0
 public bool IsTrivial()
 {
     return((WhereExpr == null || WhereExpr.Type == ExprType.EMPTY) &&
            (GroupWhereExpr == null || GroupWhereExpr.Type == ExprType.EMPTY) &&
            !Columns.Any() &&
            !OrderByExprs.Any() &&
            !Joins.Any() &&
            RowsLimit == null &&
            RowsOffset == 0 &&
            !DistinctRecords &&
            !GroupByColumns.Any());
 }