[CDBI] DBI's last_insert_id and Class::DBI's _auto_increment_value

Peter Speltz peterspeltz at gmail.com
Mon Nov 21 13:53:54 GMT 2005


I thought you had to define a sequence in you CDBI code  for PG cause
it does not have auto inc columns. Is that right?

sequence / auto_incre­
       ment

         __PACKAGE__->sequence($sequence_name);

         $sequence_name = Class->sequence;
         $sequence_name = $obj->sequence;

       If you are using a
       database which supports
       sequences and you want
       to use a sequence to
       automatically supply
       values for the primary
       key of a table, then you
       should declare this
       using the sequence()
       method:


On 11/21/05, David Steinbrunner <carbon at pobox.com> wrote:
> Hello,
>
> For the past several months I have been working on a system that uses MySQL
> and Class::DBI.  This has been my first project using Class::DBI while I
> have been hand coding queries for MySQL for several years.  I have just
> recently decided to make it so that the system works on top of Postgres,
> also.
>
> In the process of the getting Postgres working I ran into "Can't get last
> insert id".  I immediately did a Google search for last_insert_id and
> Class::DBI since I have used last_insert_id in a past database agnostic
> system.  I came upon the following:
>
> Class::DBI _auto_increment_value update/suggestion
> http://www.spanner.org/lists/cdbi/2005/06/22/03e95d38.html
>
> The discussion in the thread looks good but looking at the
> _auto_increment_value method has the following comment:
>
> # the DBI will provide a standard attribute soon, meanwhile...
>
> To get this up and running I went ahead and locally modified
> _auto_increment_value to use last_insert_id and I no longer have any issues.
>
> So now I have several questions.
>
> What is the progress on getting _auto_increment_value it use last_insert_id
> and released on CPAN?  Is there anything I can do to help make this happen
> such as code, testing or the like?
>
> Should I submit a RT bug concerning this issue?
>
> >From my understanding Postgres is a popular enough databases that it would
> seem that this type of issue would have been handled by now.  What are other
> Postgres users doing regarding this issue?
>
> My database schema relies heavily on auto incrementing primary keys which I
> never saw as a problem till I recently read the following from the Handel
> perldoc:
>
> http://search.cpan.org/~claco/Handel-0.27/lib/Handel.pm
>
> "Thanks to Class::DBI and staying away from auto incrementing ids, Handel
> should run in any database that Class::DBI supports."
>
> Aside from Class::DBI not using last_insert_id currently and some DBDs not
> supporting last_insert_id, are there other concerns that I should be aware
> of related to auto incrementing primary keys?
>
> Thanks,
>
> --
> David Steinbrunner
>
>
>
> _______________________________________________
> ClassDBI mailing list
> ClassDBI at lists.digitalcraftsmen.net
> http://lists.digitalcraftsmen.net/mailman/listinfo/classdbi
>


--
pjs




More information about the ClassDBI mailing list