/[xmltv_parser]/trunk/GBPVRProgramDatabaseFixer/SQLLITE.cs
ViewVC logotype

Diff of /trunk/GBPVRProgramDatabaseFixer/SQLLITE.cs

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

--- trunk/GBPVRProgramDatabaseFixer/SQLLITE.cs	2013/03/17 01:01:10	213
+++ trunk/GBPVRProgramDatabaseFixer/SQLLITE.cs	2013/03/17 01:15:17	216
@@ -22,17 +22,18 @@
         List<SQLLITE.IRECORDING_SCHEDULE> Recordings { get; }
         List<SQLLITE.ICHANNEL> Channels { get; }
         IDateTimeRange GetProgramsDateRange(List<SQLLITE.IPROGRAMME> programs);
-        List<SQLLITE.IPROGRAMME> FixGBPVRProgramsDatabase(List<SQLLITE.IPROGRAMME> gbpvr_programs, List<libxmltv.Interfaces.IProgramDefinition> xmltv_programs, out List<SQLLITE.IPROGRAMME> removed_programs);
+        List<IOldNewProgram> FixGBPVRProgramsDatabase(List<SQLLITE.IPROGRAMME> gbpvr_programs, List<libxmltv.Interfaces.IProgramDefinition> xmltv_programs, out List<SQLLITE.IPROGRAMME> removed_programs);
 
         void RemoveOldGBPVRPrograms(List<SQLLITE.IPROGRAMME> programs);
-        void UpdateGBPVRPrograms(List<SQLLITE.IPROGRAMME> programs);
+        void UpdateGBPVRPrograms(List<IOldNewProgram> programs);
 
     }
     public class SQLLITE : ISQLLITE
     {
         private class OldNewProgram : IOldNewProgram
         {
-            public OldNewProgram() : this(new PROGRAMME(), new PROGRAMME()) { }
+            public OldNewProgram() : this(new PROGRAMME()) { }
+            public OldNewProgram(IPROGRAMME _old) : this(_old,_old) {  }
             public OldNewProgram(IPROGRAMME _old, IPROGRAMME _new) { OldProgram = _old; NewProgram = _new; }
 
             public IPROGRAMME OldProgram { get; private set; }
@@ -347,10 +348,10 @@
             return range;
         }
 
-        public List<SQLLITE.IPROGRAMME> FixGBPVRProgramsDatabase(List<SQLLITE.IPROGRAMME> gbpvr_programs, List<libxmltv.Interfaces.IProgramDefinition> xmltv_programs, out List<SQLLITE.IPROGRAMME> source_invalid)
+        public List<IOldNewProgram> FixGBPVRProgramsDatabase(List<SQLLITE.IPROGRAMME> gbpvr_programs, List<libxmltv.Interfaces.IProgramDefinition> xmltv_programs, out List<SQLLITE.IPROGRAMME> source_invalid)
         {
             source_invalid = new List<IPROGRAMME>();
-            List<IPROGRAMME> source_valid = new List<IPROGRAMME>();
+            List<IOldNewProgram> source_valid = new List<IOldNewProgram>();
             gbpvr_programs = gbpvr_programs.OrderBy(s => s.start_time).ToList();
             xmltv_programs = xmltv_programs.OrderBy(s => DateTime.Parse(s.Start)).ToList();
             gbpvr_programs.TrimExcess();
@@ -411,13 +412,13 @@
                             throw new Exception(string.Format("Program oid '{0}' was not properly updated.", updated_program.oid));
                         }
                         //source_valid.Add(new OldNewProgram(program, updated_program));
-                        source_valid.Add(updated_program);
+                        source_valid.Add(new OldNewProgram(program, updated_program));
                     }
                     else
                     {
                         // data is the same
                         //source_valid.Add(new OldNewProgram(program, program));
-                        source_valid.Add(program);
+                        source_valid.Add(new OldNewProgram(program));
                     }
                 }
                 index++;
@@ -869,10 +870,10 @@
             st1.Stop();
             gLog.Warn.WriteLine("    operation took: {0:0.00000} seconds overall", st1.Elapsed.TotalSeconds);
         }
-        public void UpdateGBPVRPrograms(List<IPROGRAMME> programs)
+        public void UpdateGBPVRPrograms(List<IOldNewProgram> programs)
         {
             int ChunkSize = 1024;
-            var ChunkList = programs.Chunk<IPROGRAMME>(ChunkSize);
+            var ChunkList = programs.Chunk<IOldNewProgram>(ChunkSize);
 
             double total = programs.Count;
             double index = 0;
@@ -979,7 +980,7 @@
             }
             return result;
         }
-        private bool UpdateProgramEntryDatabase(IEnumerable<IPROGRAMME> list)
+        private bool UpdateProgramEntryDatabase(IEnumerable<IOldNewProgram> list)
         {
             bool result = false;
             try
@@ -1088,7 +1089,7 @@
         }
         #endregion
         #region Multi-Update Command Support
-        private string BuildGBPVRMultiUpdateCommand(IEnumerable<IPROGRAMME> list)
+        private string BuildGBPVRMultiUpdateCommand(IEnumerable<IOldNewProgram> list)
         {
             StringBuilder builder = new StringBuilder();
             /*
@@ -1100,7 +1101,11 @@
             builder.AppendLine("begin transaction;");
             foreach (var t in list)
             {
-                builder.AppendLine(BuildGBPVRSingleInsertCommand(t));
+                if (!t.OldProgram.Equals(t.NewProgram))
+                {
+                    // only update the entry if it is different
+                    builder.AppendLine(BuildGBPVRSingleUpdateCommand(t.NewProgram));
+                }                
             }
             builder.AppendLine("end transaction;");
             return builder.ToString();

 

  ViewVC Help
Powered by ViewVC 1.1.22