From b5dbf6b0678ecad80c6c948c642a3a5733f0b7ff Mon Sep 17 00:00:00 2001 From: Martin Rotter Date: Mon, 21 Mar 2016 07:11:07 +0100 Subject: [PATCH] Automatic switching to SQLite once MySQL is not available. --- resources/text/CHANGELOG | 1 + src/miscellaneous/databasefactory.cpp | 14 ++++++++++++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/resources/text/CHANGELOG b/resources/text/CHANGELOG index cd002d72c..097321b3f 100755 --- a/resources/text/CHANGELOG +++ b/resources/text/CHANGELOG @@ -9,6 +9,7 @@ http://goo.gl/forms/GcvPYgS2a8 Added: +▪ RSS Guard now automatically switches to SQLite backend if MySQL is not available on program startup. ▪ Opened web browser tabs now can be saved. (issue #126) ▪ Added experimental support for tweakable statusbar. (issue #158) ▪ Opening of download manager when new file download starts is now optional. (issue #165) diff --git a/src/miscellaneous/databasefactory.cpp b/src/miscellaneous/databasefactory.cpp index a20e180c4..9a3129b41 100755 --- a/src/miscellaneous/databasefactory.cpp +++ b/src/miscellaneous/databasefactory.cpp @@ -20,6 +20,7 @@ #include "miscellaneous/iofactory.h" #include "miscellaneous/application.h" #include "miscellaneous/textfactory.h" +#include "gui/messagebox.h" #include #include @@ -638,8 +639,17 @@ QSqlDatabase DatabaseFactory::mysqlInitializeDatabase(const QString &connection_ database.setPassword(TextFactory::decrypt(qApp->settings()->value(GROUP(Database), SETTING(Database::MySQLPassword)).toString())); if (!database.open()) { - qFatal("MySQL database was NOT opened. Delivered error message: '%s'", - qPrintable(database.lastError().text())); + qCritical("MySQL database was NOT opened. Delivered error message: '%s'", qPrintable(database.lastError().text())); + + // Now, we will display error warning and return SQLite connection. + // Also, we set the SQLite driver as active one. + qApp->settings()->setValue(GROUP(Database), Database::ActiveDriver, APP_DB_SQLITE_DRIVER); + determineDriver(); + MessageBox::show(NULL, QMessageBox::Critical, tr("MySQL database not available"), + tr("%1 cannot use MySQL storage, it is not available. %1 is now switching to SQLite database. Start your MySQL server " + "and make adjustments in application settings.").arg(APP_NAME), QString(), QString()); + + return connection(objectName(), FromSettings); } else { QSqlQuery query_db(database);