Re: Trouble making set_sql work...

[prev] [thread] [next] [Date index for 2004/07/13]

From: colm-cdbi
Subject: Re: Trouble making set_sql work...
Date: 14:54 on 13 Jul 2004
On Tue, Jul 13, 2004 at 10:28:05AM -0400, Andy Harrison wrote:
> 
> Maillog::Report::top_stats->show_top( $opt_top, $opt_top_limit );

set_sql doesn't work that way.

The set_sql will create a class method called 'sql_show_top' that will
return you a stamement handle for your SQL.  You need to use that
statement handle to fetch your results.  Class::DBI gives you shortcut
ways to write as little code as possible, e.g. :

  sub get_top_matches {
    my $class = shift;
    my $sth = $class->sql_show_top;
    $sth->execute($opt_top, $opt_top_limit);
    return $class->sth_to_objects($sth);
  }

This assumes that you want objects back (and that the first column of your
result set will be 'ids' for your objects).  If you just want raw
results in a list/hash/whatever then you can just get your $sth to use
one of the normal DBI methods.

You can see more about this in the section entitled 'Ima::DBI queries'
in the docs.

>     __PACKAGE__->set_sql( 'show_top' =>
>                                 qq { 
>                                     SELECT option_data, COUNT(*) 
>                                     FROM entry_options 
>                                     WHERE option = '?' 
>                                     GROUP BY option_data 
>                                     ORDER BY count DESC
>                                     LIMIT ?;
>                                    }
>                             );

You don't need the quoting of the first placeholder here or the
semi-colon at the end of the statement.  Also I'm pretty sure you
can't do 'LIMIT ?'.

Colm

(message missing)

Trouble making set_sql work...
Andy Harrison 14:28 on 13 Jul 2004

Re: Trouble making set_sql work...
colm-cdbi 14:54 on 13 Jul 2004

Re: Trouble making set_sql work...
colm-cdbi 15:10 on 13 Jul 2004

Re: Trouble making set_sql work...
Andy Harrison 14:58 on 13 Jul 2004

Re: Trouble making set_sql work...
Jesse Sheidlower 15:04 on 13 Jul 2004

Re: Trouble making set_sql work...
Andy Harrison 16:36 on 13 Jul 2004

Re: Trouble making set_sql work...
John Beppu 16:46 on 13 Jul 2004

Re: Trouble making set_sql work...
Stuart Johnston 16:50 on 13 Jul 2004

Re: Trouble making set_sql work...
Andy Harrison 17:32 on 13 Jul 2004

Re: Trouble making set_sql work...
colm-cdbi 18:38 on 13 Jul 2004

Re: Trouble making set_sql work...
Andy Harrison 19:33 on 13 Jul 2004

Re: Trouble making set_sql work...
Drew Taylor 19:44 on 13 Jul 2004

Re: Trouble making set_sql work...
colm-cdbi 20:08 on 13 Jul 2004

Re: Trouble making set_sql work...
Andy Harrison 20:52 on 13 Jul 2004

Re: Trouble making set_sql work...
colm-cdbi 18:57 on 13 Jul 2004

Re: Trouble making set_sql work...
Jay Strauss 15:10 on 13 Jul 2004

Re: Trouble making set_sql work...
Perrin Harkins 17:51 on 13 Jul 2004

Re: Trouble making set_sql work...
Andy Harrison 18:23 on 13 Jul 2004

Re: Trouble making set_sql work...
Stuart Johnston 19:44 on 13 Jul 2004

Generated at 11:34 on 01 Dec 2004 by mariachi v0.52