Treating invalid IdentityIds as NULL values
[quassel.git] / src / core / postgresqlstorage.cpp
index 0421224..d65b4ee 100644 (file)
@@ -61,10 +61,18 @@ QString PostgreSqlStorage::description() const {
   return tr("PostgreSQL Turbo Bomber HD!");
 }
 
-QVariantMap PostgreSqlStorage::setupKeys() const {
+QStringList PostgreSqlStorage::setupKeys() const {
+  QStringList keys;
+  keys << "Username"
+       << "Password"
+       << "Hostname"
+       << "Port"
+       << "Database";
+  return keys;
+}
+QVariantMap PostgreSqlStorage::setupDefaults() const {
   QVariantMap map;
   map["Username"] = QVariant(QString("quassel"));
-  map["Password"] = QVariant(QString());
   map["Hostname"] = QVariant(QString("localhost"));
   map["Port"] = QVariant(5432);
   map["Database"] = QVariant(QString("quassel"));
@@ -529,7 +537,7 @@ NetworkId PostgreSqlStorage::createNetwork(UserId user, const NetworkInfo &info)
   }
 
   if(!db.commit()) {
-    qWarning() << "PostgreSqlStorage::updateNetwork(): commiting data failed!";
+    qWarning() << "PostgreSqlStorage::createNetwork(): commiting data failed!";
     qWarning() << " -" << qPrintable(db.lastError().text());
     return NetworkId();
   }
@@ -538,7 +546,7 @@ NetworkId PostgreSqlStorage::createNetwork(UserId user, const NetworkInfo &info)
 
 void PostgreSqlStorage::bindNetworkInfo(QSqlQuery &query, const NetworkInfo &info) {
   query.bindValue(":networkname", info.networkName);
-  query.bindValue(":identityid", info.identity.toInt());
+  query.bindValue(":identityid", info.identity.isValid() ? info.identity.toInt() : QVariant());
   query.bindValue(":encodingcodec", QString(info.codecForEncoding));
   query.bindValue(":decodingcodec", QString(info.codecForDecoding));
   query.bindValue(":servercodec", QString(info.codecForServer));
@@ -991,7 +999,7 @@ bool PostgreSqlStorage::removeBuffer(const UserId &user, const BufferId &bufferI
     return false;
   case 1:
     db.commit();
-    return false;
+    return true;
   default:
     // there was more then one buffer deleted...
     qWarning() << "PostgreSqlStorage::removeBuffer(): Userid" << user << "BufferId" << "caused deletion of" << numRows << "Buffers! Rolling back transaction...";
@@ -1027,7 +1035,7 @@ bool PostgreSqlStorage::renameBuffer(const UserId &user, const BufferId &bufferI
     return false;
   case 1:
     db.commit();
-    return false;
+    return true;
   default:
     // there was more then one buffer deleted...
     qWarning() << "PostgreSqlStorage::renameBuffer(): Userid" << user << "BufferId" << "affected" << numRows << "Buffers! Rolling back transaction...";
@@ -1490,6 +1498,7 @@ bool PostgreSqlMigrationWriter::prepareQuery(MigrationObject mo) {
     query = queryString("migrate_write_sender");
     break;
   case Identity:
+    _validIdentities.clear();
     query = queryString("migrate_write_identity");
     break;
   case IdentityNick:
@@ -1532,6 +1541,7 @@ bool PostgreSqlMigrationWriter::writeMo(const SenderMO &sender) {
 
 //bool PostgreSqlMigrationWriter::writeIdentity(const IdentityMO &identity) {
 bool PostgreSqlMigrationWriter::writeMo(const IdentityMO &identity) {
+  _validIdentities << identity.id.toInt();
   bindValue(0, identity.id.toInt());
   bindValue(1, identity.userid.toInt());
   bindValue(2, identity.identityname);
@@ -1569,7 +1579,10 @@ bool PostgreSqlMigrationWriter::writeMo(const NetworkMO &network) {
   bindValue(0, network.networkid.toInt());
   bindValue(1, network.userid.toInt());
   bindValue(2, network.networkname);
-  bindValue(3, network.identityid.toInt());
+  if(_validIdentities.contains(network.identityid.toInt()))
+    bindValue(3, network.identityid.toInt());
+  else
+    bindValue(3, QVariant());
   bindValue(4, network.encodingcodec);
   bindValue(5, network.decodingcodec);
   bindValue(6, network.servercodec);
@@ -1649,6 +1662,7 @@ bool PostgreSqlMigrationWriter::postProcess() {
   QSqlDatabase db = logDb();
   QList<Sequence> sequences;
   sequences << Sequence("backlog", "messageid")
+           << Sequence("buffer", "bufferid")
            << Sequence("identity", "identityid")
            << Sequence("identity_nick", "nickid")
            << Sequence("ircserver", "serverid")