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

Re: Re: if (empty record set)

by Grygonos (Chaplain)
on Jun 26, 2003 at 15:10 UTC ( [id://269261]=note: print w/replies, xml ) Need Help??


in reply to Re: if (empty record set)
in thread if (empty record set)

on many RDBMS the execute method will return the number of rows like so:
my $query = "SELECT * FROM myTable"; $sth = $dbh->prepare($query); if(!$sth->execute()) { ... }
it varies from system to system .. but is another way to accomplish what you want

edit: you could also run this query
SELECT Count(yourPrimaryKeyHere) FROM yourTable
if you're on a database that doesn't support execute's return value or $sth->rows

Replies are listed 'Best First'.
Re: Re: Re: if (empty record set)
by Lachesis (Friar) on Jun 26, 2003 at 15:35 UTC
    Thats not the way execute works in DBI. Check the docs, but to summarise for you now
    If an error occurs you get undef back
    If it doesn't know the number of rows affected get -1 back
    If no rows are affected you will get 0E0 back.
    otherwise you get the number of rows affected
      The last time I tried it on MySQL it worked like that... but that was a while ago things may have changed...

      hope my old company doesn't upgrade their DBI because I used that return value from execute on a number of scripts which worked fine under that version of dbi... Thanks for the update.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (2)
As of 2024-04-26 04:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found