--- nfo/perl/libs/Data/Storage/Handler/DBI.pm 2002/12/15 02:02:22 1.10 +++ nfo/perl/libs/Data/Storage/Handler/DBI.pm 2002/12/19 16:31:05 1.11 @@ -1,8 +1,12 @@ ################################# # -# $Id: DBI.pm,v 1.10 2002/12/15 02:02:22 joko Exp $ +# $Id: DBI.pm,v 1.11 2002/12/19 16:31:05 joko Exp $ # # $Log: DBI.pm,v $ +# Revision 1.11 2002/12/19 16:31:05 joko +# + sub dropDb +# + sub rebuildDb +# # Revision 1.10 2002/12/15 02:02:22 joko # + fixed logging-message # @@ -262,4 +266,51 @@ return $self->{_COREHANDLE}; } +sub dropDb { + my $self = shift; + my $dsn = $self->{locator}->{dbi}->{dsn}; + + $logger->debug( __PACKAGE__ . "->dropDb( dsn $dsn )" ); + + $dsn =~ s/database=(.+?);//; + my $database_name = $1; + + my $ok; + + if ( my $dbh = DBI->connect($dsn, '', '', { + PrintError => 0, + } ) ) { + if ($database_name) { + if ($dbh->do("DROP DATABASE $database_name;")) { + $ok = 1; + } + } + + $dbh->disconnect(); + + } + + return $ok; +} + +sub rebuildDb { + my $self = shift; + $logger->info( __PACKAGE__ . "->rebuildDb()" ); + my @results; + + # sum up results (bool (0/1)) in array + #push @results, $self->retreatSchema(); + push @results, $self->dropDb(); + push @results, $self->createDb(); + #push @results, $self->deploySchema(); + + # scan array for "bad ones" + my $res = 1; + map { + $res = 0 if (!$_); + } @results; + + return $res; +} + 1;