Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re: Determining if a DBI SELECT comes back empty

by jZed (Prior)
on Dec 05, 2003 at 22:14 UTC ( #312674=note: print w/replies, xml ) Need Help??


in reply to Determining if a DBI SELECT comes back empty

Not all DBDs set the statement handle before a fetch, but MySQL does. That means that you don't have to fetch *any* rows. For a purposefully verbose example:
if (my $rows = $sth->execute) { if ($rows==0) { print "Zero rows returned"; } else { print "$rows rows returned"; } } else { print "Failed execute: ". $sth->errstr; } $sth->finish;
Note that the finish() is required here because you do no fetching. If one of the if's had a fetch, you'd omit the finish().

--

The heck with patents, here's how to protect your thoughts: <tinfoil>.o0(Martians can't read this)</tinfoil>

Replies are listed 'Best First'.
Re: Re: Determining if a DBI SELECT comes back empty
by tantarbobus (Hermit) on Dec 05, 2003 at 22:43 UTC

    Not all DBDs set the statement handle before a fetch, but MySQL does

    But not always. If you create the statement with mysql_use_result rows() will no longer behave that way.

    Note that the finish() is required here because you do no fetching. If one of the if's had a fetch, you'd omit the finish().

    If one had a fetch() and fetch()ed to the end of the result set. If you fetch 10 rows out of an 11 row result set you will still need to call finish on the sth

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (3)
As of 2019-11-19 20:27 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Strict and warnings: which comes first?



    Results (96 votes). Check out past polls.

    Notices?