support mysql -> sqlite fallback
This commit is contained in:
		
							parent
							
								
									e306fc1182
								
							
						
					
					
						commit
						98be85fa14
					
				
					 2 changed files with 10 additions and 11 deletions
				
			
		| 
						 | 
					@ -52,15 +52,14 @@ void DatabaseFactory::determineDriver() {
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    catch (const ApplicationException& ex) {
 | 
					    catch (const ApplicationException& ex) {
 | 
				
			||||||
      qCriticalNN << LOGSEC_DB
 | 
					      qCriticalNN << LOGSEC_DB
 | 
				
			||||||
                  << "Failed to reach connection to DB source, will fallback to SQLite:"
 | 
					                  << "Failed to reach connection to DB source, let's fallback to SQLite:"
 | 
				
			||||||
                  << QUOTE_W_SPACE_DOT(ex.message());
 | 
					                  << QUOTE_W_SPACE_DOT(ex.message());
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      qApp->showGuiMessage(tr("Cannot connect to database"),
 | 
					      MessageBox::show(nullptr,
 | 
				
			||||||
                           tr("Connection to your database was not established with error '%1'. "
 | 
					                       QMessageBox::Icon::Critical,
 | 
				
			||||||
                              "Falling back to SQLite.").arg(ex.message()),
 | 
					                       tr("Cannot connect to database"),
 | 
				
			||||||
                           QSystemTrayIcon::MessageIcon::Critical,
 | 
					                       tr("Connection to your database was not established with error: '%1'. "
 | 
				
			||||||
                           nullptr,
 | 
					                          "Falling back to SQLite.").arg(ex.message()));
 | 
				
			||||||
                           true);
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
      m_dbDriver = boolinq::from(m_allDbDrivers).first([](DatabaseDriver* driv) {
 | 
					      m_dbDriver = boolinq::from(m_allDbDrivers).first([](DatabaseDriver* driv) {
 | 
				
			||||||
        return driv->driverType() == DatabaseDriver::DriverType::SQLite;
 | 
					        return driv->driverType() == DatabaseDriver::DriverType::SQLite;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -150,8 +150,8 @@ QSqlDatabase MariaDbDriver::initializeDatabase(const QString& connection_name) {
 | 
				
			||||||
  database.setPassword(qApp->settings()->password(GROUP(Database), SETTING(Database::MySQLPassword)).toString());
 | 
					  database.setPassword(qApp->settings()->password(GROUP(Database), SETTING(Database::MySQLPassword)).toString());
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  if (!database.open()) {
 | 
					  if (!database.open()) {
 | 
				
			||||||
    qFatal("Cannot open MySQL database: %s. Make sure your DB server is running and "
 | 
					    // NOTE: In this case throw exception and fallback SQL backend will be used.
 | 
				
			||||||
           "start application again.", qPrintable(database.lastError().text()));
 | 
					    throw ApplicationException(database.lastError().text());
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
  else {
 | 
					  else {
 | 
				
			||||||
    QSqlQuery query_db(database);
 | 
					    QSqlQuery query_db(database);
 | 
				
			||||||
| 
						 | 
					@ -279,8 +279,8 @@ QSqlDatabase MariaDbDriver::connection(const QString& connection_name, DatabaseD
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (!database.isOpen() && !database.open()) {
 | 
					    if (!database.isOpen() && !database.open()) {
 | 
				
			||||||
      qFatal("MySQL database was NOT opened. Delivered error message: '%s'.",
 | 
					      // NOTE: In this case throw exception and fallback SQL backend will be used.
 | 
				
			||||||
             qPrintable(database.lastError().text()));
 | 
					      throw ApplicationException(database.lastError().text());
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    else {
 | 
					    else {
 | 
				
			||||||
      qDebugNN << LOGSEC_DB
 | 
					      qDebugNN << LOGSEC_DB
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		
		Reference in a new issue