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.
This commit is contained in:
Bart De Vries 2021-10-01 15:46:17 +02:00
parent c0dc8cee6a
commit e4ee0f19fd
1 changed files with 15 additions and 2 deletions

View File

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