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 |
# |
# |
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 { |
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; |
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; |
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 |
|
|