in reply to DBI: table locking

You can get the last insert id from mySQL on a per-handle basis by asking for:

my $new_id = $dbh->{'mysql_insertid'};

Which should get around the problem, unless you're using Apache::DBI or something else that pools database handles.

update: remembered something i saw in the lower reaches of Class::DBI::Extension: you can lock a mysql table using:

$dbh->do('LOCK TABLES mumble WRITE');

and later

$dbh->do('UNLOCK TABLES');

But it's a rather drastic thing to do, and one of the main reasons some people are rude about MySQL.

Replies are listed 'Best First'.
Re: Re: DBI: table locking
by George_Sherston (Vicar) on Sep 17, 2001 at 21:07 UTC
    Hrrmm... alas, when I try this on the same basis as the methods I did above, I still end up returning the last ID inserted, rather than the ID inserted by the querying script. I fear there may be no alternative to table locking.

    § George Sherston