This commit is contained in:
Martin Rotter 2021-03-12 10:54:15 +01:00
parent 424ec2b9af
commit da25498e51
1 changed files with 24 additions and 0 deletions

View File

@ -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 {