Skip Menu |

This queue is for tickets about the Class-DBI CPAN distribution.

Report information
The Basics
Id: 20192
Status: resolved
Priority: 0/
Queue: Class-DBI

People
Owner: Nobody in particular
Requestors: m.orr [...] daxtra.com
Cc:
AdminCc:

Bug Information
Severity: Normal
Broken in: (no value)
Fixed in: (no value)



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
Subject: Re: [rt.cpan.org #20192] No last_insert_id method found
Date: Thu, 29 Jun 2006 20:11:08 +0100
To: Guest via RT <bug-Class-DBI [...] rt.cpan.org>
From: Tony Bowden <tony [...] kasei.com>
On Thu, Jun 29, 2006 at 01:46:12PM -0400, Guest via RT wrote: Show quoted text
> 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.
DBI is only at 1.51, so I doubt your above there is correct. last_insert_id() been in DBI since 1.38 (August 2003). Tony
From: m.orr [...] daxtra.com
On Thu Jun 29 15:12:10 2006, tony@kasei.com wrote: Show quoted text
> > DBI is only at 1.51, so I doubt your above there is correct. > last_insert_id() been in DBI since 1.38 (August 2003). > > Tony
Sorry, I reported the version incorrectly. Thanks for pointing that out. It turns out my DBI, or to be more precice, the DBI used by the company I just started working for, is at version 1.37 - so of course it wouldn't have last_insert_id. That explains it, I should just upgrade DBI. Thanks Tony.