Finding last identity insert for Sybase database within Class::DBI
[prev]
[thread]
[next]
[Date index for 2004/04/29]
Hi all,
I've been using CDBI for a few days now, but have been avidly
reading up on researching it for the last month or three :)
As far as I can see - it's a great piece of software and I'm already
in love!
I ran into a problem with the _auto_increment_value method not
returning the proper last inserted id for sybase databases and overrode the
method. I've submitted the overridden _auto_increment_value to Dan Sully,
the maintainer for Class::DBI::Sybase, but was hoping that the kind (and
very very smart) people on this list could let me know if it's up to
Class::DBI's standards. If there's anything else that I might've missed or
if there are any changes you feel should be made.
Once more, let me reiterate that this is the first time I've used
Class::DBI and I'm still a bit unfamiliar with it's innards, so, forgive my
awkward coding within this method.
------------------------------------------------------------
sub _auto_increment_value
{
my $self = shift;
my $dbh = $self->db_Main;
my $row = eval { $dbh->selectcol_arrayref("SELECT \@\@identity") };
my $id = $row->[0];
if ($id == 0) # It appears that sometimes the proper last identity is not
returned. :(
# This is not ideal, but it's the next best thing to choose.
{
my @pri_column = $self->primary_columns; # If we're here, we'll only
ever have
# a one element array returned
afaik, so, no more
# checks should be required....
i hope...
# Also - just selecting the max value from the primary column could run
into problems - YMMV!
my $max_id = eval { $dbh->selectcol_arrayref("SELECT
MAX($pri_column[0]) FROM " . $self->table) };
$id = $max_id->[0];
}
$self->_croak("Can't get last insert id $id") unless defined $id;
return $id;
}
------------------------------------------------------------
--
Regards
Gabriel Fortuna - Internet Solutions
Theres no place like 127.0.0.1
|
Finding last identity insert for Sybase database within Class::DBI
"g 08:12 on 29 Apr 2004
|