Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

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)

    Spacewarp

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

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (8)
As of 2020-01-23 10:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Notices?