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/
_______________________________________________
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/[EMAIL PROTECTED]