1 package DBIx::Class::PK::Auto::Oracle;
8 use base qw/DBIx::Class/;
10 __PACKAGE__->load_components(qw/PK::Auto/);
14 $self->get_autoinc_seq unless $self->{_autoinc_seq};
15 my $sql = "SELECT " . $self->{_autoinc_seq} . ".currval FROM DUAL";
16 my ($id) = $self->result_source->storage->dbh->selectrow_array($sql);
23 # return the user-defined sequence if known
24 if ($self->sequence) {
25 return $self->{_autoinc_seq} = $self->sequence;
28 # look up the correct sequence automatically
29 my $dbh = $self->result_source->storage->dbh;
31 SELECT trigger_body FROM ALL_TRIGGERS t
32 WHERE t.table_name = ?
33 AND t.triggering_event = 'INSERT'
34 AND t.status = 'ENABLED'
36 # trigger_body is a LONG
37 $dbh->{LongReadLen} = 64 * 1024 if ($dbh->{LongReadLen} < 64 * 1024);
38 my $sth = $dbh->prepare($sql);
39 $sth->execute( uc($self->result_source->name) );
40 while (my ($insert_trigger) = $sth->fetchrow_array) {
41 if ($insert_trigger =~ m!(\w+)\.nextval!i ) {
42 $self->{_autoinc_seq} = uc($1);
45 unless ($self->{_autoinc_seq}) {
46 croak "Unable to find a sequence INSERT trigger on table '" . $self->_table_name . "'.";
54 DBIx::Class::PK::Auto::Oracle - Automatic primary key class for Oracle
58 # In your table classes
59 __PACKAGE__->load_components(qw/PK::Auto::Oracle Core/);
60 __PACKAGE__->set_primary_key('id');
64 This class implements autoincrements for Oracle.
68 Andy Grundman <andy@hybridized.org>
70 Scott Connelly <scottsweep@yahoo.com>
74 You may distribute this code under the same terms as Perl itself.