Reworked attributes & code for Feeds and Categories too. Now each category and feed knows which account it belongs to.
This commit is contained in:
parent
057a5da197
commit
d5c7e3b8f4
8 changed files with 45 additions and 39 deletions
|
@ -34,10 +34,13 @@ DROP TABLE IF EXISTS Categories;
|
|||
CREATE TABLE IF NOT EXISTS Categories (
|
||||
id INTEGER AUTO_INCREMENT PRIMARY KEY,
|
||||
parent_id INTEGER NOT NULL,
|
||||
title VARCHAR(100) NOT NULL UNIQUE CHECK (title != ''),
|
||||
title VARCHAR(100) NOT NULL CHECK (title != ''),
|
||||
description TEXT,
|
||||
date_created BIGINT NOT NULL CHECK (date_created != 0),
|
||||
icon BLOB
|
||||
icon BLOB,
|
||||
account_id INTEGER NOT NULL,
|
||||
|
||||
FOREIGN KEY (account_id) REFERENCES Accounts (id)
|
||||
);
|
||||
-- !
|
||||
DROP TABLE IF EXISTS Feeds;
|
||||
|
@ -50,13 +53,16 @@ CREATE TABLE IF NOT EXISTS Feeds (
|
|||
icon BLOB,
|
||||
category INTEGER NOT NULL CHECK (category >= -1),
|
||||
encoding TEXT NOT NULL CHECK (encoding != ''),
|
||||
url VARCHAR(100) NOT NULL UNIQUE CHECK (url != ''),
|
||||
url VARCHAR(100) NOT NULL CHECK (url != ''),
|
||||
protected INTEGER(1) NOT NULL CHECK (protected >= 0 AND protected <= 1),
|
||||
username TEXT,
|
||||
password TEXT,
|
||||
update_type INTEGER(1) NOT NULL CHECK (update_type >= 0),
|
||||
update_interval INTEGER NOT NULL DEFAULT 15 CHECK (update_interval >= 5),
|
||||
type INTEGER NOT NULL CHECK (type >= 0)
|
||||
type INTEGER NOT NULL CHECK (type >= 0),
|
||||
account_id INTEGER NOT NULL,
|
||||
|
||||
FOREIGN KEY (account_id) REFERENCES Accounts (id)
|
||||
);
|
||||
-- !
|
||||
DROP TABLE IF EXISTS Messages;
|
||||
|
|
|
@ -29,10 +29,13 @@ DROP TABLE IF EXISTS Categories;
|
|||
CREATE TABLE IF NOT EXISTS Categories (
|
||||
id INTEGER PRIMARY KEY,
|
||||
parent_id INTEGER NOT NULL,
|
||||
title TEXT NOT NULL UNIQUE CHECK (title != ''),
|
||||
title TEXT NOT NULL CHECK (title != ''),
|
||||
description TEXT,
|
||||
date_created INTEGER NOT NULL CHECK (date_created != 0),
|
||||
icon BLOB
|
||||
icon BLOB,
|
||||
account_id INTEGER NOT NULL,
|
||||
|
||||
FOREIGN KEY (account_id) REFERENCES Accounts (id)
|
||||
);
|
||||
-- !
|
||||
DROP TABLE IF EXISTS Feeds;
|
||||
|
@ -45,13 +48,16 @@ CREATE TABLE IF NOT EXISTS Feeds (
|
|||
icon BLOB,
|
||||
category INTEGER NOT NULL CHECK (category >= -1),
|
||||
encoding TEXT NOT NULL CHECK (encoding != ''),
|
||||
url TEXT NOT NULL UNIQUE CHECK (url != ''),
|
||||
url TEXT NOT NULL CHECK (url != ''),
|
||||
protected INTEGER(1) NOT NULL CHECK (protected >= 0 AND protected <= 1),
|
||||
username TEXT,
|
||||
password TEXT,
|
||||
update_type INTEGER(1) NOT NULL CHECK (update_type >= 0),
|
||||
update_interval INTEGER NOT NULL CHECK (update_interval >= 5) DEFAULT 15,
|
||||
type INTEGER NOT NULL CHECK (type >= 0)
|
||||
type INTEGER NOT NULL CHECK (type >= 0),
|
||||
account_id INTEGER NOT NULL,
|
||||
|
||||
FOREIGN KEY (account_id) REFERENCES Accounts (id)
|
||||
);
|
||||
-- !
|
||||
DROP TABLE IF EXISTS Messages;
|
||||
|
|
|
@ -19,5 +19,10 @@ CREATE TABLE IF NOT EXISTS TtRssAccounts (
|
|||
ALTER TABLE Messages
|
||||
ADD COLUMN account_id INTEGER NOT NULL DEFAULT (1);
|
||||
-- !
|
||||
|
||||
ALTER TABLE Feeds
|
||||
ADD COLUMN account_id INTEGER NOT NULL DEFAULT (1);
|
||||
-- !
|
||||
ALTER TABLE Categories
|
||||
ADD COLUMN account_id INTEGER NOT NULL DEFAULT (1);
|
||||
-- !
|
||||
UPDATE Information SET inf_value = '4' WHERE inf_key = 'schema_version';
|
|
@ -19,4 +19,10 @@ CREATE TABLE IF NOT EXISTS TtRssAccounts (
|
|||
ALTER TABLE Messages
|
||||
ADD COLUMN account_id INTEGER NOT NULL DEFAULT (1);
|
||||
-- !
|
||||
ALTER TABLE Feeds
|
||||
ADD COLUMN account_id INTEGER NOT NULL DEFAULT (1);
|
||||
-- !
|
||||
ALTER TABLE Categories
|
||||
ADD COLUMN account_id INTEGER NOT NULL DEFAULT (1);
|
||||
-- !
|
||||
UPDATE Information SET inf_value = '4' WHERE inf_key = 'schema_version';
|
|
@ -208,6 +208,7 @@
|
|||
#define FDS_DB_UPDATE_TYPE_INDEX 11
|
||||
#define FDS_DB_UPDATE_INTERVAL_INDEX 12
|
||||
#define FDS_DB_TYPE_INDEX 13
|
||||
#define FDS_DB_ACCOUNT_ID_INDEX 14
|
||||
|
||||
// Indexes of columns for feed models.
|
||||
#define FDS_MODEL_TITLE_INDEX 0
|
||||
|
|
|
@ -174,13 +174,14 @@ bool StandardCategory::addItself(RootItem *parent) {
|
|||
|
||||
query_add.setForwardOnly(true);
|
||||
query_add.prepare("INSERT INTO Categories "
|
||||
"(parent_id, title, description, date_created, icon) "
|
||||
"VALUES (:parent_id, :title, :description, :date_created, :icon);");
|
||||
"(parent_id, title, description, date_created, icon, account_id) "
|
||||
"VALUES (:parent_id, :title, :description, :date_created, :icon, :account_id);");
|
||||
query_add.bindValue(QSL(":parent_id"), parent->id());
|
||||
query_add.bindValue(QSL(":title"), title());
|
||||
query_add.bindValue(QSL(":description"), description());
|
||||
query_add.bindValue(QSL(":date_created"), creationDate().toMSecsSinceEpoch());
|
||||
query_add.bindValue(QSL(":icon"), qApp->icons()->toByteArray(icon()));
|
||||
query_add.bindValue(QSL(":account_id"), parent->getParentServiceRoot()->accountId());
|
||||
|
||||
if (!query_add.exec()) {
|
||||
qDebug("Failed to add category to database: %s.", qPrintable(query_add.lastError().text()));
|
||||
|
@ -189,18 +190,7 @@ bool StandardCategory::addItself(RootItem *parent) {
|
|||
return false;
|
||||
}
|
||||
|
||||
query_add.prepare(QSL("SELECT id FROM Categories WHERE title = :title;"));
|
||||
query_add.bindValue(QSL(":title"), title());
|
||||
|
||||
if (query_add.exec() && query_add.next()) {
|
||||
// New category was added, fetch is primary id
|
||||
// from the database.
|
||||
setId(query_add.value(0).toInt());
|
||||
}
|
||||
else {
|
||||
// Something failed.
|
||||
return false;
|
||||
}
|
||||
setId(query_add.lastInsertId().toInt());
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -519,9 +519,8 @@ bool StandardFeed::removeItself() {
|
|||
query_remove.setForwardOnly(true);
|
||||
|
||||
// Remove all messages from this standard feed.
|
||||
query_remove.prepare(QSL("DELETE FROM Messages WHERE feed = :feed AND account_id = :account_id;"));
|
||||
query_remove.prepare(QSL("DELETE FROM Messages WHERE feed = :feed;"));
|
||||
query_remove.bindValue(QSL(":feed"), id());
|
||||
query_remove.bindValue(QSL(":account_id"), const_cast<StandardFeed*>(this)->serviceRoot()->accountId());
|
||||
|
||||
if (!query_remove.exec()) {
|
||||
return false;
|
||||
|
@ -541,8 +540,8 @@ bool StandardFeed::addItself(RootItem *parent) {
|
|||
|
||||
query_add_feed.setForwardOnly(true);
|
||||
query_add_feed.prepare("INSERT INTO Feeds "
|
||||
"(title, description, date_created, icon, category, encoding, url, protected, username, password, update_type, update_interval, type) "
|
||||
"VALUES (:title, :description, :date_created, :icon, :category, :encoding, :url, :protected, :username, :password, :update_type, :update_interval, :type);");
|
||||
"(title, description, date_created, icon, category, encoding, url, protected, username, password, update_type, update_interval, type, account_id) "
|
||||
"VALUES (:title, :description, :date_created, :icon, :category, :encoding, :url, :protected, :username, :password, :update_type, :update_interval, :type, :account_id);");
|
||||
query_add_feed.bindValue(QSL(":title"), title());
|
||||
query_add_feed.bindValue(QSL(":description"), description());
|
||||
query_add_feed.bindValue(QSL(":date_created"), creationDate().toMSecsSinceEpoch());
|
||||
|
@ -552,6 +551,7 @@ bool StandardFeed::addItself(RootItem *parent) {
|
|||
query_add_feed.bindValue(QSL(":url"), url());
|
||||
query_add_feed.bindValue(QSL(":protected"), (int) passwordProtected());
|
||||
query_add_feed.bindValue(QSL(":username"), username());
|
||||
query_add_feed.bindValue(QSL(":account_id"), parent->getParentServiceRoot()->accountId());
|
||||
|
||||
if (password().isEmpty()) {
|
||||
query_add_feed.bindValue(QSL(":password"), password());
|
||||
|
@ -571,16 +571,8 @@ bool StandardFeed::addItself(RootItem *parent) {
|
|||
return false;
|
||||
}
|
||||
|
||||
query_add_feed.prepare(QSL("SELECT id FROM Feeds WHERE url = :url;"));
|
||||
query_add_feed.bindValue(QSL(":url"), url());
|
||||
if (query_add_feed.exec() && query_add_feed.next()) {
|
||||
// New feed was added, fetch is primary id from the database.
|
||||
setId(query_add_feed.value(0).toInt());
|
||||
}
|
||||
else {
|
||||
// Something failed.
|
||||
return false;
|
||||
}
|
||||
// New feed was added, fetch is primary id from the database.
|
||||
setId(query_add_feed.lastInsertId().toInt());
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -119,12 +119,12 @@ bool StandardServiceRoot::deleteViaGui() {
|
|||
// TODO: todo
|
||||
|
||||
// Remove all feeds.
|
||||
if (!QSqlQuery(connection).exec(QSL("DELETE FROM Feeds;"))) {
|
||||
if (!QSqlQuery(connection).exec(QSL("DELETE FROM Feeds WHERE account_id = %1;").arg(accountId()))) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Remove all categories.
|
||||
if (!QSqlQuery(connection).exec(QSL("DELETE FROM Categories;"))) {
|
||||
if (!QSqlQuery(connection).exec(QSL("DELETE FROM Categories WHERE account_id = %1;").arg(accountId()))) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue