Changeset View
Changeset View
Standalone View
Standalone View
kmymoney/plugins/sql/onlinetasks/sepa/sepastorageplugin.cpp
Show First 20 Lines • Show All 51 Lines • ▼ Show 20 Line(s) | 44 | { | |||
---|---|---|---|---|---|
52 | } | 52 | } | ||
53 | 53 | | |||
54 | int currentVersion = 0; | 54 | int currentVersion = 0; | ||
55 | if (query.next()) | 55 | if (query.next()) | ||
56 | currentVersion = query.value(0).toInt(); | 56 | currentVersion = query.value(0).toInt(); | ||
57 | 57 | | |||
58 | // Create database in it's most recent version if version is 0 | 58 | // Create database in it's most recent version if version is 0 | ||
59 | // (version 0 means the database was not installed) | 59 | // (version 0 means the database was not installed) | ||
60 | if (currentVersion == 0) { | 60 | if (currentVersion <= 1) { | ||
61 | // If the database is recreated the table may be still there. So drop it if needed. No error handling needed | 61 | // If the database is recreated the table may be still there. So drop it if needed. No error handling needed | ||
62 | // as this step is not necessary - only the creation is important. | 62 | // as this step is not necessary - only the creation is important. | ||
63 | if (!query.exec("DROP TABLE IF EXISTS kmmSepaOrders;")) | 63 | if (!query.exec("DROP TABLE IF EXISTS kmmSepaOrders;")) | ||
64 | return false; | 64 | return false; | ||
65 | 65 | | |||
66 | if (!query.exec( | 66 | if (!query.exec( | ||
67 | "CREATE TABLE kmmSepaOrders (" | 67 | "CREATE TABLE kmmSepaOrders (" | ||
68 | " id varchar(32) NOT NULL PRIMARY KEY REFERENCES kmmOnlineJobs( id )," | 68 | " id varchar(32) NOT NULL PRIMARY KEY REFERENCES kmmOnlineJobs( id ) ON UPDATE CASCADE ON DELETE CASCADE," | ||
69 | " originAccount varchar(32) REFERENCES kmmAccounts( id ) ON UPDATE CASCADE ON DELETE SET NULL," | 69 | " originAccount varchar(32) REFERENCES kmmAccounts( id ) ON UPDATE CASCADE ON DELETE SET NULL," | ||
70 | " value text DEFAULT '0'," | 70 | " value text DEFAULT '0'," | ||
71 | " purpose text," | 71 | " purpose text," | ||
72 | " endToEndReference varchar(35)," | 72 | " endToEndReference varchar(35)," | ||
73 | " beneficiaryName varchar(27)," | 73 | " beneficiaryName varchar(27)," | ||
74 | " beneficiaryIban varchar(32)," | 74 | " beneficiaryIban varchar(32)," | ||
75 | " beneficiaryBic char(11)," | 75 | " beneficiaryBic char(11)," | ||
76 | " textKey int," | 76 | " textKey int," | ||
77 | " subTextKey int" | 77 | " subTextKey int" | ||
78 | " );" | 78 | " );" | ||
79 | )) { | 79 | )) { | ||
80 | qWarning("Error while creating table kmmSepaOrders: %s", qPrintable(query.lastError().text())); | 80 | qWarning("Error while creating table kmmSepaOrders: %s", qPrintable(query.lastError().text())); | ||
81 | return false; | 81 | return false; | ||
82 | } | 82 | } | ||
83 | 83 | | |||
84 | query.prepare("DELETE FROM kmmPluginInfo WHERE iid = ?;"); | ||||
85 | query.bindValue(0, iid); | ||||
86 | query.exec(); | ||||
87 | | ||||
84 | query.prepare("INSERT INTO kmmPluginInfo (iid, versionMajor, versionMinor, uninstallQuery) VALUES(?, ?, ?, ?)"); | 88 | query.prepare("INSERT INTO kmmPluginInfo (iid, versionMajor, versionMinor, uninstallQuery) VALUES(?, ?, ?, ?)"); | ||
85 | query.bindValue(0, iid); | 89 | query.bindValue(0, iid); | ||
86 | query.bindValue(1, 1); | 90 | query.bindValue(1, 2); | ||
87 | query.bindValue(2, 0); | 91 | query.bindValue(2, 0); | ||
88 | query.bindValue(3, "DROP TABLE kmmSepaOrders;"); | 92 | query.bindValue(3, "DROP TABLE kmmSepaOrders;"); | ||
89 | if (query.exec()) | 93 | if (query.exec()) | ||
90 | return true; | 94 | return true; | ||
91 | qWarning("Error while inserting kmmPluginInfo for '%s': %s", qPrintable(iid), qPrintable(query.lastError().text())); | 95 | qWarning("Error while inserting kmmPluginInfo for '%s': %s", qPrintable(iid), qPrintable(query.lastError().text())); | ||
92 | return false; | 96 | return false; | ||
93 | } | 97 | } | ||
94 | 98 | | |||
95 | // Check if version is valid with this plugin | 99 | // Check if version is valid with this plugin | ||
96 | switch (currentVersion) { | 100 | switch (currentVersion) { | ||
97 | case 1: return true; | 101 | case 2: return true; | ||
98 | } | 102 | } | ||
99 | 103 | | |||
100 | return false; | 104 | return false; | ||
101 | } | 105 | } | ||
102 | 106 | | |||
103 | #include "sepastorageplugin.moc" | 107 | #include "sepastorageplugin.moc" |