[CDBI] Group by and AbstractSearch

Bill Moseley moseley at hank.org
Fri Oct 21 19:20:50 BST 2005

On Fri, Oct 21, 2005 at 12:10:53PM -0400, Brett Sanger wrote:
> __PACKAGE__->set_sql( summarize =>  
>   "select fips, provider_type, count(id) as Count  
>   from __TABLE__
>   %s
>   group by fips, provider_type"
> );
> sub area_summary {
>   my $self = shift;
>   my $sql = SQL::Abstract->new();
>   my ($where, @bind) = $sql->where(@_);
>   return $self->sth_to_objects($self->sql_summarize($where), \@bind);
> }

That's how I do it.

> But again, I'm a little uncomfortable since sth_to_objects() is undocumented
> (but not marked as internal)

You might also look at Class::DBI::Sweet.  I provided a patch so
it can do aggregates like the above.  I use CDBI::Sweet for it's pager
on most of my selects and so avoid having to also write the
"area_summary" method as well.

Bill Moseley
moseley at hank.org

More information about the ClassDBI mailing list