Added new table Accounts, which now holds JUST the information about how many of accounts is there.

This commit is contained in:
Martin Rotter 2015-12-02 13:32:19 +01:00
parent bd44be2921
commit aa62b7feaa
6 changed files with 40 additions and 9 deletions

@ -14,7 +14,12 @@ CREATE TABLE IF NOT EXISTS Information (
-- ! -- !
INSERT INTO Information VALUES (1, 'schema_version', '4'); INSERT INTO Information VALUES (1, 'schema_version', '4');
-- ! -- !
INSERT INTO Information (inf_key, inf_value) VALUES ('standard_account_enabled', 1); CREATE TABLE IF NOT EXISTS Accounts (
id INTEGER PRIMARY KEY,
type TEXT NOT NULL
);
-- !
INSERT INTO Accounts (type) VALUES ('std-rss');
-- ! -- !
DROP TABLE IF EXISTS Categories; DROP TABLE IF EXISTS Categories;
-- ! -- !

@ -8,7 +8,12 @@ CREATE TABLE IF NOT EXISTS Information (
-- ! -- !
INSERT INTO Information VALUES (1, 'schema_version', '4'); INSERT INTO Information VALUES (1, 'schema_version', '4');
-- ! -- !
INSERT INTO Information (inf_key, inf_value) VALUES ('standard_account_enabled', 1); CREATE TABLE IF NOT EXISTS Accounts (
id INTEGER PRIMARY KEY,
type TEXT NOT NULL
);
-- !
INSERT INTO Accounts (type) VALUES ('std-rss');
-- ! -- !
DROP TABLE IF EXISTS Categories; DROP TABLE IF EXISTS Categories;
-- ! -- !

@ -1,4 +1,9 @@
INSERT INTO Information (inf_key, inf_value) VALUES ('standard_account_enabled', 1); CREATE TABLE IF NOT EXISTS Accounts (
id INTEGER PRIMARY KEY,
type TEXT NOT NULL
);
-- !
INSERT INTO Accounts (type) VALUES ('std-rss');
-- ! -- !
DROP TABLE IF EXISTS FeedsData; DROP TABLE IF EXISTS FeedsData;
-- ! -- !

@ -1,4 +1,9 @@
INSERT INTO Information (inf_key, inf_value) VALUES ('standard_account_enabled', 1); CREATE TABLE IF NOT EXISTS Accounts (
id INTEGER PRIMARY KEY,
type TEXT NOT NULL
);
-- !
INSERT INTO Accounts (type) VALUES ('std-rss');
-- ! -- !
DROP TABLE IF EXISTS FeedsData; DROP TABLE IF EXISTS FeedsData;
-- ! -- !

@ -64,8 +64,18 @@ ServiceRoot *StandardServiceEntryPoint::createNewRoot() {
QSqlDatabase database = qApp->database()->connection(QSL("StandardServiceEntryPoint"), DatabaseFactory::FromSettings); QSqlDatabase database = qApp->database()->connection(QSL("StandardServiceEntryPoint"), DatabaseFactory::FromSettings);
QSqlQuery query(database); QSqlQuery query(database);
if (query.exec(QSL("UPDATE Information SET inf_value = 1 WHERE inf_key = 'standard_account_enabled';"))) { // First obtain the ID, which can be assigned to this new account.
return new StandardServiceRoot(true); if (!query.exec("SELECT max(id) FROM Accounts;") || !query.next()) {
return NULL;
}
int id_to_assing = query.value(0).toInt() + 1;
if (query.exec(QString("INSERT INTO Accounts (id, type) VALUES (%1, '%2');").arg(QString::number(id_to_assing),
SERVICE_CODE_STD_RSS))) {
StandardServiceRoot *root = new StandardServiceRoot(true);
root->setId(id_to_assing);
return root;
} }
else { else {
return NULL; return NULL;
@ -78,9 +88,10 @@ QList<ServiceRoot*> StandardServiceEntryPoint::initializeSubtree() {
QSqlQuery query(database); QSqlQuery query(database);
QList<ServiceRoot*> roots; QList<ServiceRoot*> roots;
if (query.exec(QSL("SELECT inf_value FROM Information WHERE inf_key = 'standard_account_enabled';"))) { if (query.exec(QString("SELECT id FROM Accounts WHERE type = '%1';").arg(SERVICE_CODE_STD_RSS))) {
if (query.next() && query.value(0).toInt() == 1) { while (query.next()) {
StandardServiceRoot *root = new StandardServiceRoot(true); StandardServiceRoot *root = new StandardServiceRoot(true);
root->setId(query.value(0).toInt());
roots.append(root); roots.append(root);
} }
} }

@ -131,7 +131,7 @@ bool StandardServiceRoot::deleteViaGui() {
} }
// Switch "existence" flag. // Switch "existence" flag.
bool data_removed = QSqlQuery(connection).exec(QSL("UPDATE Information SET inf_value = 0 WHERE inf_key = 'standard_account_enabled';")); bool data_removed = QSqlQuery(connection).exec(QString("DELETE FROM Accounts WHERE id = %1;").arg(QString::number(id())));
if (data_removed) { if (data_removed) {
requestItemRemoval(this); requestItemRemoval(this);