I've been using a method suggested in the here early in my tenure at the forum, but recently I've been told it's bad, but I haven't been able to get a straight answer on what the "correct" way is...

Basically, I want to insert a record unless it violates the primary key. If it violates the PK, I want to update the row with the new information. To do this, I've been using something like:

eval { $insert_stmt->execute($pk,$what, $ever, $else) } if ($@) { $update_stmt->execute($what, $ever, $else, $pk) }

I understand that the eval traps any error, PK or otherwise and tries the update... I've even struggled with debugging malformed mysql statements until I remembered this, but I don't have a better way to do it.

This is all about processing log files, and I doubt I'm the only person in the world that has data for a primary key's record potentially coming more than one "processing session". Can someone help me with a best practice for this?

thanks,

--Jimbus aka Jim Babcock
Wireless Data Engineer and Geek Wannabe
jim-dot-babcock-at-usa-dot-com

In reply to Of Mysql, DBI and PK best practices by jimbus

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.