Hi,
sorry, for the late response, I was a "little" busy...
> I've just started using DBIx and I was wondering what the syntax
> of implementing group functions such as MAX, MIN, AVG, SUM, and
> COUNT. How do you use DBIx to do for example:
> SELECT MAX(salary)
> FROM emp
> WHERE emp_name like '%L'
>
> and how you access the result.
>
Here is a short example for a count function:
*cnt = DBIx::Recordset -> Search ({'!DataSource' => $db,
'!Table' => 'foo',
'!Fields' => 'count(*)',
}) ;
This counts all the records in the table. If you want to group and/or order
use the '$order' and '$group' parameter additionaly. To access the data use
$num = (each (%cnt))[1] ;
this fetches the first value of the returned record. The name is assigned by
your database, so it may vary depending on your DBMS, but the value is
always found there. To see all names/values that are returned by the query
just do something like
while (($k, $v) = each (%cnt))
{
print "$k = $v\n" ;
}
If you don't like this way of retriving data, you could also get the
underlying statement handle and use DBI directly:
$sth = $cnt -> StHdl ;
$num = $sth -> fetchrow_arrayref -> [0] ;
Gerald
-------------------------------------------------------------
Gerald Richter ecos electronic communication services gmbh
Internetconnect * Webserver/-design/-datenbanken * Consulting
Post: Tulpenstrasse 5 D-55276 Dienheim b. Mainz
E-Mail: [EMAIL PROTECTED] Voice: +49 6133 925131
WWW: http://www.ecos.de Fax: +49 6133 925152
-------------------------------------------------------------