I highly recommend using SQL::Abstract to help you generate your place holders. You give it some perlish syntax describing your "where" statement, it gives you back a SQL snippet and some bind variables. Very clean and easy to use.

I used to use DBIx::Abstract, which is similar, but I found it does a lot more than I need, it's slower, and it's gets tied to your database handle. (Although I think the author may currently be working on making it faster and able to work without a DB handle).

Also, look at using the RaiseError and PrintError attributes in DBI to help with your error handling. It's not clear from the code above that you are doing any. My favorite technique is to turn on RaiseError, which will cause DBI to die if there is an error. Then I wrap a whole block of DBI statements with an eval statement, and check the errors in one place. Of course, this works better if your database supports transactions and you can rollback after an error. :)

You may also be interested in looking into the prepare_cached method for additional performance gains.

-mark


In reply to Re: Understanding placeholders by markjugg
in thread Understanding placeholders 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.