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());