For the sake of completeness, in case any other monk happens upon this thread in future years, I shall mention here the solution that I've settled on, after reviewing above and some comments in the CB:
$dbh->do("LOCK TABLES tbl WRITE"); $dbh->do("INSERT INTO tbl VALUES(NULL,'foo','bar')"); my $ref = $dbh->selectcol_arrayref(" SELECT LAST_INSERT_ID() FROM tbl"); $dbh->do("UNLOCK TABLES");
This is not the best solution. The best solution would be either PostGreSQL, or getting transactions to work in MySQL. But given where I'm up to with the project I'm working on I'm going to have to live with the second-bestness of it. A bit of a sledgehammer to crack a nut... but it DOES crack the nut!

Thanks again to all those who've helped me with this.

update: crazyinsomniac /msg'd the following even better alternative:

from DBD::mysql
DATABASE HANDLES The DBD::mysql driver supports the following attributes of database ha +ndles (read only): $infoString = $dbh->{'info'}; $threadId = $dbh->{'thread_id'}; $insertId = $dbh->{'mysql_insertid'} These correspond to mysql_info(), mysql_thread_id() and mysql_insertid +(), respectively. insertid MySQL has the ability to choose unique key values automatically. If th +is happened, the new ID will be stored in this attribute. This attrib +u +te is not valid for DBD::mSQL. An alternative way for accessing this +a +ttribute is via $dbh->{'mysql_insertid'}. (Note we are using the $dbh + +in this case!)
So, each instance of your script will have its own database handle, and will only do one INSERT, so the 'mysql_insertid' will be the right one. There is no chance of the insertid being that of a subsequent INSERT that a different process performed (you're not sharing the handle, mysql will not fuck up in this manner).

§ George Sherston

In reply to Re: DBI: table locking by George_Sherston
in thread DBI: table locking by George_Sherston

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.