When I originally posted I assumed whoever had written DBD::Interbase had already coded the method but it was not being picked up.

last_insert_id in DBI is not well supported as it is generally quite difficult to implement. For instance, DBD::ODBC does not support it as each ODBC driver uses a different method to obtain the last identity value e.g., select @@identity or select id from sequence_name or countless other ways. I don't think DBD::Oracle supports it either as generally you use sequences in Oracle to generate unique ids and put them in a trigger. Lastly, the problem with many databases is that if you attempt to get the identity after the insert someone else may have used another one in the mean time. I suspect this latter issue will be the one that will hamper you in Firebird as I believe it uses generators and the only way to know for sure what the value is, is to create it yourself then use it in the insert - perhaps in a procedure.

A colleague tells me FB 2 supports the "returning" clause which is a lot neater but not going to help with DBIs last_insert_id.

Years ago when we started a project here that was to work with MySQL, Oracle, ODBC and DB2 we quickly found last_insert_id was next to useless and we created our own database independent method with database specific bits under the hood. For DB2 it did a select identity_val_local() from table, MySQL was select LAST_INSERT_ID() and Oracle was select LastInsertID() from dual where we wrote the LastInsertID function for Oracle which simply held an identity in a long held in the package. We no longer use it as it was just at the initial prototyping stage where writing the SQL in Perl was quicker and now all our SQL is in procedures.


In reply to Re^3: Building DBD::InterBase with last_insert_id by mje
in thread Building DBD::InterBase with last_insert_id by moritz

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.