/[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

revision 213 by william, Sun Mar 17 01:01:10 2013 UTC revision 215 by william, Sun Mar 17 01:14:21 2013 UTC
# Line 22  namespace GBPVRProgramDatabaseFixer Line 22  namespace GBPVRProgramDatabaseFixer
22          List<SQLLITE.IRECORDING_SCHEDULE> Recordings { get; }          List<SQLLITE.IRECORDING_SCHEDULE> Recordings { get; }
23          List<SQLLITE.ICHANNEL> Channels { get; }          List<SQLLITE.ICHANNEL> Channels { get; }
24          IDateTimeRange GetProgramsDateRange(List<SQLLITE.IPROGRAMME> programs);          IDateTimeRange GetProgramsDateRange(List<SQLLITE.IPROGRAMME> programs);
25          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);
26    
27          void RemoveOldGBPVRPrograms(List<SQLLITE.IPROGRAMME> programs);          void RemoveOldGBPVRPrograms(List<SQLLITE.IPROGRAMME> programs);
28          void UpdateGBPVRPrograms(List<SQLLITE.IPROGRAMME> programs);          void UpdateGBPVRPrograms(List<IOldNewProgram> programs);
29    
30      }      }
31      public class SQLLITE : ISQLLITE      public class SQLLITE : ISQLLITE
32      {      {
33          private class OldNewProgram : IOldNewProgram          private class OldNewProgram : IOldNewProgram
34          {          {
35              public OldNewProgram() : this(new PROGRAMME(), new PROGRAMME()) { }              public OldNewProgram() : this(new PROGRAMME()) { }
36                public OldNewProgram(IPROGRAMME _old) : this(_old,_old) {  }
37              public OldNewProgram(IPROGRAMME _old, IPROGRAMME _new) { OldProgram = _old; NewProgram = _new; }              public OldNewProgram(IPROGRAMME _old, IPROGRAMME _new) { OldProgram = _old; NewProgram = _new; }
38    
39              public IPROGRAMME OldProgram { get; private set; }              public IPROGRAMME OldProgram { get; private set; }
# Line 347  namespace GBPVRProgramDatabaseFixer Line 348  namespace GBPVRProgramDatabaseFixer
348              return range;              return range;
349          }          }
350    
351          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)
352          {          {
353              source_invalid = new List<IPROGRAMME>();              source_invalid = new List<IPROGRAMME>();
354              List<IPROGRAMME> source_valid = new List<IPROGRAMME>();              List<IOldNewProgram> source_valid = new List<IOldNewProgram>();
355              gbpvr_programs = gbpvr_programs.OrderBy(s => s.start_time).ToList();              gbpvr_programs = gbpvr_programs.OrderBy(s => s.start_time).ToList();
356              xmltv_programs = xmltv_programs.OrderBy(s => DateTime.Parse(s.Start)).ToList();              xmltv_programs = xmltv_programs.OrderBy(s => DateTime.Parse(s.Start)).ToList();
357              gbpvr_programs.TrimExcess();              gbpvr_programs.TrimExcess();
# Line 411  namespace GBPVRProgramDatabaseFixer Line 412  namespace GBPVRProgramDatabaseFixer
412                              throw new Exception(string.Format("Program oid '{0}' was not properly updated.", updated_program.oid));                              throw new Exception(string.Format("Program oid '{0}' was not properly updated.", updated_program.oid));
413                          }                          }
414                          //source_valid.Add(new OldNewProgram(program, updated_program));                          //source_valid.Add(new OldNewProgram(program, updated_program));
415                          source_valid.Add(updated_program);                          source_valid.Add(new OldNewProgram(program, updated_program));
416                      }                      }
417                      else                      else
418                      {                      {
419                          // data is the same                          // data is the same
420                          //source_valid.Add(new OldNewProgram(program, program));                          //source_valid.Add(new OldNewProgram(program, program));
421                          source_valid.Add(program);                          source_valid.Add(new OldNewProgram(program));
422                      }                      }
423                  }                  }
424                  index++;                  index++;
# Line 869  namespace GBPVRProgramDatabaseFixer Line 870  namespace GBPVRProgramDatabaseFixer
870              st1.Stop();              st1.Stop();
871              gLog.Warn.WriteLine("    operation took: {0:0.00000} seconds overall", st1.Elapsed.TotalSeconds);              gLog.Warn.WriteLine("    operation took: {0:0.00000} seconds overall", st1.Elapsed.TotalSeconds);
872          }          }
873          public void UpdateGBPVRPrograms(List<IPROGRAMME> programs)          public void UpdateGBPVRPrograms(List<IOldNewProgram> programs)
874          {          {
875              int ChunkSize = 1024;              int ChunkSize = 1024;
876              var ChunkList = programs.Chunk<IPROGRAMME>(ChunkSize);              var ChunkList = programs.Chunk<IOldNewProgram>(ChunkSize);
877    
878              double total = programs.Count;              double total = programs.Count;
879              double index = 0;              double index = 0;
# Line 979  namespace GBPVRProgramDatabaseFixer Line 980  namespace GBPVRProgramDatabaseFixer
980              }              }
981              return result;              return result;
982          }          }
983          private bool UpdateProgramEntryDatabase(IEnumerable<IPROGRAMME> list)          private bool UpdateProgramEntryDatabase(IEnumerable<IOldNewProgram> list)
984          {          {
985              bool result = false;              bool result = false;
986              try              try
# Line 1088  namespace GBPVRProgramDatabaseFixer Line 1089  namespace GBPVRProgramDatabaseFixer
1089          }          }
1090          #endregion          #endregion
1091          #region Multi-Update Command Support          #region Multi-Update Command Support
1092          private string BuildGBPVRMultiUpdateCommand(IEnumerable<IPROGRAMME> list)          private string BuildGBPVRMultiUpdateCommand(IEnumerable<IOldNewProgram> list)
1093          {          {
1094              StringBuilder builder = new StringBuilder();              StringBuilder builder = new StringBuilder();
1095              /*              /*
# Line 1100  namespace GBPVRProgramDatabaseFixer Line 1101  namespace GBPVRProgramDatabaseFixer
1101              builder.AppendLine("begin transaction;");              builder.AppendLine("begin transaction;");
1102              foreach (var t in list)              foreach (var t in list)
1103              {              {
1104                  builder.AppendLine(BuildGBPVRSingleInsertCommand(t));                  if (t.OldProgram != t.NewProgram)
1105                    {
1106                        builder.AppendLine(BuildGBPVRSingleUpdateCommand(t.NewProgram));
1107                    }                
1108              }              }
1109              builder.AppendLine("end transaction;");              builder.AppendLine("end transaction;");
1110              return builder.ToString();              return builder.ToString();

Legend:
Removed from v.213  
changed lines
  Added in v.215

  ViewVC Help
Powered by ViewVC 1.1.22