From: gregor herrmann Date: Fri, 22 Jul 2011 15:33:34 +0000 (+0000) Subject: SqlEngine::addRoomToDB: remove event/conference combinations from EVENT_ROOM that... X-Git-Tag: 0.5.2~2 X-Git-Url: https://git.toastfreeware.priv.at/toast/confclerk.git/commitdiff_plain/274f6dc343081d82b762b9baaebed9065e4e0a17 SqlEngine::addRoomToDB: remove event/conference combinations from EVENT_ROOM that are already there. Should avoid duplicates on updates where the room name changes. Hopefully fixes ticket #24. --- diff --git a/src/sql/sqlengine.cpp b/src/sql/sqlengine.cpp index 2d82f7c..b7cc0a1 100644 --- a/src/sql/sqlengine.cpp +++ b/src/sql/sqlengine.cpp @@ -261,6 +261,19 @@ void SqlEngine::addRoomToDB(QHash &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"]);