Oracle GROUP BY and DynaReporter
Note: for this example to work, you must switch your BusinessLogicJava.framework's Movies EOModel to an Oracle database. What this example does is display hashtables (NSDictionaries) fetched using raw SQL. The hashtables represent the results of performing an aggregate function on groups of records in a Table. The EOs aren't actually fetched. They are grouped on the Server by Oracle and just the aggregate operation results are returned.
Here's the line that fetches the dictionaries in this example: groupByRows = EOUtilities.rawRowsForSQL(
defaultEditingContext(),
"Movies",
"select category, count(*) from MOVIE group by category");
In this case, instead of a total, the aggregate function is a count(*) on the number of records in each group. Here I'm grouping by 'category'. The rows returned by this SQL operation are:
(
{Attribute0 = Action; Attribute1 = 9; },
{Attribute0 = Animated; Attribute1 = 1; },
{Attribute0 = Comedy; Attribute1 = 14; },
{Attribute0 = Cult; Attribute1 = 1; },
{Attribute0 = Detective; Attribute1 = 1; },
{Attribute0 = Documentary; Attribute1 = 2; },
{Attribute0 = Drama; Attribute1 = 29; },
{Attribute0 = "Film-noir"; Attribute1 = 5; },
{Attribute0 = Horror; Attribute1 = 1; },
{Attribute0 = Musical; Attribute1 = 1; },
{Attribute0 = Romantic; Attribute1 = 1; },
{Attribute0 = "Romantic Comedy"; Attribute1 = 1; },
{Attribute0 = "Sci-Fi"; Attribute1 = 2; },
{Attribute0 = Surreal; Attribute1 = 5; },
{Attribute0 = Thriller; Attribute1 = 7; },
{Attribute0 = Western; Attribute1 = 2; },
{Attribute0 = <NULL>; Attribute1 = 1; }
)Notice how Oracle named the attributes which became keys in my dictionaries. Different databases might name these keys differently. Note that you could group by more than one column by adding a item in the SELECT as well as adding the same column to the GROUP BY list.