Beefy Boxes and Bandwidth Generously Provided by pair Networks
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??


in reply to if (empty record set)

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

Log In?
Username:
Password:

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

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

    No recent polls found