[CDBI] Dealing with non-required primary keys
peterspeltz at gmail.com
Sun Sep 4 12:46:18 BST 2005
On 9/3/05, Rusty Phillips <rustyp at freeshell.org> wrote:
> > > It's not really important to add a constraint to Class::DBI to handle
> > > the typename; the RDBMS will take care of that. What is important is
> > > how to deal with the typeid.
> > What do you mean - "how to deal with the typeid"?
> How to tell Class::DBI that the typeid is a generated by the database upon insertion.
You do this by not specifying a sequence. From docs;
sequence / auto_increment
$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:
__PACKAGE__->columns(Primary => 'id');
Class::DBI will use the sequence to generate a primary key
value when objects are created without one.
*NOTE* This method does not work for Oracle. However,
Class::DBI::Oracle (which can be downloaded separately from
CPAN) provides a suitable replacement sequence() method.
If you are using a database with AUTO_INCREMENT (e.g. MySQL)
then you do not need this, and any call to create() without a
primary key specified will fill this in automagically.
Sequence and auto-increment mechanisms only apply to tables
that have a single column primary key. For tables with multi-
column primary keys you need to supply the key values manu
More information about the ClassDBI