Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re: Determining if a DBI SELECT comes back empty

by grinder (Bishop)
on Dec 05, 2003 at 21:29 UTC ( [id://312652]=note: print w/replies, xml ) Need Help??


in reply to Determining if a DBI SELECT comes back empty

There are cheaper ways of doing it... When I have to do things like this, the code tends to look like the following:

$sth->execute( @arg ); my $row = 0; while( defined( my $r = $sth->fetchrow_arrayref )) { ... # do stuff with $r .... ++$row; } print "fetched $row row(s)\n";

Just keeping a scalar around isn't a particularly expensive proposition. That's all your mySQL client is doing.

Note that for some database architectures, such as Sybase, the only way to determine the number of rows that a query would return is to go and fetch them; there is no way to know beforehand (that is, after the statement is executed but before the first row is fetched) how many rows will be returned.

I believe that the DBD driver for mySQL supports the rows method, which does provide you with this information beforehand, if you really need it, but do note that using it is not portable.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://312652]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (6)
As of 2024-04-19 07:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found