[Dbix-class] FW: DBIC and Informix

Robert Carew Robert.Carew at topazsolutions.co.nz
Wed Sep 5 01:49:17 GMT 2007


Hi

Thanks Matt, almost right. The following works:

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

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

sub last_insert_id {
  shift->__last_insert_id;
}

using $args[0] rather than $type, $type is DBI::db hash.

I now need to try and understand what exactly is happening here.

Robert

-----Original Message-----
From: Matt S Trout [mailto:dbix-class at trout.me.uk]
Sent: Tue 9/4/2007 9:25 PM
To: DBIx::Class user and developer list
Subject: Re: [Dbix-class] FW: DBIC and Informix
 =

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 presen=
t I am working through the Catalyst Tutorial. I got this working ok with SQ=
Lite 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 w=
hich has a primary key of serial (auto-increment) the primary key of the ne=
w record is not retrieved. I tried overriding the "_dbh_last_insert_id" met=
hod by adding an Informix.pm module in the DBIx/Class/Storage/DBI folder. B=
ut this method does not have access to the statement handle in order to ret=
rieve the new key.
> The way the key is retrieved in Informix is:
> =

> my $sth =3D $dbh->prepare('insert .....');
> my $status =3D $sth->execute(...);
> =

> Immediately after an execute of an insert statement make the following ca=
ll
> =

> my $id =3D $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' =3D> '__last_insert_id');

sub _dbh_execute {
  my ($self, $type, @args) =3D @_;
  my ($rv, $sth, @rest) =3D $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 projec=
t?
   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=
/ =


_______________________________________________
List: http://lists.rawmode.org/cgi-bin/mailman/listinfo/dbix-class
IRC: irc.perl.org#dbix-class
SVN: http://dev.catalyst.perl.org/repos/bast/DBIx-Class/
Searchable Archive: http://www.grokbase.com/group/dbix-class@lists.rawmode.=
org


-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/ms-tnef
Size: 3987 bytes
Desc: not available
Url : http://lists.scsys.co.uk/pipermail/dbix-class/attachments/20070905/af=
f31e22/attachment.bin


More information about the DBIx-Class mailing list