Perl-Sensitive Sunglasses | |
PerlMonks |
Re: Determining if a DBI SELECT comes back emptyby grinder (Bishop) |
on Dec 05, 2003 at 21:29 UTC ( [id://312652]=note: print w/replies, xml ) | Need Help?? |
There are cheaper ways of doing it... When I have to do things like this, the code tends to look like the following:
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.
In Section
Seekers of Perl Wisdom
|
|