Azavea.Open.DAO.SQL.SqlDaLayer.GroupBysToEndOfQuery C# (CSharp) Method

GroupBysToEndOfQuery() public method

Adds the group by fields to the end of the query, including the keyword "GROUP BY" if necessary.
public GroupBysToEndOfQuery ( SqlDaQuery query, ICollection groupExpressions, ClassMapping mapping ) : void
query SqlDaQuery Query to append to.
groupExpressions ICollection Group by expressions.
mapping ClassMapping Class mapping for the class we're dealing with.
return void
        public virtual void GroupBysToEndOfQuery(SqlDaQuery query,
            ICollection<AbstractGroupExpression> groupExpressions, ClassMapping mapping)
        {
            if (groupExpressions.Count > 0)
            {
                query.Sql.Append(" GROUP BY ");
            }
            bool first = true;
            foreach (AbstractGroupExpression expression in groupExpressions)
            {
                if (first)
                {
                    first = false;
                }
                else
                {
                    query.Sql.Append(", ");
                }
                if (expression is MemberGroupExpression)
                {
                    query.Sql.Append(
                        mapping.AllDataColsByObjAttrs[((MemberGroupExpression) expression).MemberName]);
                }
                else
                {
                    throw new ArgumentException(
                        "Group expression '" + expression + "' is an unsupported type.",
                        "groupExpressions");
                }
            }
        }