From 30f4974863325adb3aae8bb5531cfd8eb53f7db1 Mon Sep 17 00:00:00 2001
From: Andrew Yates <ayates@ebi.ac.uk>
Date: Tue, 18 Oct 2011 14:29:37 +0000
Subject: [PATCH] Bringing in a new method which allows us to retrieve the last
 inserted identifier into the table this adaptor is working with via DBI.
 Should be called from within an execute block so we do not need to wrap this
 in a work_with_dbh call

---
 modules/Bio/EnsEMBL/DBSQL/BaseAdaptor.pm | 25 ++++++++++++++++++++++++
 1 file changed, 25 insertions(+)

diff --git a/modules/Bio/EnsEMBL/DBSQL/BaseAdaptor.pm b/modules/Bio/EnsEMBL/DBSQL/BaseAdaptor.pm
index 7675e5269d..8340f1e518 100755
--- a/modules/Bio/EnsEMBL/DBSQL/BaseAdaptor.pm
+++ b/modules/Bio/EnsEMBL/DBSQL/BaseAdaptor.pm
@@ -657,6 +657,31 @@ sub fetch_all {
   return $self->generic_fetch();
 }
 
+=head2 last_insert_id
+
+  Arg [1]     : (optional) $field the name of the field the inserted ID was pushed 
+                into
+  Arg [2]     : (optional) HashRef used to pass extra attributes through to the 
+                DBD driver
+  Description : Delegating method which uses DBI to extract the last inserted 
+                identifier. If using MySQL we just call the DBI method 
+                L<DBI::last_insert_id()> since MySQL ignores any extra
+                arguments. See L<DBI> for more information about this 
+                delegated method. 
+  Example     : my $id = $self->last_insert_id('my_id'); my $other_id = $self->last_insert_id();
+  Returntype  : Scalar or undef
+  
+=cut
+
+sub last_insert_id {
+  my ($self, $field, $attributes) = @_;
+  my $dbc = $self->dbc();
+  my $dbh = $dbc->db_handle();
+  $attributes ||= {};
+  my ($table) = $self->_tables();
+  return $dbh->last_insert_id(undef, $dbc->dbname(), $table->[0], $field, $attributes);
+}
+
 
 #_tables
 #
-- 
GitLab