[mythtv] [PATCH] Support for Scheduling changes in DVB EPG

Stuart Auchterlonie stuarta at squashedfrog.net
Fri Apr 8 14:34:36 UTC 2005


On Fri, Apr 08, 2005 at 01:31:13PM +0100, Stuart Auchterlonie wrote:
> 
> Hi all,
> 
> I've sat down and come up with a proper patch that adds support for
> scheduling changes that show up in the EPG.
> 

I've updated the patch and this takes care of programs that have
moved forward in time. Plus simplified the sql a bit by only 
checking the chanid once rather than 3 times.


Stuart

-------------- next part --------------
Index: libs/libmythtv/siscan.cpp
===================================================================
--- libs/libmythtv/siscan.cpp	(revision 4)
+++ libs/libmythtv/siscan.cpp	(working copy)
@@ -928,6 +928,7 @@
 void SIScan::AddEvents()
 {
     MSqlQuery query(MSqlQuery::InitCon());
+    MSqlQuery query2(MSqlQuery::InitCon());
     QString theQuery;
     int counter = 0;
 
@@ -997,25 +998,67 @@
 #endif
         for (e = events->begin() ; e != events->end() ; ++e)
         {
+            query.prepare("select starttime, endtime, title "
+                        "from program where chanid=:CHANID and "
+                        "(((starttime>=:STARTTIME and starttime<:ENDTIME) "
+                        "or (endtime>:STARTTIME and endtime<=:ENDTIME)) "
+                        "and not (starttime=:STARTTIME "
+                        "and endtime=:ENDTIME and title=:TITLE))");
+            query.bindValue(":CHANID",ChanID);
+            query.bindValue(":STARTTIME",(*e).StartTime.toString(QString("yyyy-MM-dd hh:mm:00")));
+            query.bindValue(":ENDTIME",(*e).EndTime.toString(QString("yyyy-MM-dd hh:mm:00")));
+            query.bindValue(":TITLE",(*e).Event_Name.utf8());
 
-            query.prepare("select * from  program where chanid=:CHANID and "
-                      "starttime=:STARTTIME and title=:TITLE;");
+            if(!query.exec())
+                MythContext::DBError("Checking Rescheduled Event", query);
+            if (!query.isActive())
+                MythContext::DBError("Checking Rescheduled Event", query);
+
+            for (int i=query.first(); i<query.size();i++, query.next()) 
+            // New guide data overriding existing
+            // Possibly more than one conflict
+            {
+                VERBOSE(VB_GENERAL, QString("Schedule Change on Channel %1:\n"
+                    "Old Program: S=%2 E=%3 %4\n"
+                    "New Program: S=%5 E=%6 %7") 
+                    .arg(ChanID)
+                    .arg(query.value(0).toString())
+                    .arg(query.value(1).toString())
+                    .arg(query.value(2).toString())
+                    .arg((*e).StartTime.toString(QString("yyyy-MM-dd hh:mm:00")))
+                    .arg((*e).EndTime.toString(QString("yyyy-MM-dd hh:mm:00")))
+                    .arg((*e).Event_Name.utf8()));
+                // Delete old EPG record.
+                query2.prepare("delete from program where chanid=:CHANID and "
+                    "starttime=:STARTTIME and endtime=:ENDTIME and title=:TITLE");
+                query2.bindValue(":CHANID",ChanID);
+                query2.bindValue(":STARTTIME",query.value(0).toString());
+                query2.bindValue(":ENDTIME",query.value(1).toString());
+                query2.bindValue(":TITLE",query.value(2).toString());
+                if(!query2.exec())
+                    MythContext::DBError("Deleting Rescheduled Event", query2);
+                if (!query2.isActive())
+                    MythContext::DBError("Deleting Rescheduled Event", query2);
+            }
+
+            query.prepare("select 1 from program where chanid=:CHANID and "
+                        "starttime=:STARTTIME and endtime=:ENDTIME and "
+                        "title=:TITLE");
             query.bindValue(":CHANID",ChanID);
             query.bindValue(":STARTTIME",(*e).StartTime.toString(QString("yyyy-MM-dd hh:mm:00")));
             query.bindValue(":ENDTIME",(*e).EndTime.toString(QString("yyyy-MM-dd hh:mm:00")));
             query.bindValue(":TITLE",(*e).Event_Name.utf8());
 
             if(!query.exec())
-                MythContext::DBError("Checking Event", query);
-
+                MythContext::DBError("Checking If Event Exists", query);
             if (!query.isActive())
-                MythContext::DBError("Checking Event", query);
+                MythContext::DBError("Checking If Event Exists", query);
 
             if (query.size() <= 0)
             {
-                 counter++;
+                counter++;
 
-                 query.prepare("INSERT INTO program (chanid,starttime,endtime,"
+                query.prepare("REPLACE INTO program (chanid,starttime,endtime,"
                           "title,description,subtitle,category,"
                           "stereo,closecaptioned,hdtv,airdate,originalairdate)"
                           "VALUES (:CHANID,:STARTTIME,:ENDTIME,:TITLE,:DESCRIPTION,:SUBTITLE,:CATEGORY,:STEREO,:CLOSECAPTIONED,:HDTV,:AIRDATE,:ORIGINALAIRDATE);");
@@ -1036,7 +1079,7 @@
                     MythContext::DBError("Adding Event", query);
 
                 if (!query.isActive())
-                   MythContext::DBError("Adding Event", query);
+                    MythContext::DBError("Adding Event", query);
 
                 for(QValueList<Person>::Iterator it=(*e).Credits.begin();it!=(*e).Credits.end();it++)
                 {
@@ -1063,7 +1106,6 @@
                     if (!query.isActive())
                         MythContext::DBError("Adding Event (Credits)", query);
                 }
-
             }
         }
 
@@ -1079,4 +1121,3 @@
     }
     pthread_mutex_unlock(&events_lock);
 }
-


More information about the mythtv-dev mailing list