/[cvs]/nfo/perl/libs/Data/Storage/Handler/DBI.pm
ViewVC logotype

Diff of /nfo/perl/libs/Data/Storage/Handler/DBI.pm

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.1 by cvsjoko, Thu Oct 10 03:44:07 2002 UTC revision 1.2 by joko, Fri Oct 25 11:43:27 2002 UTC
# Line 3  Line 3 
3  #  $Id$  #  $Id$
4  #  #
5  #  $Log$  #  $Log$
6    #  Revision 1.2  2002/10/25 11:43:27  joko
7    #  + enhanced robustness
8    #  + more logging for debug-levels
9    #
10  #  Revision 1.1  2002/10/10 03:44:07  cvsjoko  #  Revision 1.1  2002/10/10 03:44:07  cvsjoko
11  #  + new  #  + new
12  #  #
# Line 32  sub connect { Line 36  sub connect {
36            
37      # create handle      # create handle
38        if ( my $dsn = $self->{dbi}->{dsn} ) {        if ( my $dsn = $self->{dbi}->{dsn} ) {
39          $logger->debug( __PACKAGE__ . "->connect($dsn)" );          $logger->debug( __PACKAGE__ . "->connect( dsn $dsn )" );
40          $self->{COREHANDLE} = DBI->connect($dsn);          
41            # HACK:
42            # set errorhandler before actually calling DBI->connect
43            # in order to catch errors from the very beginning
44            #DBI->{HandleError} = $self->{dbi}->{HandleError};
45            
46            #use Data::Dumper; print Dumper($self->{dbi});
47            
48            $self->{COREHANDLE} = DBI->connect(
49              $dsn, '', '', {
50                RaiseError => $self->{dbi}->{RaiseError},
51                #RaiseError => 1,
52                PrintError => $self->{dbi}->{PrintError},
53                HandleError => $self->{dbi}->{HandleError},
54              }
55            );
56            if (!$self->{COREHANDLE}) {
57              $logger->warning( __PACKAGE__ . "->connect failed: " . DBI::errstr );
58              return;
59            }
60        }        }
61        $self->configureCOREHANDLE();        $self->configureCOREHANDLE();
62            
63        return 1;
64        
65  }  }
66    
67  sub configureCOREHANDLE {  sub configureCOREHANDLE {
# Line 64  sub configureCOREHANDLE { Line 89  sub configureCOREHANDLE {
89  sub _sendSql {  sub _sendSql {
90    my $self = shift;    my $self = shift;
91    my $sql = shift;    my $sql = shift;
92      
93      # two-level handling for implicit connect:
94      # if there's no corehandle ...
95      if (!$self->{COREHANDLE}) {
96        # ... try to connect, but ...
97        $self->connect();
98        # ... if this still fails, there's something wrong probably, so we won't continue
99        if (!$self->{COREHANDLE}) {
100          return;
101        }
102      }
103      
104    my $sth = $self->{COREHANDLE}->prepare($sql);    my $sth = $self->{COREHANDLE}->prepare($sql);
105    $sth->execute();    $sth->execute();
106    return $sth;    return $sth;
# Line 72  sub _sendSql { Line 109  sub _sendSql {
109  sub sendCommand {  sub sendCommand {
110    my $self = shift;    my $self = shift;
111    my $command = shift;    my $command = shift;
112      #$logger->debug( __PACKAGE__ . "->sendCommand( command $command )" );
113    my $cmdHandle = $self->_sendSql($command);    my $cmdHandle = $self->_sendSql($command);
114    my $result = Data::Storage::Result::DBI->new( RESULTHANDLE => $cmdHandle );    my $result = Data::Storage::Result::DBI->new( RESULTHANDLE => $cmdHandle );
115    return $result;    return $result;
# Line 157  use base ("Data::Storage::Result"); Line 195  use base ("Data::Storage::Result");
195  sub DESTROY {  sub DESTROY {
196    my $self = shift;    my $self = shift;
197    #$logger->debug( __PACKAGE__ . "->" . "DESTROY" );    #$logger->debug( __PACKAGE__ . "->" . "DESTROY" );
198    $self->{RESULTHANDLE}->finish();    $self->{RESULTHANDLE} && $self->{RESULTHANDLE}->finish();
199  }  }
200    
201  sub _getNextEntry {  sub _getNextEntry {
202    my $self = shift;    my $self = shift;
203    return $self->{RESULTHANDLE}->fetchrow_hashref;    $self->{RESULTHANDLE} && return $self->{RESULTHANDLE}->fetchrow_hashref;
204  }  }
205    
206    

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.2

MailToCvsAdmin">MailToCvsAdmin
ViewVC Help
Powered by ViewVC 1.1.26 RSS 2.0 feed