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?


In reply to Class::DBI && Sybase by kal

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.