+
+// ONLY NEEDED FOR MIGRATION
+bool SqliteStorage::init(const QVariantMap &settings) {
+ if(!AbstractSqlStorage::init(settings))
+ return false;
+
+ QSqlQuery checkMigratedQuery(logDb());
+ checkMigratedQuery.prepare("SELECT DISTINCT typeOf(password) FROM quasseluser");
+ checkMigratedQuery.exec();
+ if(!watchQuery(&checkMigratedQuery))
+ return false;
+
+ if(!checkMigratedQuery.first())
+ return false;
+
+ QString passType = checkMigratedQuery.value(0).toString().toLower();
+ if(passType == "text")
+ return true; // allready migrated
+
+ Q_ASSERT(passType == "blob");
+
+ QSqlQuery getPasswordsQuery(logDb());
+ getPasswordsQuery.prepare("SELECT userid, password FROM quasseluser");
+ getPasswordsQuery.exec();
+
+ if(!watchQuery(&getPasswordsQuery)) {
+ qWarning() << "unable to migrate to new password format!";
+ return false;
+ }
+
+ QHash<int, QByteArray> passHash;
+ while(getPasswordsQuery.next()) {
+ passHash[getPasswordsQuery.value(0).toInt()] = getPasswordsQuery.value(1).toByteArray();
+ }
+
+ QSqlQuery setPasswordsQuery(logDb());
+ setPasswordsQuery.prepare("UPDATE quasseluser SET password = :password WHERE userid = :userid");
+ foreach(int userId, passHash.keys()) {
+ setPasswordsQuery.bindValue(":password", QString(passHash[userId]));
+ setPasswordsQuery.bindValue(":userid", userId);
+ setPasswordsQuery.exec();
+ watchQuery(&setPasswordsQuery);
+ }
+
+ qDebug() << "successfully migrated passwords!";
+ return true;
+}