Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
One idea, though probably not the most efficient, would be to create two prepared statements, one for insert and another for query.
use DBI; #connection stuff #prepare your statement handles #assuming the values are unique enough... my $sth_ins = $dbh->prepare("INSERT INTO table_foo(col1,col2,col3) VAL +UES(?,?,?)"); #after the insert run the query on those same values. my $sth_sel = $dbh->prepare("SELECT id FROM table_foo WHERE col1=?, co +l2=?, col3=?"); #...later in the code... my $last_id; for(@some_data_of_yours){ $sth_ins->execute($_->{'col1'},$_->{'col2'},$_->{'col3'}); $sth_sel->execute($_->{'col1'},$_->{'col2'},$_->{'col3'}); $sth_sel->bind_columns(\$last_id); $sth_sel->fetch(); #do some stuff with your $last_id... }
Seems like overkill but at least you can trust the results. Basically a "Read it back to me" strategy.
Not sure how much load this will add to things but since the statements are prepared you get all of those benefits. You can also use the select statement as a pre-check to see if the data is already in the DB. Just a thought...

"I do not feel obliged to believe that the same God who endowed us with sense, reason and intellect has intended us to forego their use." -Galileo

In reply to Re: DBI insert: Need to retrieve an autoincremented column from a table after an insert. by injunjoel
in thread DBI insert: Need to retrieve an autoincremented column from a table after an insert. by SkipHuffman

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, 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, 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.
  • Log In?

    What's my password?
    Create A New User
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others having an uproarious good time at the Monastery: (6)
    As of 2019-06-18 23:08 GMT
    Find Nodes?
      Voting Booth?
      Is there a future for codeless software?

      Results (83 votes). Check out past polls.

      • (Sep 10, 2018 at 22:53 UTC) Welcome new users!