George_Sherston has asked for the wisdom of the Perl Monks concerning the following question:
and then either$dbh->do("INSERT INTO tbl VALUES(NULL,'foo','bar')");
ormy $ref = $dbh->selectcol_arrayref( "SELECT MAX(LineID) FROM tbl" ); my $LineID = $$ref_booking[0];
But I tested this by making my script sleep between the INSERT and the SELECT, and whilst it was asleep running a second INSERT from another script. And in both cases, the result was that the SELECT returns the LineID for the record created by the second INSERT.my $ref = $dbh->selectcol_arrayref( "SELECT LAST_INSERT_ID() FROM tbl ");
... but, and here I tear out what little hair I have left, my MySQL doesn't support transactions.$dbh->{AutoCommit} = 0; # enable transactions, if possible $dbh->{RaiseError} = 1; eval { $dbh->do("INSERT INTO tbl VALUES(NULL,'foo','bar')"); my $ref = $dbh->selectcol_arrayref( "SELECT MAX(LineID) FROM tbl" ); $dbh->commit; # commit the changes if we get this far }; if ($@) { warn "Transaction aborted because $@"; $dbh->rollback; # undo the incomplete changes # add other application on-error-clean-up code here }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: DBI: table locking
by thpfft (Chaplain) on Sep 17, 2001 at 20:58 UTC | |
by George_Sherston (Vicar) on Sep 17, 2001 at 21:07 UTC | |
|
Re: DBI: table locking
by dga (Hermit) on Sep 17, 2001 at 23:45 UTC | |
|
Re: DBI: table locking
by pmas (Hermit) on Sep 17, 2001 at 21:02 UTC | |
by broquaint (Abbot) on Sep 17, 2001 at 21:25 UTC | |
by George_Sherston (Vicar) on Sep 17, 2001 at 21:08 UTC | |
|
Re: DBI: table locking
by George_Sherston (Vicar) on Sep 18, 2001 at 01:41 UTC |