Remove authors when removing feed

This commit is contained in:
Tobias Fella 2020-04-20 02:06:21 +02:00
parent 593d221c9c
commit 276d8ba831
3 changed files with 7 additions and 2 deletions

View File

@ -55,7 +55,7 @@ bool Database::migrateTo1() {
QSqlQuery query(QSqlDatabase::database()); 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 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 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;"))); TRUE_OR_RETURN(execute(QStringLiteral("PRAGMA user_version = 1;")));
return true; return true;
} }

View File

@ -87,6 +87,10 @@ bool FeedListModel::feedExists(QString url) {
void FeedListModel::removeFeed(int index) void FeedListModel::removeFeed(int index)
{ {
QSqlQuery query; 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.prepare(QStringLiteral("DELETE FROM Entries WHERE feed=:feed;"));
query.bindValue(QStringLiteral(":feed"), data(createIndex(index, 0), 1).toString()); query.bindValue(QStringLiteral(":feed"), data(createIndex(index, 0), 1).toString());
Database::instance().execute(query); Database::instance().execute(query);

View File

@ -74,7 +74,8 @@ void Fetcher::fetch(QUrl url)
query.bindValue(QStringLiteral(":content"), entry->description()); query.bindValue(QStringLiteral(":content"), entry->description());
Database::instance().execute(query); Database::instance().execute(query);
for (const auto &author : entry->authors()) { 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(":id"), entry->id());
query.bindValue(QStringLiteral(":name"), author->name()); query.bindValue(QStringLiteral(":name"), author->name());
query.bindValue(QStringLiteral(":uri"), author->uri()); query.bindValue(QStringLiteral(":uri"), author->uri());