mirror of
https://github.com/clementine-player/Clementine
synced 2024-12-17 20:09:50 +01:00
Run database integrity check on startup
Update issue #2743 Integrity check now run on startup
This commit is contained in:
parent
ab0ae4414b
commit
9cf279f5a3
@ -89,6 +89,8 @@ Application::Application(QObject* parent)
|
|||||||
|
|
||||||
library_->Init();
|
library_->Init();
|
||||||
library_->StartThreads();
|
library_->StartThreads();
|
||||||
|
|
||||||
|
QMetaObject::invokeMethod(database_, "DoBackup", Qt::QueuedConnection);
|
||||||
}
|
}
|
||||||
|
|
||||||
Application::~Application() {
|
Application::~Application() {
|
||||||
|
@ -21,6 +21,7 @@
|
|||||||
#include "utilities.h"
|
#include "utilities.h"
|
||||||
#include "core/application.h"
|
#include "core/application.h"
|
||||||
#include "core/logging.h"
|
#include "core/logging.h"
|
||||||
|
#include "core/taskmanager.h"
|
||||||
|
|
||||||
#include <QCoreApplication>
|
#include <QCoreApplication>
|
||||||
#include <QDir>
|
#include <QDir>
|
||||||
@ -634,3 +635,44 @@ bool Database::CheckErrors(const QSqlQuery& query) {
|
|||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Database::IntegrityCheck(QSqlDatabase db) {
|
||||||
|
int task_id = app_->task_manager()->StartTask(tr("Integrity check"));
|
||||||
|
|
||||||
|
bool ok = false;
|
||||||
|
bool error_reported = false;
|
||||||
|
// Ask for 10 error messages at most.
|
||||||
|
QSqlQuery q(QString("PRAGMA integrity_check(10)"), db);
|
||||||
|
while (q.next()) {
|
||||||
|
QString message = q.value(0).toString();
|
||||||
|
|
||||||
|
// If no errors are found, a single row with the value "ok" is returned
|
||||||
|
if (message == "ok") {
|
||||||
|
ok = true;
|
||||||
|
break;
|
||||||
|
} else {
|
||||||
|
if (!error_reported) {
|
||||||
|
app_->AddError(tr("Database corruption detected. Please read "
|
||||||
|
"https://code.google.com/p/clementine-player/wiki/DatabaseCorruption "
|
||||||
|
"for instructions on how to recover your database"));
|
||||||
|
}
|
||||||
|
app_->AddError("Database: " + message);
|
||||||
|
error_reported = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
app_->task_manager()->SetTaskFinished(task_id);
|
||||||
|
|
||||||
|
return ok;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Database::DoBackup() {
|
||||||
|
QSqlDatabase db(this->Connect());
|
||||||
|
|
||||||
|
// Before we overwrite anything, make sure the database is not corrupt
|
||||||
|
const bool ok = IntegrityCheck(db);
|
||||||
|
|
||||||
|
if (ok) {
|
||||||
|
// TODO: Run database backup...
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -64,12 +64,16 @@ class Database : public QObject {
|
|||||||
signals:
|
signals:
|
||||||
void Error(const QString& message);
|
void Error(const QString& message);
|
||||||
|
|
||||||
|
private slots:
|
||||||
|
void DoBackup();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void UpdateMainSchema(QSqlDatabase* db);
|
void UpdateMainSchema(QSqlDatabase* db);
|
||||||
|
|
||||||
void UpdateDatabaseSchema(int version, QSqlDatabase& db);
|
void UpdateDatabaseSchema(int version, QSqlDatabase& db);
|
||||||
void UrlEncodeFilenameColumn(const QString& table, QSqlDatabase& db);
|
void UrlEncodeFilenameColumn(const QString& table, QSqlDatabase& db);
|
||||||
QStringList SongsTables(QSqlDatabase& db, int schema_version) const;
|
QStringList SongsTables(QSqlDatabase& db, int schema_version) const;
|
||||||
|
bool IntegrityCheck(QSqlDatabase db);
|
||||||
|
|
||||||
struct AttachedDatabase {
|
struct AttachedDatabase {
|
||||||
AttachedDatabase() {}
|
AttachedDatabase() {}
|
||||||
|
Loading…
Reference in New Issue
Block a user