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

ReadGroupByCount() protected method

Reads the results from the data reader produced by the group by query, creates the GroupCountResults, and returns them in the parameters collection.
protected ReadGroupByCount ( Hashtable parameters, IDataReader reader ) : void
parameters System.Collections.Hashtable Input and output parameters for the method.
reader IDataReader Data reader to read from.
return void
        protected virtual void ReadGroupByCount(Hashtable parameters, IDataReader reader)
        {
            ICollection<AbstractGroupExpression> groupExpressions =
                (ICollection<AbstractGroupExpression>) parameters["groupBys"];
            ClassMapping mapping = (ClassMapping) parameters["mapping"];
            List<GroupCountResult> results = new List<GroupCountResult>();
            parameters["results"] = results;

            // Read each row and store it as a GroupCountResult.
            while (reader.Read())
            {
                // We aliased the count as COUNT_COL_ALIAS.
                // Some databases return other numeric types, like "decimal", so you can't
                // just call reader.GetInt.
                string colName = COUNT_COL_ALIAS;
                int count = (int)CoerceType(typeof(int), reader.GetValue(reader.GetOrdinal(colName)));
                IDictionary<string, object> values = new CheckedDictionary<string, object>();
                int groupByNum = 0;
                foreach (AbstractGroupExpression expr in groupExpressions)
                {
                    values[expr.Name] = GetGroupByValue(mapping, reader, groupByNum, expr);
                    groupByNum++;
                }
                results.Add(new GroupCountResult(count, values));
            }
        }