SPOPS::DBI::Oracle - Oracle-specific routines for the SPOPS::DBI


SPOPS documentation Contained in the SPOPS distribution.

Index


Code Index:

NAME

Top

SPOPS::DBI::Oracle -- Oracle-specific routines for the SPOPS::DBI

SYNOPSIS

Top

 # Define your table and sequence

 CREATE TABLE mytable (
   id int not null primary key,
   ...
 );

 CREATE SEQUENCE MySeq;

 # In your configuration:

 'myspops' => {
     'isa'             => [ qw/ SPOPS::DBI::Oracle SPOPS::DBI / ],
     'id'              => 'id',
     'no_insert'       => [ 'id' ],
     'increment_field' => 1,
     'sequence_name'   => 'MySeq';
     ...
 },

DESCRIPTION

Top

This subclass allows you to specify a sequence name from which you can retrieve the next ID value.

METHODS

Top

pre_fetch_id

Fetch the data from the specified sequence and return it.

sql_quote

DBD::Oracle uses the type of a field to implement the DBI quote() call, so we override the default 'sql_quote' from SPOPS::SQLInterface.

BUGS

Top

None known.

TO DO

Top

Nothing known.

SEE ALSO

Top

DBD::Oracle

DBI

COPYRIGHT

Top

AUTHORS

Top

Chris Winters <chris@cwinters.com>


SPOPS documentation Contained in the SPOPS distribution.

package SPOPS::DBI::Oracle;

# $Id: Oracle.pm,v 3.6 2004/06/02 00:48:22 lachoy Exp $

use strict;
use SPOPS::Exception qw( spops_error );
use SPOPS::Utility;

$SPOPS::DBI::Oracle::VERSION  = sprintf("%d.%02d", q$Revision: 3.6 $ =~ /(\d+)\.(\d+)/);

sub sql_current_date  { return SPOPS::Utility->now() }

use constant ORA_SEQUENCE_NEXT    => 'SELECT %s.NextVal FROM dual';
use constant ORA_SEQUENCE_CURRENT => 'SELECT %s.CurrVal FROM dual';

sub pre_fetch_id {
    my ( $item, $p ) = @_;
    my ( $seq_name );
    return undef unless ( $item->CONFIG->{increment_field} );
    return undef unless ( $seq_name = $item->CONFIG->{sequence_name} );
    my ( $sth );
    eval {
        $sth = $p->{db}->prepare( sprintf( ORA_SEQUENCE_NEXT, $seq_name ) );
        $sth->execute;
    };
    if ( $@ ) {
        spops_error "Failed to retrieve ID from sequence '$seq_name': $@";
    }
    return ( $sth->fetchrow_arrayref->[0], undef );
}


sub post_fetch_id {
    return undef;
}

1;

__END__