| 1 | package SPOPS::DBI::Oracle; | ||
| 2 | |||
| 3 | # $Id: Oracle.pm,v 3.6 2004/06/02 00:48:22 lachoy Exp $ | ||
| 4 | |||
| 5 | use strict; | ||
| 6 | use SPOPS::Exception qw( spops_error ); | ||
| 7 | use SPOPS::Utility; | ||
| 8 | |||
| 9 | $SPOPS::DBI::Oracle::VERSION = sprintf("%d.%02d", q$Revision: 3.6 $ =~ /(\d+)\.(\d+)/); | ||
| 10 | |||
| 11 | sub sql_current_date { return SPOPS::Utility->now() } | ||
| 12 | |||
| 13 | use constant ORA_SEQUENCE_NEXT => 'SELECT %s.NextVal FROM dual'; | ||
| 14 | use constant ORA_SEQUENCE_CURRENT => 'SELECT %s.CurrVal FROM dual'; | ||
| 15 | |||
| 16 | sub pre_fetch_id { | ||
| 17 | my ( $item, $p ) = @_; | ||
| 18 | my ( $seq_name ); | ||
| 19 | return undef unless ( $item->CONFIG->{increment_field} ); | ||
| 20 | return undef unless ( $seq_name = $item->CONFIG->{sequence_name} ); | ||
| 21 | my ( $sth ); | ||
| 22 | eval { | ||
| 23 | $sth = $p->{db}->prepare( sprintf( ORA_SEQUENCE_NEXT, $seq_name ) ); | ||
| 24 | $sth->execute; | ||
| 25 | }; | ||
| 26 | if ( $@ ) { | ||
| 27 | spops_error "Failed to retrieve ID from sequence '$seq_name': $@"; | ||
| 28 | } | ||
| 29 | return ( $sth->fetchrow_arrayref->[0], undef ); | ||
| 30 | } | ||
| 31 | |||
| 32 | |||
| 33 | sub post_fetch_id { | ||
| 34 | return undef; | ||
| 35 | } | ||
| 36 | |||
| 37 | 1; | ||
| 38 | |||
| 39 | __END__ |