Shouldn't prepare return a undefined reference on error, forcing the die to be executed?

prepare() is a funny beast. For many databases, it does a "please ignore the man behind the curtain" trick, saving the query until execute() time, when placeholders are expanded by the driver before sending the complete query over the wire to the server. In these case, errors in the query aren't detected until you try to execute().

Why is this? It's so that we can have a generic, RDBMS-independent API. Some databases don't support reusable queries. Others (e.g., Postgress) are just now supporting them. But by coding as if your database supports prepared queries, you're setting yourself up to benefit from performance gains if and when support for them is added.

But even if you're using a database that supports reusable queries, you want to check for errors at both prepare() and execute() time, since errors can happen at both.


In reply to Re: $dbh->prepare not triggering die by dws
in thread $dbh->prepare not triggering die by Nomis52

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.