Fix bug: display_time_shift was lost when conference was reloaded.
authorPhilipp Spitzer <philipp@spitzer.priv.at>
Wed, 18 Aug 2021 19:17:28 +0000 (21:17 +0200)
committerPhilipp Spitzer <philipp@spitzer.priv.at>
Wed, 18 Aug 2021 19:17:28 +0000 (21:17 +0200)
src/sql/schedulexmlparser.cpp
src/sql/sqlengine.cpp
src/sql/sqlengine.h

index 8cddd3d7abb3a446311e3c33a72237df6bc0a93f..64e266dbec34f4ddba26842a636a703a5e20001c 100644 (file)
@@ -84,7 +84,7 @@ void ScheduleXmlParser::parseDataImpl(const QByteArray &aData, const QString& ur
             conference["utc_offset"] = QString();
             conference["display_time_shift"] = QString();
             conference["url"] = url;
-            sqlEngine->addConferenceToDB(conference, conferenceId);
+            sqlEngine->addConferenceToDB(conference, conferenceId, conferenceId != 0);
             conferenceId = conference["id"].toInt();
             conference_title = conference["title"];
             conference_day_change = QTime(0, 0).addSecs(conference["day_change"].toInt());
@@ -192,7 +192,7 @@ void ScheduleXmlParser::parseDataImpl(const QByteArray &aData, const QString& ur
 
         // Re-write conference as utc_offset was not known previously
         if (!conference.value("utc_offset").isEmpty()) {
-            sqlEngine->addConferenceToDB(conference, conferenceId);
+            sqlEngine->addConferenceToDB(conference, conferenceId, conferenceId != 0);
         }
 
     } // schedule element
index 9a5bdb1ca311add9bc3d481da1fc0304357a4577..74c5cd7d3a4926b39f89feb6428e1c2612a22665 100644 (file)
@@ -144,7 +144,7 @@ bool SqlEngine::applySqlFile(const QString sqlFile) {
 }
 
 
-void SqlEngine::addConferenceToDB(QHash<QString,QString> &aConference, int conferenceId) {
+void SqlEngine::addConferenceToDB(QHash<QString,QString> &aConference, int conferenceId, bool omit_display_time_shift) {
     QSqlQuery query(db);
     bool insert = conferenceId <= 0;
     if (insert) { // insert conference
@@ -153,9 +153,11 @@ void SqlEngine::addConferenceToDB(QHash<QString,QString> &aConference, int confe
                         " VALUES (:title,:url,:subtitle,:venue,:city,:start,:end,"
                                                 ":day_change,:timeslot_duration,:utc_offset,:display_time_shift,:active)");
     } else { // update conference
-        query.prepare("UPDATE CONFERENCE set title=:title, url=:url, subtitle=:subtitle, venue=:venue, city=:city, start=:start, end=:end,"
-                                            "day_change=:day_change, timeslot_duration=:timeslot_duration, utc_offset=:utc_offset, display_time_shift=:display_time_shift, active=:active "
-                      "WHERE id=:id");
+        QString update = "UPDATE CONFERENCE set title=:title, url=:url, subtitle=:subtitle, venue=:venue, city=:city, start=:start, end=:end, "
+                         "day_change=:day_change, timeslot_duration=:timeslot_duration, utc_offset=:utc_offset";
+        if (!omit_display_time_shift) update += ", display_time_shift=:display_time_shift";
+        update += ", active=:active WHERE id=:id";
+        query.prepare(update);
     }
     foreach (QString prop_name, (QList<QString>() << "title" << "url" << "subtitle" << "venue" << "city")) {
         query.bindValue(QString(":") + prop_name, aConference[prop_name]);
@@ -168,9 +170,11 @@ void SqlEngine::addConferenceToDB(QHash<QString,QString> &aConference, int confe
     QVariant utc_offset;
     if (!aConference.value("utc_offset").isEmpty()) utc_offset = aConference["utc_offset"].toInt();
     query.bindValue(":utc_offset", utc_offset);
-    QVariant display_time_shift;
-    if (!aConference.value("display_time_shift").isEmpty()) display_time_shift = aConference["display_time_shift"].toInt();
-    query.bindValue(":display_time_shift", display_time_shift);
+    if (!omit_display_time_shift) {
+        QVariant display_time_shift;
+        if (!aConference.value("display_time_shift").isEmpty()) display_time_shift = aConference["display_time_shift"].toInt();
+        query.bindValue(":display_time_shift", display_time_shift);
+    }
     query.bindValue(":active", 1);
     if (!insert) query.bindValue(":id", conferenceId);
     query.exec();
index 0a964bf599c553517cc1503e43dea9901283bb58..85ace9780dc53a96727003b89daced81b7bee878 100644 (file)
@@ -59,8 +59,8 @@ class SqlEngine : public QObject {
         /// Applies an SQL file
         bool applySqlFile(const QString sqlFile);
 
-        // if a conferneceId != 0 is given, the confernce is updated instead of inserted.
-        void addConferenceToDB(QHash<QString,QString> &aConference, int conferenceId);
+        // if a conferenceId != 0 is given, the conference is updated instead of inserted.
+        void addConferenceToDB(QHash<QString,QString> &aConference, int conferenceId, bool omit_display_time_shift = false);
         void addEventToDB(QHash<QString,QString> &aEvent);
         void addPersonToDB(QHash<QString,QString> &aPerson);
         void addLinkToDB(QHash<QString,QString> &aLink);