From: Russell, A. <arc...@me...> - 2003-08-22 18:31:13
|
How do I subscribe to this list? I'm having a problem with autonumbering. I'm using an oracle sequence to give numbers to my rows (using Class::DBI::Oracle. Here is my class declaration for a "Lab" class: package Genetics::Lab; use base 'Genetics::DBI'; Genetics::Lab->table('lab'); # pk comes first (only works for single val pks) Genetics::Lab->columns( All => qw / lab_id lab_name load_id /); # set up sequence __PACKAGE__->sequence('lab_seq'); And here's the code to create one of these use Genetics::Lab; my $lab = Genetics::Lab->create( { lab_name => 'somelab', load_id => 1}); This fails trying to insert NULL into column "lab_id" I tracked the error down to here in Class::DBI.pm if (@primary_columns == 1) { # table has a single primary key column # if it's null and there is a sequence, use it ### ### right here we're still ok, code seems to access oracle sequence alright and get next value ### the "data" hash gets the value. ### $data->{ $primary_columns[0] } ||= $class->_next_in_sequence if !defined($data->{ $primary_columns[0] }) && $class->sequence; } else { my @null_pk = grep { !defined $self->{$_} } @primary_columns; $class->_croak( "Can't create $class object with null primary key columns (@null_pk)") if @null_pk; } # Reinstate data : TODO make _insert_row operate on object, not $data my ($real, $temp) = ({}, {}); foreach my $col (grep exists $self->{$_}, $self->all_columns) { ($class->has_real_column($col) ? $real : $temp)->{$col} = $self->{$col}; } ### ### here is where the problem is. Real is a hash of columns, but doesn't include the ### primary key column ("lab_id" in this case). This causes the insert to fail ### ### the code above looks like it builds up the "real" hash based on what is in the $self hash, but ### self never has the pk column filled in (though it seems to go to the "data" hash) ### $self->_insert_row($real); $self->{ $primary_columns[0] } = $real->{ $primary_columns[0] } if @primary_columns == 1; Thanks Archie ------------------------------------------------------------------------------ Notice: This e-mail message, together with any attachments, contains information of Merck & Co., Inc. (Whitehouse Station, New Jersey, USA), and/or its affiliates (which may be known outside the United States as Merck Frosst, Merck Sharp & Dohme or MSD) that may be confidential, proprietary copyrighted and/or legally privileged, and is intended solely for the use of the individual or entity named on this message. If you are not the intended recipient, and have received this message in error, please immediately return this by e-mail and then delete it. ------------------------------------------------------------------------------ |