1 package DBIx::Class::Storage::DBI::Oracle::Generic;
2 # -*- mode: cperl; cperl-indent-level: 2 -*-
7 use Carp::Clan qw/^DBIx::Class/;
9 use base qw/DBIx::Class::Storage::DBI::MultiDistinctEmulation/;
11 # __PACKAGE__->load_components(qw/PK::Auto/);
13 sub _dbh_last_insert_id {
14 my ($self, $dbh, $source, $col) = @_;
15 my $seq = ($source->column_info($col)->{sequence} ||= $self->get_autoinc_seq($source,$col));
16 my $sql = 'SELECT ' . $seq . '.currval FROM DUAL';
17 my ($id) = $dbh->selectrow_array($sql);
21 sub _dbh_get_autoinc_seq {
22 my ($self, $dbh, $source, $col) = @_;
24 # look up the correct sequence automatically
26 SELECT trigger_body FROM ALL_TRIGGERS t
27 WHERE t.table_name = ?
28 AND t.triggering_event = 'INSERT'
29 AND t.status = 'ENABLED'
32 # trigger_body is a LONG
33 $dbh->{LongReadLen} = 64 * 1024 if ($dbh->{LongReadLen} < 64 * 1024);
35 my $sth = $dbh->prepare($sql);
36 $sth->execute( uc($source->name) );
37 while (my ($insert_trigger) = $sth->fetchrow_array) {
38 return uc($1) if $insert_trigger =~ m!(\w+)\.nextval!i; # col name goes here???
40 croak "Unable to find a sequence INSERT trigger on table '" . $source->name . "'.";
44 my ($self, $source, $col) = @_;
46 $self->dbh_do($self->can('_dbh_get_autoinc_seq'), $source, $col);
49 sub columns_info_for {
50 my ($self, $table) = @_;
52 $self->next::method(uc($table));
60 DBIx::Class::Storage::DBI::Oracle - Automatic primary key class for Oracle
64 # In your table classes
65 __PACKAGE__->load_components(qw/PK::Auto Core/);
66 __PACKAGE__->set_primary_key('id');
67 __PACKAGE__->sequence('mysequence');
71 This class implements autoincrements for Oracle.
75 Andy Grundman <andy@hybridized.org>
77 Scott Connelly <scottsweep@yahoo.com>
81 You may distribute this code under the same terms as Perl itself.