From: Peter Rabbitson Date: Wed, 10 Feb 2010 11:40:37 +0000 (+0000) Subject: Consolidate last_insert_id handling with a fallback-attempt on DBI::last_insert_id X-Git-Tag: v0.08119~27 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=dbsrgits%2FDBIx-Class.git;a=commitdiff_plain;h=243d702ea2d1350e9c08d52eb84cdde745913452 Consolidate last_insert_id handling with a fallback-attempt on DBI::last_insert_id --- diff --git a/lib/DBIx/Class/Storage/DBI.pm b/lib/DBIx/Class/Storage/DBI.pm index 4333c4e..32c6ed1 100644 --- a/lib/DBIx/Class/Storage/DBI.pm +++ b/lib/DBIx/Class/Storage/DBI.pm @@ -2053,18 +2053,14 @@ Return the row id of the last insert. =cut sub _dbh_last_insert_id { - # All Storage's need to register their own _dbh_last_insert_id - # the old SQLite-based method was highly inappropriate + my ($self, $dbh, $source, $col) = @_; - my $self = shift; - my $class = ref $self; - $self->throw_exception (<last_insert_id (undef, undef, $source->name, $col) }; -No _dbh_last_insert_id() method found in $class. -Since the method of obtaining the autoincrement id of the last insert -operation varies greatly between different databases, this method must be -individually implemented for every storage class. -EOE + return $id if defined $id; + + my $class = ref $self; + $self->throw_exception ("No storage specific _dbh_last_insert_id() method implemented in $class, and the generic DBI::last_insert_id() failed"); } sub last_insert_id { diff --git a/lib/DBIx/Class/Storage/DBI/ODBC.pm b/lib/DBIx/Class/Storage/DBI/ODBC.pm index 2b7790d..f8e9209 100644 --- a/lib/DBIx/Class/Storage/DBI/ODBC.pm +++ b/lib/DBIx/Class/Storage/DBI/ODBC.pm @@ -21,15 +21,6 @@ sub _rebless { } } -sub _dbh_last_insert_id { - my ($self, $dbh, $source, $col) = @_; - - # punt: if there is no derived class for the specific backend, attempt - # to use the DBI->last_insert_id, which may not be sufficient (see the - # discussion of last_insert_id in perldoc DBI) - return $dbh->last_insert_id(undef, undef, $source->from, $col); -} - 1; =head1 NAME diff --git a/lib/DBIx/Class/Storage/DBI/SQLite.pm b/lib/DBIx/Class/Storage/DBI/SQLite.pm index 95122b1..f7977bb 100644 --- a/lib/DBIx/Class/Storage/DBI/SQLite.pm +++ b/lib/DBIx/Class/Storage/DBI/SQLite.pm @@ -10,11 +10,6 @@ use POSIX 'strftime'; use File::Copy; use File::Spec; -sub _dbh_last_insert_id { - my ($self, $dbh, $source, $col) = @_; - $dbh->func('last_insert_rowid'); -} - sub backup { my ($self, $dir) = @_;