kal has asked for the wisdom of the Perl Monks concerning the following question:
Hi guys.
I'm having wonderful fun implementing 'latest app' in Class::DBI and Class::DBI::Pager (I've put off learning these modules for a while, and now regret it ;). However, I do have a problem - I'm interfacing with a Sybase database setup with auto incrementing (IDENTITY) primary keys, and Class::DBI doesn't like them.
Looking at the code, there is already a bit of a hack in there for this:
my $id = $dbh->{mysql_insertid} # mysql || eval { $dbh->func('last_insert_rowid') }; # SQLite $self->_croak("Can't get last insert id") unless defined $id;
Now, sadly, I can't just hook in there, because on Sybase I need to execute 'SELECT @@identity' immediately after the INSERT, there's no convenient variable hanging around for me to poach. And herein lies the issue.
I've overridden _auto_increment_value() to do this extra query, but all I get back is '0'. It seems that by the time I get to execute my query, Sybase has forgotton what @@identity is. I'm assuming this is to do with the database handle - I've tried turning off autoupdate/autocommit, but that doesn't make any different. I guess I'm just not getting their in time. I've even tried overriding _insert_row(), still no go. Perhaps the answer lies in Ima::DBI somewhere.
Has anyone got this combination to work in this style? I don't personally want to run without auto-incrementing keys, because that would be work. However, I do need to find some way of getting back the id of the recently created object, otherwise Class::DBI isn't going to speak to me :/ Can anyone offer any hints?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Class::DBI && Sybase
by IlyaM (Parson) on Apr 03, 2003 at 14:42 UTC | |
by kal (Hermit) on Apr 03, 2003 at 14:56 UTC | |
by mpeppler (Vicar) on Apr 03, 2003 at 16:51 UTC | |
by kal (Hermit) on Apr 03, 2003 at 17:55 UTC | |
by zengargoyle (Deacon) on Apr 04, 2003 at 01:20 UTC | |
|
Re: Class::DBI && Sybase
by DapperDan (Pilgrim) on Apr 03, 2003 at 14:00 UTC | |
|
Re: Class::DBI && Sybase
by zengargoyle (Deacon) on Apr 03, 2003 at 14:30 UTC |