diff --git a/resources/misc/db_init_mysql.sql b/resources/misc/db_init_mysql.sql index 97a908f91..83a36e479 100644 --- a/resources/misc/db_init_mysql.sql +++ b/resources/misc/db_init_mysql.sql @@ -14,7 +14,12 @@ CREATE TABLE IF NOT EXISTS Information ( -- ! 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; -- ! diff --git a/resources/misc/db_init_sqlite.sql b/resources/misc/db_init_sqlite.sql index ecf85b2a1..2f55e3e7e 100644 --- a/resources/misc/db_init_sqlite.sql +++ b/resources/misc/db_init_sqlite.sql @@ -8,7 +8,12 @@ CREATE TABLE IF NOT EXISTS Information ( -- ! 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; -- ! diff --git a/resources/misc/db_update_mysql_3_4.sql b/resources/misc/db_update_mysql_3_4.sql index f6e1cb49e..68720dbd6 100644 --- a/resources/misc/db_update_mysql_3_4.sql +++ b/resources/misc/db_update_mysql_3_4.sql @@ -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; -- ! diff --git a/resources/misc/db_update_sqlite_3_4.sql b/resources/misc/db_update_sqlite_3_4.sql index f6e1cb49e..68720dbd6 100644 --- a/resources/misc/db_update_sqlite_3_4.sql +++ b/resources/misc/db_update_sqlite_3_4.sql @@ -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; -- ! diff --git a/src/services/standard/standardserviceentrypoint.cpp b/src/services/standard/standardserviceentrypoint.cpp index 97fa542d1..8d979815c 100755 --- a/src/services/standard/standardserviceentrypoint.cpp +++ b/src/services/standard/standardserviceentrypoint.cpp @@ -64,8 +64,18 @@ ServiceRoot *StandardServiceEntryPoint::createNewRoot() { QSqlDatabase database = qApp->database()->connection(QSL("StandardServiceEntryPoint"), DatabaseFactory::FromSettings); QSqlQuery query(database); - if (query.exec(QSL("UPDATE Information SET inf_value = 1 WHERE inf_key = 'standard_account_enabled';"))) { - return new StandardServiceRoot(true); + // First obtain the ID, which can be assigned to this new account. + 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 { return NULL; @@ -78,9 +88,10 @@ QList StandardServiceEntryPoint::initializeSubtree() { QSqlQuery query(database); QList roots; - if (query.exec(QSL("SELECT inf_value FROM Information WHERE inf_key = 'standard_account_enabled';"))) { - if (query.next() && query.value(0).toInt() == 1) { + if (query.exec(QString("SELECT id FROM Accounts WHERE type = '%1';").arg(SERVICE_CODE_STD_RSS))) { + while (query.next()) { StandardServiceRoot *root = new StandardServiceRoot(true); + root->setId(query.value(0).toInt()); roots.append(root); } } diff --git a/src/services/standard/standardserviceroot.cpp b/src/services/standard/standardserviceroot.cpp index 58ebfc167..623178b6c 100755 --- a/src/services/standard/standardserviceroot.cpp +++ b/src/services/standard/standardserviceroot.cpp @@ -131,7 +131,7 @@ bool StandardServiceRoot::deleteViaGui() { } // 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) { requestItemRemoval(this);