From: janw Date: Wed, 4 Mar 2009 09:11:03 +0000 (+0000) Subject: Added automatic deletion of malformed databases. X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=09da8a9d20228264da852ed2f37a3a1379da3c7f;p=gosa.git Added automatic deletion of malformed databases. git-svn-id: https://oss.gonicus.de/repositories/gosa/branches/2.6-lhm@13489 594d385d-05f5-0310-b6e9-bd551577e9d8 --- diff --git a/trunk/gosa-si/modules/DBsqlite.pm b/trunk/gosa-si/modules/DBsqlite.pm index 0e1da74f6..cba1df504 100644 --- a/trunk/gosa-si/modules/DBsqlite.pm +++ b/trunk/gosa-si/modules/DBsqlite.pm @@ -18,6 +18,18 @@ sub new { my $lock = $db_name.".si.lock"; my $self = {dbh=>undef,db_name=>undef,db_lock=>undef,db_lock_handle=>undef}; my $dbh = DBI->connect("dbi:SQLite:dbname=$db_name", "", "", {RaiseError => 1, AutoCommit => 1}); + my $sth = $dbh->prepare("pragma integrity_check"); + $sth->execute(); + my @ret = $sth->fetchall_arrayref(); + if(length(@ret)==1 && $ret[0][0][0] eq 'ok') { + &main::daemon_log("DEBUG: Database image $db_name is ok", 7); + } else { + &main::daemon_log("ERROR: Database image $db_name is malformed, creating new database.", 1); + $sth->finish(); + $dbh->disconnect(); + unlink($db_name); + $dbh = DBI->connect("dbi:SQLite:dbname=$db_name", "", "", {RaiseError => 1, AutoCommit => 1}); + } $self->{dbh} = $dbh; $self->{db_name} = $db_name; $self->{db_lock} = $lock;