From: Chris W. <ch...@cw...> - 2004-03-26 17:12:18
|
On Mar 26, 2004, at 10:15 AM, Vsevolod (Simon) Ilyushchenko wrote: > Maybe I am missing something, but is there a way in SPOPS to retrieve > expressions like MAX(field) etc. I'd like to be able to say something > like > my ($maxValue) = SPOPS::Class->select({select => [MAX(field)]}) > > (ie, keeping the SPOPS way of passing parameters compared to raw SQL > calls). > > It sounds simple, but I can't find a way of doing it. Every SPOPS::DBI implementation also subclasses SPOPS::SQLInterface, so you can do: my $max_row = SPOPS_Class->db_select({ field => [ 'MAX( myfield )' ], table => SPOPS_class->table_name, return => 'single' ); print "Max of 'myfield' is $max_row->[0]\n"; I always put stuff like this in the class implementation so I can just do something like: my $max = SPOPS_Class->find_max_myfield; Of course you can parameterize further, passing in 'myfield' and plugging it into the select; even just creating a find_max() in a parent class of all your SPOPS classes since this isn't tied to any particular class. Later, Chris -- Chris Winters Creating enterprise-capable snack systems since 1988 |