[Dbix-class] oracle sequence auto-pk patch

Hartmaier Alexander Alexander.Hartmaier at t-systems.at
Thu Oct 4 16:06:56 GMT 2007


Hi!

That is possible now too, you only have to specify the sequence name in your table class:

__PACKAGE__->add_columns(
    id_table   => {
        sequence            => __PACKAGE__->schemaname . '.seq_for_this_table',
        is_auto_increment   => 1,
    },
);

Works for me flawless since dbic 0.05 or so...

-Alex


-----Original Message-----
From: Johannes Plunien [mailto:plu at pqpq.de] 
Sent: Thursday, September 06, 2007 11:53 AM
To: dbix-class at lists.scsys.co.uk
Subject: [Dbix-class] oracle sequence auto-pk patch

Hi,

thanks to mst who posted yesterday a few lines of code:

2007-09-05 19:31:40 <@mst> sub insert { my ($self, $source,
$to_insert) = @_; foreach my $pri ($source->primary_columns) { if (! 
defined $to_insert->{$pri}) { my $col_info = $source->column_info ($pri); if ($col_info->{auto_nextval}) { $to_insert->{$pri} = $self-  >_sequence_fetch('nextval',$col_info->{sequence}); } } $self-  >next::method($source, $to_insert); }
2007-09-05 19:32:44 <@mst> sub _sequence_fetch { my ($self, $type,
$seq) = @_; $self->_dbh_do("SELECT ${seq}.${type} FROM DUAL"); }

So now here's the patch with some test *attached* What does it do? You can use oracle & dbic with an autoincremental sequence WITHOUT using an oracle trigger.
So finally ".. insert a row with a primary key that uses a sequence?"  
from DBIx::Class::Manual::FAQ works :)

Kind regards,
plu

*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*
T-Systems Austria GesmbH   Rennweg 97-99, 1030 Wien
Handelsgericht Wien, FN 79340b
*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*
Notice: This e-mail contains information that is confidential and may be privileged.
If you are not the intended recipient, please notify the sender and then delete this e-mail immediately.
*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*


More information about the DBIx-Class mailing list