1# $Id: Oracle.pm,v 1.1 2001/08/02 16:32:22 matt Exp $ 2 3package Example::DB::Oracle; 4 5use strict; 6 7sub _init 8{ 9 my $self = shift; 10 11 $self->get_dbh->{LongReadLen} = $self->config_value('LongReadLen') || ( 2**16 - 1 ); 12 $self->get_dbh->{LongTruncOk} = 1; 13 14 # Since the default date picture format for a given Oracle database 15 # cannot be known in advance, its best to set it to something 16 # consistent and easy to deal with. 17 $self->do_sql( sql => q|ALTER SESSION SET NLS_DATE_FORMAT = 'YYYYMMDDHH24MISS'| ); 18} 19 20sub sql_date 21{ 22 my $self = shift; 23 my $time = localtime( shift || time ); 24 25 return $time->strftime('%Y%m%d%H%M%S'); 26} 27 28sub _prepare_and_execute 29{ 30 my $self = shift; 31# ::Utils::check_params( @_, 32# mandatory => ['sql'], 33# optional => [ qw( begin limit bind ) ], 34# ); 35 my %p = @_; 36 37 my @bind = exists $p{bind} ? ( ref $p{bind} ? @{ $p{bind} } : $p{bind} ) : (); 38 39 my $sth; 40 eval 41 { 42 $sth = $self->get_dbh->prepare_cached( $p{sql} ); 43 $sth->execute(@bind); 44 }; 45 if ($@) 46 { 47 Example::Exception::SQL->throw( -text => $@, 48 -sql => $p{sql}, 49 -bind => \@bind ); 50 } 51 52 return $sth; 53} 54 55sub _outer_join_operator 56{ 57 return '(+)='; 58} 59 60sub get_next_pk 61{ 62 my $self = shift; 63 64# ::Utils::check_params( @_, 65# mandatory => [ qw( table ) ], 66# ); 67 my %p = @_; 68 69 my $id = $self->get_one_row( sql => "SELECT $p{table}_seq.NEXTVAL FROM DUAL" ); 70 71 $self->{last_id} = $id; 72 73 return $id; 74} 75 76sub last_id 77{ 78 my $self = shift; 79 80 return delete $self->{last_id}; 81} 82 831; 84