One way to achieve database portability and avoid race conditions is to assign the id from a common source independent of the database, then insert the id along with your data. The example below (untested) of course is not OS portable and has some warts of its own.
my $episodeid = nextId(); my $query=qq(INSERT INTO MasterEpisode SET episoideid = "$episodeid", ShowId = "$ShowID", title = "$p->{'ep_title'}", description = "$p->{'ep_description'}", uploaddate = "@{[localtime]}" ); sub nextId { open my $seq, "+<", "sequence.dat"; flock $seq, 2 my $id = <$seq>; $id++; print $seq $id; close $seq; return $id; }
In reply to Re: DBI insert: Need to retrieve an autoincremented column from a table after an insert.
by hangon
in thread DBI insert: Need to retrieve an autoincremented column from a table after an insert.
by SkipHuffman
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |