From e4ee0f19fdba922c3b0b64f311d0a6dfe7ab94c6 Mon Sep 17 00:00:00 2001 From: Bart De Vries Date: Fri, 1 Oct 2021 15:46:17 +0200 Subject: [PATCH] Do not create feed object if it's not in the database Also clear errors related to a feed that's being removed from the database. --- src/datamanager.cpp | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/datamanager.cpp b/src/datamanager.cpp index 8257e2f1..0ec5ac71 100644 --- a/src/datamanager.cpp +++ b/src/datamanager.cpp @@ -237,8 +237,13 @@ void DataManager::removeFeed(const int index) // Then delete everything from the database qCDebug(kastsDataManager) << "delete database part of" << feedurl; - // Delete Authors + // Delete related Errors QSqlQuery query; + query.prepare(QStringLiteral("DELETE FROM Errors WHERE url=:url;")); + query.bindValue(QStringLiteral(":url"), feedurl); + Database::instance().execute(query); + + // Delete Authors query.prepare(QStringLiteral("DELETE FROM Authors WHERE feed=:feed;")); query.bindValue(QStringLiteral(":feed"), feedurl); Database::instance().execute(query); @@ -502,7 +507,15 @@ void DataManager::exportFeeds(const QString &path) void DataManager::loadFeed(const QString feedurl) const { - m_feeds[feedurl] = new Feed(feedurl); + QSqlQuery query; + query.prepare(QStringLiteral("SELECT url FROM Feeds WHERE url=:feedurl;")); + query.bindValue(QStringLiteral(":feedurl"), feedurl); + Database::instance().execute(query); + if (!query.next()) { + qWarning() << "Failed to load feed" << feedurl; + } else { + m_feeds[feedurl] = new Feed(feedurl); + } } void DataManager::loadEntry(const QString id) const