From 276d8ba831fc3ec2c6e4fc595d7257f9f8ef1193 Mon Sep 17 00:00:00 2001 From: Tobias Fella Date: Mon, 20 Apr 2020 02:06:21 +0200 Subject: [PATCH] Remove authors when removing feed --- src/database.cpp | 2 +- src/feedListModel.cpp | 4 ++++ src/fetcher.cpp | 3 ++- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/database.cpp b/src/database.cpp index 5d7b9166..164d1fad 100644 --- a/src/database.cpp +++ b/src/database.cpp @@ -55,7 +55,7 @@ bool Database::migrateTo1() { QSqlQuery query(QSqlDatabase::database()); TRUE_OR_RETURN(execute(QStringLiteral("CREATE TABLE IF NOT EXISTS Feeds (name TEXT, url TEXT, image TEXT);"))); TRUE_OR_RETURN(execute(QStringLiteral("CREATE TABLE IF NOT EXISTS Entries (feed TEXT, id TEXT UNIQUE, title TEXT, content TEXT, created INTEGER, updated INTEGER);"))); - TRUE_OR_RETURN(execute(QStringLiteral("CREATE TABLE IF NOT EXISTS Authors (id TEXT, name TEXT, uri TEXT, email TEXT);"))); + TRUE_OR_RETURN(execute(QStringLiteral("CREATE TABLE IF NOT EXISTS Authors (feed TEXT, id TEXT, name TEXT, uri TEXT, email TEXT);"))); TRUE_OR_RETURN(execute(QStringLiteral("PRAGMA user_version = 1;"))); return true; } diff --git a/src/feedListModel.cpp b/src/feedListModel.cpp index 0dba60c6..6d318119 100644 --- a/src/feedListModel.cpp +++ b/src/feedListModel.cpp @@ -87,6 +87,10 @@ bool FeedListModel::feedExists(QString url) { void FeedListModel::removeFeed(int index) { QSqlQuery query; + query.prepare(QStringLiteral("DELETE FROM Authors WHERE feed=:feed;")); + query.bindValue(QStringLiteral(":feed"), data(createIndex(index, 0), 1).toString()); + Database::instance().execute(query); + query.prepare(QStringLiteral("DELETE FROM Entries WHERE feed=:feed;")); query.bindValue(QStringLiteral(":feed"), data(createIndex(index, 0), 1).toString()); Database::instance().execute(query); diff --git a/src/fetcher.cpp b/src/fetcher.cpp index 797399e4..84320134 100644 --- a/src/fetcher.cpp +++ b/src/fetcher.cpp @@ -74,7 +74,8 @@ void Fetcher::fetch(QUrl url) query.bindValue(QStringLiteral(":content"), entry->description()); Database::instance().execute(query); for (const auto &author : entry->authors()) { - query.prepare(QStringLiteral("INSERT INTO Authors VALUES(:id, :name, :uri, :email);")); + query.prepare(QStringLiteral("INSERT INTO Authors VALUES(:feed, :id, :name, :uri, :email);")); + query.bindValue(QStringLiteral(":feed"), url.toString()); query.bindValue(QStringLiteral(":id"), entry->id()); query.bindValue(QStringLiteral(":name"), author->name()); query.bindValue(QStringLiteral(":uri"), author->uri());