Ron Savage wrote:
On Sun, 16 Apr 2006 22:15:22 +1000, Daniel Kasak wrote:
Hi Daniel
DBI: V 1.47
DBD::mysql: V 3.002
There are critical bugs in the $dbh->column_info() method in
DBD::mysql-3.x that prevent us from upgrading :(
I've tried a line identical to your:
$id = $self -> dbh() -> last_insert_id(undef, undef, $table_name, undef);
and I didn't get anything useful from it. Ah well. 'select @@IDENTITY'
works well for me, and appears to be the most compatible way of doing
things.
Is last_insert_id() supposed to work in versions prior to 3.x? I know
it's only a relatively recent addition. That means that the code below
requires more checks on the version of DBD::mysql to see if
last_insert_id() is supported ( and working ).
sub last_insert_id
{
my($self, $table_name) = @_;
my($id);
if ($self -> db_vendor() =~ /(?:mysql|Pg)/)
{
$id = $self -> dbh() -> last_insert_id(undef, undef,
$table_name, undef);
}
else # Oracle.
{
my($sth) = $self -> dbh() -> prepare("select ${table_name}_id_seq.currval from
dual");
$sth -> execute();
$id = ${$sth -> fetch()}[0];
$sth -> finish();
}
return $id;
} # End of last_insert_id.