There's more than one way to do things | |
PerlMonks |
Re: if (empty record set)by digger (Friar) |
on Jun 26, 2003 at 16:12 UTC ( [id://269284]=note: print w/replies, xml ) | Need Help?? |
I have struggled with this same issue in the past. Just using the rows will not solve the problem, according to the DBI documentation. For SELECT statements, it is generally not possible to know how many rows will be returned except by fetching them all. Some drivers will return the number of rows the application has fetched so far, but others may return -1 until all rows have been fetched. So use of the rows method or $DBI::rows with SELECT statements is not recommended. You would have to do a fetchall_arrayref first, if I am understanding the docs correctly, then you could rely on the rows method. I ended up using the "SELECT COUNT(*) FROM ..." SQL statement to check the number of records returned. On a tangent, which method is more efficient? If I do a select count... first, then I might end up executing 2 SQL statements, if I get a count>0 from the select statement. If I do fetchall_arraref then I might end up pulling a large number of records into memory, and slowing things down. The answer is probably "it depends", but your input is appreciated. digger
In Section
Seekers of Perl Wisdom
|
|