From 820b1b9a52c5aae6c833f42413c45f8c10099090 Mon Sep 17 00:00:00 2001 From: Martin Rotter Date: Sat, 4 Apr 2015 07:44:13 +0200 Subject: [PATCH] Some work on feeds core. --- src/core/feedsmodel.cpp | 1 - src/core/feedsmodelrecyclebin.cpp | 0 src/core/feedsmodelrecyclebin.h | 0 src/gui/formsettings.ui | 10 +++++---- src/miscellaneous/databasefactory.cpp | 29 ++++++++++++++++----------- 5 files changed, 23 insertions(+), 17 deletions(-) mode change 100644 => 100755 src/core/feedsmodelrecyclebin.cpp mode change 100644 => 100755 src/core/feedsmodelrecyclebin.h mode change 100644 => 100755 src/gui/formsettings.ui diff --git a/src/core/feedsmodel.cpp b/src/core/feedsmodel.cpp index eeda8bdd5..f926e4d05 100755 --- a/src/core/feedsmodel.cpp +++ b/src/core/feedsmodel.cpp @@ -264,7 +264,6 @@ bool FeedsModel::removeItem(const QModelIndex &index) { endRemoveRows(); delete deleting_item; - return true; } } diff --git a/src/core/feedsmodelrecyclebin.cpp b/src/core/feedsmodelrecyclebin.cpp old mode 100644 new mode 100755 diff --git a/src/core/feedsmodelrecyclebin.h b/src/core/feedsmodelrecyclebin.h old mode 100644 new mode 100755 diff --git a/src/gui/formsettings.ui b/src/gui/formsettings.ui old mode 100644 new mode 100755 index 3f8bfa391..3f10b5ee8 --- a/src/gui/formsettings.ui +++ b/src/gui/formsettings.ui @@ -88,7 +88,7 @@ - 7 + 1 @@ -346,7 +346,9 @@ Authors of this application are NOT responsible for lost data. - Note that speed of used MySQL server and latency of used connection medium HEAVILY influences the final performance of this application. Using slow database connections leads to bad performance when browsing feeds or messages. + Note that speed of used MySQL server and latency of used connection medium HEAVILY influences the final performance of this application. Using slow database connections leads to bad performance when browsing feeds or messages. + +MySQL backend will automatically use database with name "rssguard". Do not create this database manually, let this application to handle it by itself. Therefore, given user must have rights to created and deleted databases. Qt::AlignCenter @@ -470,8 +472,8 @@ Authors of this application are NOT responsible for lost data. 0 0 - 695 - 425 + 167 + 219 diff --git a/src/miscellaneous/databasefactory.cpp b/src/miscellaneous/databasefactory.cpp index a2d5cac6a..2a76189c4 100755 --- a/src/miscellaneous/databasefactory.cpp +++ b/src/miscellaneous/databasefactory.cpp @@ -248,9 +248,7 @@ QSqlDatabase DatabaseFactory::sqliteInitializeFileBasedDatabase(const QString &c query_db.exec("PRAGMA temp_store = MEMORY"); // Sample query which checks for existence of tables. - query_db.exec("SELECT inf_value FROM Information WHERE inf_key = 'schema_version'"); - - if (query_db.lastError().isValid()) { + if (!query_db.exec("SELECT inf_value FROM Information WHERE inf_key = 'schema_version'")) { qWarning("Error occurred. File-based SQLite database is not initialized. Initializing now."); QFile file_init(APP_MISC_PATH + QDir::separator() + APP_DB_SQLITE_INIT); @@ -262,8 +260,7 @@ QSqlDatabase DatabaseFactory::sqliteInitializeFileBasedDatabase(const QString &c qPrintable(APP_MISC_PATH)); } - QStringList statements = QString(file_init.readAll()).split(APP_DB_COMMENT_SPLIT, - QString::SkipEmptyParts); + QStringList statements = QString(file_init.readAll()).split(APP_DB_COMMENT_SPLIT, QString::SkipEmptyParts); database.transaction(); foreach(const QString &statement, statements) { @@ -403,8 +400,7 @@ bool DatabaseFactory::mysqlUpdateDatabaseSchema(QSqlDatabase database, const QSt return true; } -QSqlDatabase DatabaseFactory::connection(const QString &connection_name, - DesiredType desired_type) { +QSqlDatabase DatabaseFactory::connection(const QString &connection_name, DesiredType desired_type) { switch (m_activeDatabaseDriver) { case MYSQL: return mysqlConnection(connection_name); @@ -534,12 +530,10 @@ QSqlDatabase DatabaseFactory::mysqlInitializeDatabase(const QString &connection_ } else { QSqlQuery query_db(database); - query_db.setForwardOnly(true); if (!query_db.exec("USE rssguard") || !query_db.exec("SELECT inf_value FROM Information WHERE inf_key = 'schema_version'")) { - // If no "rssguard" database exists - // or schema version is wrong, then initialize it. + // If no "rssguard" database exists or schema version is wrong, then initialize it. qWarning("Error occurred. MySQL database is not initialized. Initializing now."); QFile file_init(APP_MISC_PATH + QDir::separator() + APP_DB_MYSQL_INIT); @@ -567,10 +561,21 @@ QSqlDatabase DatabaseFactory::mysqlInitializeDatabase(const QString &connection_ qDebug("MySQL database backend should be ready now."); } else { + // Database was previously initialized. Now just check the schema version. query_db.next(); - qDebug("MySQL database connection '%s' seems to be established.", qPrintable(connection_name)); - qDebug("MySQL database has version '%s'.", qPrintable(query_db.value(0).toString())); + QString installed_db_schema = query_db.value(0).toString(); + + if (!mysqlUpdateDatabaseSchema(database, installed_db_schema)) { + qFatal("Database schema was not updated from '%s' to '%s' successully.", + qPrintable(installed_db_schema), + APP_DB_SCHEMA_VERSION); + } + else { + qDebug("Database schema was updated from '%s' to '%s' successully or it is already up to date.", + qPrintable(installed_db_schema), + APP_DB_SCHEMA_VERSION); + } } query_db.finish();