--- nfo/perl/libs/Data/Storage/Handler/DBI.pm 2002/12/19 16:31:05 1.11 +++ nfo/perl/libs/Data/Storage/Handler/DBI.pm 2003/04/08 23:06:45 1.13 @@ -1,8 +1,14 @@ ################################# # -# $Id: DBI.pm,v 1.11 2002/12/19 16:31:05 joko Exp $ +# $Id: DBI.pm,v 1.13 2003/04/08 23:06:45 joko Exp $ # # $Log: DBI.pm,v $ +# Revision 1.13 2003/04/08 23:06:45 joko +# renamed core database helper functions +# +# Revision 1.12 2003/01/30 22:28:21 joko +# + implemented new concrete methods +# # Revision 1.11 2002/12/19 16:31:05 joko # + sub dropDb # + sub rebuildDb @@ -51,11 +57,13 @@ use base ("Data::Storage::Handler::Abstract"); + use DBI; use Data::Dumper; -use libdb qw( getDbNameByDsn hash2Sql ); +use shortcuts::db qw( hash2sql dsn2dbname ); use Data::Storage::Result::DBI; + # get logger instance my $logger = Log::Dispatch::Config->instance; @@ -165,7 +173,7 @@ my $locator = $self->{locator}; #print Dumper($locator); exit; if (my $result = $self->sendCommand( 'SHOW TABLES;' ) ) { - my $dbname = getDbNameByDsn($self->{locator}->{dbi}->{dsn}); + my $dbname = dsn2dbname($self->{locator}->{dbi}->{dsn}); my $key = "Tables_in_$dbname"; while ( my $row = $result->getNextEntry() ) { push @nodes, $row->{$key}; @@ -205,7 +213,7 @@ map { $subnodes->{$_}++ } @{$query->{subnodes}}; # HACK: this is hardcoded ;( expand possibilities! my $crit = join(' AND ', @crits); - my $sql = hash2Sql($query->{node}, $subnodes, 'SELECT', $crit); + my $sql = hash2sql($query->{node}, $subnodes, 'SELECT', $crit); return $self->sendCommand($sql); } @@ -313,4 +321,29 @@ return $res; } +sub testAvailability { + my $self = shift; + my $status = $self->testDsn(); + $self->{locator}->{status}->{available} = $status; + return $status; +} + +sub testDsn { + my $self = shift; + my $dsn = $self->{locator}->{dbi}->{dsn}; + my $result; + if ( my $dbh = DBI->connect($dsn, '', '', { + PrintError => 0, + } ) ) { + + # TODO: REVIEW + $dbh->disconnect(); + + return 1; + } else { + $logger->warning( __PACKAGE__ . "[$self->{locator}->{type}]" . "->testDsn(): " . "DBI-error: " . $DBI::errstr ); + } +} + 1; +__END__