diff --git a/src/core/feedsmodel.cpp b/src/core/feedsmodel.cpp index e62826a37..f3299ef44 100755 --- a/src/core/feedsmodel.cpp +++ b/src/core/feedsmodel.cpp @@ -35,7 +35,6 @@ #include #include -#include #include #include #include diff --git a/src/core/messagesmodel.cpp b/src/core/messagesmodel.cpp index b016f92d3..7d5511298 100755 --- a/src/core/messagesmodel.cpp +++ b/src/core/messagesmodel.cpp @@ -24,6 +24,7 @@ #include "miscellaneous/iconfactory.h" #include "gui/dialogs/formmain.h" #include "services/abstract/serviceroot.h" +#include "miscellaneous/databasequeries.h" #include #include @@ -258,18 +259,7 @@ bool MessagesModel::setMessageRead(int row_index, RootItem::ReadStatus read) { return false; } - QSqlQuery query_read_msg(database()); - query_read_msg.setForwardOnly(true); - - if (!query_read_msg.prepare(QSL("UPDATE Messages SET is_read = :read WHERE id = :id;"))) { - qWarning("Query preparation failed for message read change."); - return false; - } - - query_read_msg.bindValue(QSL(":id"), message.m_id); - query_read_msg.bindValue(QSL(":read"), (int) read); - - if (query_read_msg.exec()) { + if (DatabaseQueries::markMessageReadUnread(database(), message.m_id, read)) { return m_selectedItem->getParentServiceRoot()->onAfterSetMessagesRead(m_selectedItem, QList() << message, read); } else { diff --git a/src/miscellaneous/databasequeries.cpp b/src/miscellaneous/databasequeries.cpp new file mode 100644 index 000000000..25bee0a4b --- /dev/null +++ b/src/miscellaneous/databasequeries.cpp @@ -0,0 +1,39 @@ +// This file is part of RSS Guard. +// +// Copyright (C) 2011-2016 by Martin Rotter +// +// RSS Guard is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// RSS Guard is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with RSS Guard. If not, see . + +#include "miscellaneous/databasequeries.h" + +#include + + +bool DatabaseQueries::markMessageReadUnread(QSqlDatabase db, int id, RootItem::ReadStatus read) { + QSqlQuery query_read_msg(db); + query_read_msg.setForwardOnly(true); + + if (!query_read_msg.prepare(QSL("UPDATE Messages SET is_read = :read WHERE id = :id;"))) { + qWarning("Query preparation failed for message read change."); + return false; + } + + query_read_msg.bindValue(QSL(":id"), id); + query_read_msg.bindValue(QSL(":read"), (int) read); + + return query_read_msg.exec(); +} + +DatabaseQueries::DatabaseQueries() { +} diff --git a/src/miscellaneous/databasequeries.h b/src/miscellaneous/databasequeries.h new file mode 100644 index 000000000..95cda5b1f --- /dev/null +++ b/src/miscellaneous/databasequeries.h @@ -0,0 +1,35 @@ +// This file is part of RSS Guard. +// +// Copyright (C) 2011-2016 by Martin Rotter +// +// RSS Guard is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// RSS Guard is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with RSS Guard. If not, see . + +#ifndef DATABASEQUERIES_H +#define DATABASEQUERIES_H + +#include "services/abstract/rootitem.h" + +#include + + +class DatabaseQueries { + public: + static bool markMessageReadUnread(QSqlDatabase db, int id, RootItem::ReadStatus read); + + + private: + explicit DatabaseQueries(); +}; + +#endif // DATABASEQUERIES_H diff --git a/src/services/standard/standardfeed.cpp b/src/services/standard/standardfeed.cpp index 8ec1e7f32..33281d89e 100755 --- a/src/services/standard/standardfeed.cpp +++ b/src/services/standard/standardfeed.cpp @@ -383,7 +383,7 @@ bool StandardFeed::removeItself() { // Remove all messages from this standard feed. query_remove.prepare(QSL("DELETE FROM Messages WHERE feed = :feed;")); - query_remove.bindValue(QSL(":feed"), id()); + query_remove.bindValue(QSL(":feed"), customId()); if (!query_remove.exec()) { return false; diff --git a/src/services/tt-rss/ttrssfeed.cpp b/src/services/tt-rss/ttrssfeed.cpp index bbe51a4ba..8a2199011 100755 --- a/src/services/tt-rss/ttrssfeed.cpp +++ b/src/services/tt-rss/ttrssfeed.cpp @@ -213,14 +213,13 @@ bool TtRssFeed::removeItself() { } // Remove feed itself. - query_remove.prepare(QSL("DELETE FROM Feeds WHERE custom_id = :feed;")); - query_remove.bindValue(QSL(":feed"), customId()); + query_remove.prepare(QSL("DELETE FROM Feeds WHERE id = :feed;")); + query_remove.bindValue(QSL(":feed"), id()); return query_remove.exec(); } else { qWarning("TT-RSS: Unsubscribing from feed failed, received JSON: '%s'", qPrintable(response.toString())); - return false; } }