[Dbix-class] FW: DBIC and Informix

Matt S Trout dbix-class at trout.me.uk
Tue Sep 4 10:25:22 GMT 2007


On Tue, Sep 04, 2007 at 12:46:17PM +1200, Robert Carew wrote:
> Request originally posted on Catalyst list.
> 
> Hi
> 
> I am trying to use Catalyst and DBIC with an Informix database. At present I am working through the Catalyst Tutorial. I got this working ok with SQLite and have now converted it for Informix. 
> So far the select and insert statements are working ok.
> The problem I am having is when a record is inserted in the books table which has a primary key of serial (auto-increment) the primary key of the new record is not retrieved. I tried overriding the "_dbh_last_insert_id" method by adding an Informix.pm module in the DBIx/Class/Storage/DBI folder. But this method does not have access to the statement handle in order to retrieve the new key.
> The way the key is retrieved in Informix is:
> 
> my $sth = $dbh->prepare('insert .....');
> my $status = $sth->execute(...);
> 
> Immediately after an execute of an insert statement make the following call
> 
> my $id = $sth->{ix_sqlerrd}[1];
> 
> How can I get hold of the statement handle in order to execute this call?
> Any ideas?

How about (in your Informix.pm) -

__PACKAGE__->mk_group_accessors('simple' => '__last_insert_id');

sub _dbh_execute {
  my ($self, $type, @args) = @_;
  my ($rv, $sth, @rest) = $self->next::method($type, @args);
  if ($type eq 'insert') {
    $self->__last_insert_id($sth->{ix_sqlerrd}[1]);
  }
  return (wantarray ? ($rv, $sth, @rest) : $rv);
}

sub last_insert_id {
  shift->__last_insert_id;
}

-- 
      Matt S Trout       Need help with your Catalyst or DBIx::Class project?
   Technical Director    Want a managed development or deployment platform?
 Shadowcat Systems Ltd.  Contact mst (at) shadowcatsystems.co.uk for a quote
http://chainsawblues.vox.com/                    http://www.shadowcat.co.uk/ 



More information about the DBIx-Class mailing list