As an unfortunate user recently found out, this depends on the database. DBI offers 
the 'rows' method that you would call on your statement handle to tell you the number 
of rows it returned (this is NOT matched rows, for example if you use a LIMIT these 
are two very different things).

I know MySQL supports this method, but I can't tell you about any other DBs.

http://danconia.org

------------------------------------------------
On Mon, 18 Nov 2002 13:26:56 -0800 (PST), "Roderick A. Anderson" <[EMAIL PROTECTED]> 
wrote:

> Looked at Q&A for databases at perl.org, been through the Cheetah book 
> (several times) and can't seem to find an archive of this list so I'm down 
> to asking for help what is probably a FAQ.  But I hope to put a twist on 
> it.
> 
> I'm querying a table what may return more than one row.  If there is more 
> than one row I display a selection list (so the users can pick the one 
> they want) or else the results of the query.
> 
> So far it is a brute force effort.  I use fetchall_arrayref and determine
> the count of rows returned.  Question is is the correct method to return
> the count of an array of references 'scalar(@$array_ref)' or is there an
> easier/trickier/DBI way to check on the count?
> 
> 
> And here's some code.  (Please be gentle.  I'm trying to get back into 
> this after several years of hit and miss coding.)
> 
> .... 
> 
> my ($dbh, $sth, $cnt, $qry_domainname);
> 
> ....
> 
> my $domain_cnt_qry = "SELECT tbl_key, domainname " .
>     "  FROM domain_info " .
>     " WHERE domain_name LIKE '%?%' " .
>     " ORDER BY domainname ";
> 
> ....
> 
> $sth = $dbh->prepare($domain_cnt_qry);
> $sth->execute($qry_domainname);
> 
> $domain_array = $sth->fetchall_arrayref();
> $cnt = scalar(@$domain_array);
> 
> if ($cnt > 1) {
> 
>       ### Print a selection list of domains
> 
> } else {
> 
>       ### Print the domain information
> 
> }
> 
> 
> TIA,
> Rod
> -- 
>   "Open Source Software - Sometimes you get more than you paid for..."
> 
> 

Reply via email to