Subject: | No last_insert_id method found |
Hi,
In Class-DBI-3.0.14, around line 599, the $id variable is set from a
number of choices, the first of which is a call to the last_insert_id
method of the $dbh object.
In my environment (Linux/Fedora, perl-5.8.6, MySQL-5.0.16, DBI-3.000014,
DBIx-ContextualFetch-1.03), the object has no such method and my scripts
croak.
A simple solution would be to add a guard clause as follows.
OLD CODE:
my $id = $dbh->last_insert_id(undef, undef, $self->table, undef)
|| $dbh->{mysql_insertid}
|| eval { $dbh->func('last_insert_rowid') }
or $self->_croak("Can't get last insert id");
return $id;
NEW CODE:
my $id = ($dbh->can('last_insert_id') && $dbh->last_insert_id(undef,
undef, $self->table, undef))
|| $dbh->{mysql_insertid}
|| eval { $dbh->func('last_insert_rowid') }
or $self->_croak("Can't get last insert id");
return $id;
Cheers, Mark