Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change

Re: Determining if a DBI SELECT comes back empty

by iburrell (Chaplain)
on Dec 05, 2003 at 21:46 UTC ( #312661=note: print w/replies, xml ) Need Help??

in reply to Determining if a DBI SELECT comes back empty

If you just need to know if there are any results but don't need to fetch them, use SELECT COUNT(*). If you need to both read any results and do something if nothing was read, then you can use a flag to signal when you read anything:
$sth->execute(); my $count = 0; while (my $row = $sth->fetchrow_arrayref()) { process_row($row); $count++; } unless ($count) { do_something_else(); }

Replies are listed 'Best First'.
Re: Re: Determining if a DBI SELECT comes back empty
by spacewarp (Pilgrim) on Dec 05, 2003 at 22:08 UTC
    Beautiful! Now that's the level of elegance I like to use, and I'm embarassed that I couldn't think of something this simple myself. 8)

    Thanks to everyone else as well.. you've added to my toolbox 8)


    Use of this advanced computing technology does not imply an endorsement
    of Western industrial civilization.

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (2)
As of 2021-01-27 03:40 GMT
Find Nodes?
    Voting Booth?