diff --git a/kmymoney/plugins/sql/mymoneystoragesql.cpp b/kmymoney/plugins/sql/mymoneystoragesql.cpp --- a/kmymoney/plugins/sql/mymoneystoragesql.cpp +++ b/kmymoney/plugins/sql/mymoneystoragesql.cpp @@ -252,6 +252,11 @@ d->m_onlineJobs = d->m_payeeIdentifier = 0; d->m_displayStatus = true; try { + if (this->driverName().compare(QLatin1String("QSQLITE")) == 0) { + QSqlQuery query(*this); + query.exec("PRAGMA foreign_keys = ON"); // this is needed for "ON UPDATE" and "ON DELETE" to work + } + MyMoneyDbTransaction t(*this, Q_FUNC_INFO); d->writeInstitutions(); d->writePayees(); diff --git a/kmymoney/plugins/sql/mymoneystoragesql_p.h b/kmymoney/plugins/sql/mymoneystoragesql_p.h --- a/kmymoney/plugins/sql/mymoneystoragesql_p.h +++ b/kmymoney/plugins/sql/mymoneystoragesql_p.h @@ -892,9 +892,6 @@ if (!query.exec("DELETE FROM kmmOnlineJobs;")) throw MYMONEYEXCEPTIONSQL("Clean kmmOnlineJobs table"); - if (!query.exec("DELETE FROM kmmSepaOrders;")) - throw MYMONEYEXCEPTIONSQL("Clean kmmSepaOrders table"); - const QList jobs(m_storage->onlineJobList()); signalProgress(0, jobs.count(), i18n("Inserting online jobs.")); // Create list for onlineJobs which failed and the reason therefor diff --git a/kmymoney/plugins/sql/onlinetasks/sepa/sepastorageplugin.cpp b/kmymoney/plugins/sql/onlinetasks/sepa/sepastorageplugin.cpp --- a/kmymoney/plugins/sql/onlinetasks/sepa/sepastorageplugin.cpp +++ b/kmymoney/plugins/sql/onlinetasks/sepa/sepastorageplugin.cpp @@ -57,7 +57,7 @@ // Create database in it's most recent version if version is 0 // (version 0 means the database was not installed) - if (currentVersion == 0) { + if (currentVersion <= 1) { // If the database is recreated the table may be still there. So drop it if needed. No error handling needed // as this step is not necessary - only the creation is important. if (!query.exec("DROP TABLE IF EXISTS kmmSepaOrders;")) @@ -65,7 +65,7 @@ if (!query.exec( "CREATE TABLE kmmSepaOrders (" - " id varchar(32) NOT NULL PRIMARY KEY REFERENCES kmmOnlineJobs( id )," + " id varchar(32) NOT NULL PRIMARY KEY REFERENCES kmmOnlineJobs( id ) ON UPDATE CASCADE ON DELETE CASCADE," " originAccount varchar(32) REFERENCES kmmAccounts( id ) ON UPDATE CASCADE ON DELETE SET NULL," " value text DEFAULT '0'," " purpose text," @@ -81,9 +81,13 @@ return false; } + query.prepare("DELETE FROM kmmPluginInfo WHERE iid = ?;"); + query.bindValue(0, iid); + query.exec(); + query.prepare("INSERT INTO kmmPluginInfo (iid, versionMajor, versionMinor, uninstallQuery) VALUES(?, ?, ?, ?)"); query.bindValue(0, iid); - query.bindValue(1, 1); + query.bindValue(1, 2); query.bindValue(2, 0); query.bindValue(3, "DROP TABLE kmmSepaOrders;"); if (query.exec()) @@ -94,7 +98,7 @@ // Check if version is valid with this plugin switch (currentVersion) { - case 1: return true; + case 2: return true; } return false;