diff --git a/src/librssguard/database/databasefactory.cpp b/src/librssguard/database/databasefactory.cpp index df8c47890..3275ee93c 100644 --- a/src/librssguard/database/databasefactory.cpp +++ b/src/librssguard/database/databasefactory.cpp @@ -5,6 +5,7 @@ #include "3rd-party/boolinq/boolinq.h" #include "database/mariadbdriver.h" #include "database/sqlitedriver.h" +#include "exceptions/applicationexception.h" #include "gui/messagebox.h" #include "miscellaneous/application.h" #include "miscellaneous/iofactory.h" @@ -43,6 +44,29 @@ void DatabaseFactory::determineDriver() { if (m_dbDriver == nullptr) { qFatal("DB driver for '%s' was not found.", qPrintable(db_driver)); } + + if (m_dbDriver->driverType() != DatabaseDriver::DriverType::SQLite) { + // Try to setup connection and fallback to SQLite. + try { + m_dbDriver->connection(metaObject()->className()); + } + catch (const ApplicationException& ex) { + qCriticalNN << LOGSEC_DB + << "Failed to reach connection to DB source, will fallback to SQLite:" + << QUOTE_W_SPACE_DOT(ex.message()); + + qApp->showGuiMessage(tr("Cannot connect to database"), + tr("Connection to your database was not established with error '%1'. " + "Falling back to SQLite.").arg(ex.message()), + QSystemTrayIcon::MessageIcon::Critical, + nullptr, + true); + + m_dbDriver = boolinq::from(m_allDbDrivers).first([](DatabaseDriver* driv) { + return driv->driverType() == DatabaseDriver::DriverType::SQLite; + }); + } + } } DatabaseDriver* DatabaseFactory::driver() const {