SqlEngine::addRoomToDB: remove event/conference combinations from EVENT_ROOM that...
authorgregor herrmann <gregoa@debian.org>
Fri, 22 Jul 2011 15:33:34 +0000 (15:33 +0000)
committergregor herrmann <gregoa@debian.org>
Fri, 22 Jul 2011 15:33:34 +0000 (15:33 +0000)
Should avoid duplicates on updates where the room name changes.
Hopefully fixes ticket #24.

src/sql/sqlengine.cpp

index 2d82f7c..b7cc0a1 100644 (file)
@@ -261,6 +261,19 @@ void SqlEngine::addRoomToDB(QHash<QString,QString> &aRoom)
             aRoom["id"]= query.lastInsertId().toString(); // 'id' is assigned automatically
             //LOG_AUTOTEST(query);
         }
+        // check if event is already there, i.e. room name changed
+        query = QSqlQuery(db);
+        query.prepare("SELECT * FROM EVENT_ROOM WHERE xid_conference=:conference_id AND xid_event=:event_id");
+        query.bindValue(":conference_id", aRoom["conference_id"]);
+        query.bindValue(":event_id", aRoom["event_id"]);
+        if (!query.exec()) qDebug() << "Could not execute SELECT * FROM EVENT_ROOM' query:" << query.lastError();
+        if(query.next()) // event/conference exists --> delete it
+        {
+          query.prepare("DELETE FROM EVENT_ROOM WHERE xid_conference=:conference_id AND xid_event=:event_id");
+          query.bindValue(":conference_id", aRoom["conference_id"]);
+          query.bindValue(":event_id", aRoom["event_id"]);
+          if (!query.exec()) qDebug() << "Could not execute SELECT * FROM EVENT_ROOM' query:" << query.lastError();
+        }
         query = QSqlQuery(db);
         query.prepare("INSERT INTO EVENT_ROOM (xid_conference,xid_event,xid_room) VALUES (:conference_id, :event_id, :room_id)");
         query.bindValue(":conference_id", aRoom["conference_id"]);