Dear Monks

I have seen code like this to handle errors when you retrieve a row count in sql

(my $buddy_count = $dbh->selectrow_array ("SELECT COUNT(*) FROM profil +e") ) or die "query failed"
I assumed that this query only returned undef if there was an error but looking at the docs i am wrong.
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.
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?

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

In reply to dbi error handling by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.