Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
Dear Monks
I have seen code like this to handle errors when you retrieve a row count in sql
I assumed that this query only returned undef if there was an error but looking at the docs i am wrong.(my $buddy_count = $dbh->selectrow_array ("SELECT COUNT(*) FROM profil +e") ) or die "query failed"
so you can't tell with the code if there was an error or no more rows - but a select count should always return one row unless there is an error? So, what is the proper way of doing this?Also, in a scalar context, an undef is returned if there are no more r +ows or if an error occurred. That undef can't be distinguished from a +n undef returned because the first field value was NULL. For these re +asons you should exercise some caution if you use selectrow_array in +a scalar context, or just don't do that.
I have also read you should always use individual prepare and execute statements when executing select queries. What do you think about that?
Also when handling database errors is it 'better' to set RaiseError = 1 or handle the errors yourself manual with or diechecks. I've seen this link http://docstore.mik.ua/orelly/linux/dbi/ch04_05.htm and i think the upshot is to use RaiseError=1 as the code is cleaner and easier to read. What do you think?
thanks a lot
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: dbi error handling
by erix (Prior) on Dec 21, 2010 at 00:24 UTC | |
by runrig (Abbot) on Dec 21, 2010 at 17:02 UTC | |
by Anonymous Monk on Dec 22, 2010 at 03:31 UTC | |
by Anonymous Monk on Dec 22, 2010 at 04:01 UTC | |
by runrig (Abbot) on Dec 22, 2010 at 18:16 UTC |
Back to
Seekers of Perl Wisdom