/[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/16 18:55:49	185
+++ trunk/GBPVRProgramDatabaseFixer/SQLLITE.cs	2013/03/17 04:02:57	228
@@ -11,6 +11,10 @@
 using libxmltv.Core;
 namespace GBPVRProgramDatabaseFixer
 {
+    public interface ICloneable<T>
+    {
+        T Clone();
+    }
     public interface IOldNewProgram
     {
         SQLLITE.IPROGRAMME OldProgram { get; }
@@ -32,7 +36,8 @@
     {
         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; }
@@ -44,56 +49,7 @@
         }
 
         #region DATABASE DEFINITIONS
-
-        public interface ICHANNEL
-        {
-            Int64 oid { get; }
-            String name { get; }
-            String channelID { get; }
-            Int64 channel_number { get; }
-            String favourite_channel { get; }
-            String display_name { get; }
-        }
-        private class CHANNEL : ICHANNEL
-        {
-            public CHANNEL()
-            {
-                BaseDatabaseDefinition<CHANNEL>.CreateDefault(this);
-            }
-            //public RECORDING_SCHEDULE(SQLiteDataReader r, int index) { BaseDatabaseDefinition<RECORDING_SCHEDULE>.Create(this, r, index); }
-
-            public static void Create(ref CHANNEL instance, SQLiteDataReader r, int index)
-            {
-                BaseDatabaseDefinition<CHANNEL>.Create(ref instance, r, index);
-            }
-            #region ICHANNEL members
-            public Int64 oid { get; set; }
-            public String name { get; set; }
-            public String channelID { get; set; }
-            public Int64 channel_number { get; set; }
-            public String favourite_channel { get; set; }
-            public String display_name { get; set; }
-            #endregion
-        }
-        public interface IRECORDING_SCHEDULE
-        {
-            Int64 oid { get; }
-            Int64 programme_oid { get; }
-            Int64 capture_source_oid { get; }
-            Int16 status { get; }
-            String filename { get; }
-            Int64 recording_type { get; }
-            Int64 recording_group { get; }
-            DateTime manual_start_time { get; }
-            DateTime manual_end_time { get; }
-            Int64 manual_channel_oid { get; }
-            Int64 quality_level { get; }
-            Int64 pre_pad_minutes { get; }
-            Int64 post_pad_minutes { get; }
-            Int32 priority { get; }
-            String conversion_profile { get; }
-        }
-
+        #region BaseDatabaseDefinition
         private static class BaseDatabaseDefinition<T>
         {
             public static void CreateDefault(T instance)
@@ -129,6 +85,23 @@
                     throw ex;
                 }
             }
+            public static void Create(T source, ref T destination)
+            {
+                Type t = source.GetType();
+                var props = t.GetProperties();
+                foreach (var prop in props)
+                {
+                    try
+                    {
+                        object value = prop.GetValue(source, null);
+                        prop.SetValue(destination, value, null);
+                    }
+                    catch (Exception ex)
+                    {
+                        throw ex;
+                    }
+                }
+            }
             public static void Create(ref T instance, SQLiteDataReader r, int index)
             {
                 string field_name = r.GetName(index);
@@ -172,8 +145,67 @@
 
             }
         }
+        #endregion
+        public interface ICHANNEL : ICloneable<ICHANNEL>
+        {
+            Int64 oid { get; }
+            String name { get; }
+            String channelID { get; }
+            Int64 channel_number { get; }
+            String favourite_channel { get; }
+            String display_name { get; }
+        }
+        private class CHANNEL : ICHANNEL, ICloneable<CHANNEL>
+        {
+            public CHANNEL()
+            {
+                BaseDatabaseDefinition<CHANNEL>.CreateDefault(this);
+            }
+            //public RECORDING_SCHEDULE(SQLiteDataReader r, int index) { BaseDatabaseDefinition<RECORDING_SCHEDULE>.Create(this, r, index); }
 
-        private class RECORDING_SCHEDULE : IRECORDING_SCHEDULE
+            public static void Create(ref CHANNEL instance, SQLiteDataReader r, int index)
+            {
+                BaseDatabaseDefinition<CHANNEL>.Create(ref instance, r, index);
+            }
+            #region ICHANNEL members
+            public Int64 oid { get; set; }
+            public String name { get; set; }
+            public String channelID { get; set; }
+            public Int64 channel_number { get; set; }
+            public String favourite_channel { get; set; }
+            public String display_name { get; set; }
+            #endregion
+
+            ICHANNEL ICloneable<ICHANNEL>.Clone()
+            {
+                return Clone();
+            }
+            public CHANNEL Clone()
+            {
+                CHANNEL p = new CHANNEL();
+                BaseDatabaseDefinition<CHANNEL>.Create(this, ref p);
+                return p;
+            }
+        }
+        public interface IRECORDING_SCHEDULE : ICloneable<IRECORDING_SCHEDULE>
+        {
+            Int64 oid { get; }
+            Int64 programme_oid { get; }
+            Int64 capture_source_oid { get; }
+            Int16 status { get; }
+            String filename { get; }
+            Int64 recording_type { get; }
+            Int64 recording_group { get; }
+            DateTime manual_start_time { get; }
+            DateTime manual_end_time { get; }
+            Int64 manual_channel_oid { get; }
+            Int64 quality_level { get; }
+            Int64 pre_pad_minutes { get; }
+            Int64 post_pad_minutes { get; }
+            Int32 priority { get; }
+            String conversion_profile { get; }
+        }
+        private class RECORDING_SCHEDULE : IRECORDING_SCHEDULE, ICloneable<RECORDING_SCHEDULE>
         {
             public RECORDING_SCHEDULE()
             {
@@ -185,7 +217,16 @@
             {
                 BaseDatabaseDefinition<RECORDING_SCHEDULE>.Create(ref instance, r, index);
             }
-
+            IRECORDING_SCHEDULE ICloneable<IRECORDING_SCHEDULE>.Clone()
+            {
+                return Clone();
+            }
+            public RECORDING_SCHEDULE Clone()
+            {
+                RECORDING_SCHEDULE p = new RECORDING_SCHEDULE();
+                BaseDatabaseDefinition<RECORDING_SCHEDULE>.Create(this, ref p);
+                return p;
+            }
             #region IRECORDING_SCHEDULE members
             public Int64 oid { get; set; }
             public Int64 programme_oid { get; set; }
@@ -203,9 +244,10 @@
             public Int32 priority { get; set; }
             public String conversion_profile { get; set; }
             #endregion
-        }
 
-        public interface IPROGRAMME : IEquatable<IPROGRAMME>
+            
+        }
+        public interface IPROGRAMME : IEquatable<IPROGRAMME>, ICloneable<IPROGRAMME>
         {
             Int64 oid { get; set; }
             String name { get; set; }
@@ -220,8 +262,19 @@
             string ToString();
             IProgramDefinition AsXMLTVProgramDefinition(ISQLLITE sqllite);
         }
-        private class PROGRAMME : IPROGRAMME
+        private class PROGRAMME : IPROGRAMME, ICloneable<PROGRAMME>
         {
+           
+            IPROGRAMME ICloneable<IPROGRAMME>.Clone()
+            {
+                return Clone();
+            }
+            public PROGRAMME Clone()
+            {
+                PROGRAMME p = new PROGRAMME();
+                BaseDatabaseDefinition<PROGRAMME>.Create(this, ref p);
+                return p; 
+            }
             public PROGRAMME()
             {
                 BaseDatabaseDefinition<PROGRAMME>.CreateDefault(this);
@@ -255,6 +308,7 @@
                 definition.Stop = this.end_time.ToDateTimeString();
                 definition.SubTitle = this.sub_title;
                 definition.Title = this.name;
+                definition.Rating = this.rating;
                 return definition;
             }
             #endregion
@@ -292,6 +346,14 @@
             {
                 return this.ToString().GetHashCode();
             }
+
+
+
+
+
+
+
+          
         }
         #endregion
         private static class TABLES
@@ -300,7 +362,7 @@
             public const string PROGRAMME = "PROGRAMME";
             public const string CHANNEL = "CHANNEL";
         }
-
+        private string DATABASE_BACKUP_FILE = string.Empty;
         //public SQLLite() { }
         protected SQLLITE(string database, EventHandler<EventArgs> OnInstanceCreated)
         {
@@ -377,7 +439,7 @@
                     if (!xmltv_entry.Equals(program_xmltv_entry))
                     {
                         // data is different
-                        var updated_program = program;
+                        var updated_program = program.Clone();
 
                         if (program_xmltv_entry.Title != xmltv_entry.Title)
                         {
@@ -405,22 +467,33 @@
                             updated_program.description = xmltv_entry.Description;
                         }
 
+                        if(program_xmltv_entry.Rating != xmltv_entry.Rating)
+                        {
+                            gLog.Verbose.Warn.WriteLine("    Program oid: '{0}' - replacing rating", updated_program.oid);
+                            updated_program.rating = xmltv_entry.Rating;
+                        }
+
                         var updated_xmltv_entry = updated_program.AsXMLTVProgramDefinition(this);
                         if (!xmltv_entry.Equals(updated_xmltv_entry))
                         {
                             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(new OldNewProgram(program, updated_program));
                     }
                     else
                     {
                         // data is the same
-                        source_valid.Add(new OldNewProgram(program, program));
+                        //source_valid.Add(new OldNewProgram(program, program));
+                        source_valid.Add(new OldNewProgram(program));
                     }
                 }
                 index++;
             }
-
+            gLog.Info.WriteLine("Total XMLTV Programs: 0x{0:x8}", xmltv_programs.Count);
+            gLog.Info.WriteLine("Total Valid GB-PVR Programs: 0x{0:x8}", source_valid.Count);
+            gLog.Info.WriteLine("Total Invalid GB-PVR Programs: 0x{0:x8}", source_invalid.Count);
+            gLog.Info.WriteLine("Total GB-PVR Programs (Valid+Invalid): 0x{0:x8} == 0x{1:x8}", source_valid.Count + source_invalid.Count, gbpvr_programs.Count);
             #region old-code
             //List<OldNewProgram> source_update = new List<OldNewProgram>();
             ////if (range == null)
@@ -653,6 +726,7 @@
                 gLog.Info.WriteLine("\tDestination: {0}", backup_file);
 
                 System.IO.File.Copy(this.Database, backup_file);
+                DATABASE_BACKUP_FILE = backup_file;
                 return true;
             }
             catch (Exception ex)
@@ -816,49 +890,95 @@
         }
 
         public void RemoveOldGBPVRPrograms(List<SQLLITE.IPROGRAMME> programs)
-        {
-            gLog.Info.WriteLine("Removing {0} old gbpvr programs.", programs.Count);
+        {            
+            gLog.Info.WriteLine("Removing {0} gbpvr programs.", programs.Count);
+            int ChunkSize = 1024;
+            var ChunkList = programs.Chunk<IPROGRAMME>(ChunkSize);
             double total = programs.Count;
             double index = 0;
             double progress = 0;
-            foreach (var program in programs)
+            Stopwatch st1 = new Stopwatch();
+            st1.Start();
+            foreach (var p in ChunkList)
             {
                 progress = 100.0 * (index / total);
-                gLog.ReportProgress(this, new ReportProgressEventArgs((int)progress, string.Format("Removing GBPVR Programs: {0:00}%", (int)progress)));
-                if (!RemoveProgramDatabaseEntry(program))
+                if (!RemoveProgramDatabaseEntry(p))
                 {
-                    gLog.Error.WriteLine("Failed to remove program with oid: {0}", program.oid);
+                    gLog.Error.WriteLine("Failed to remove one or more program(s)");
                 }
-                index++;
+                gLog.ReportProgress(this, new ReportProgressEventArgs((int)progress, string.Format("Removing old gbpvr programs ({0} of {1}) {2:00}%", index, total, (int)progress)));
+                index += (double)p.Count(); 
             }
+            gLog.ReportProgress(this, new ReportProgressEventArgs((int)progress, string.Format("Removing old gbpvr programs ({0} of {1}) {2:00}%", index, total, (int)progress)));
+            st1.Stop();
+            gLog.Warn.WriteLine("    operation took: {0:0.00000} seconds overall", st1.Elapsed.TotalSeconds);
         }
         public void UpdateGBPVRPrograms(List<IOldNewProgram> programs)
         {
             gLog.Info.WriteLine("Updating {0} gbpvr programs.", programs.Count);
+            int ChunkSize = 4096;
+            var ChunkList = programs.Chunk<IOldNewProgram>(ChunkSize);
+
             double total = programs.Count;
             double index = 0;
             double progress = 0;
-            foreach (var program in programs)
+            Stopwatch st1 = new Stopwatch();
+            st1.Start();
+            foreach (var p in ChunkList)
             {
                 progress = 100.0 * (index / total);
-                gLog.ReportProgress(this, new ReportProgressEventArgs((int)progress, string.Format("Updating GBPVR Programs: {0:00}%", (int)progress)));
-                if (program.NewProgram.Equals(program.OldProgram))
+                if (!UpdateProgramEntryDatabase(p))
                 {
-                    // program does not need to be updated
-                    continue;
+                    gLog.Error.WriteLine("Failed to update one or more program(s)");
                 }
-                else
+                gLog.ReportProgress(this, new ReportProgressEventArgs((int)progress, string.Format("Updating gbpvr programs ({0} of {1}) {2:00}%", index, total, (int)progress)));
+                index += (double)p.Count();                
+            }
+            gLog.ReportProgress(this, new ReportProgressEventArgs((int)progress, string.Format("Updating gbpvr programs ({0} of {1}) {2:00}%", index, total, (int)progress)));
+            st1.Stop();
+            gLog.Warn.WriteLine("    operation took: {0:0.00000} seconds overall", st1.Elapsed.TotalSeconds);
+        }
+
+        private bool RemoveAllProgramDatabaseEntries()
+        {
+            bool result = false;
+            try
+            {
+                using (SQLiteConnection con = CreateConnection())
                 {
-                    if (!UpdateProgramDatabaseEntry(program.NewProgram))
+                    try
+                    {
+                        //gLog.Verbose.Info.WriteLine("Removing old program with oid: '{0}'", old_program.oid);
+                        con.Open();
+                        string command_text = string.Format(@"DELETE FROM [{0}];", TABLES.PROGRAMME);
+                        //gLog.Verbose.Debug.WriteLine("Executing Command: '{0}'", command_text);
+                        using (SQLiteCommand cmd = new SQLiteCommand(command_text, con))
+                        {
+                            //cmd.Parameters.Add(new SQLiteParameter("oid", old_program.oid));
+                            int rowsupdated = cmd.ExecuteNonQuery();
+                            //gLog.Verbose.Info.WriteLine("Updated '{0}' rows", rowsupdated);
+                        }
+                        result = true;
+                    }
+                    catch (SQLiteException ex)
                     {
-                        gLog.Error.WriteLine("Failed to update program with oid: {0}", program.NewProgram.oid);
+                        gLog.Error.WriteLine(ex.ToString());
+                        result = false;
+                    }
+                    finally
+                    {
+                        con.Close();
                     }
                 }
-                index++;
             }
+            catch (Exception ex)
+            {
+                gLog.Error.WriteLine(ex.ToString());
+                result = false;
+            }
+            return result;
         }
-
-        private bool RemoveProgramDatabaseEntry(IPROGRAMME old_program)
+        private bool RemoveProgramDatabaseEntry(IEnumerable<IPROGRAMME> list)
         {
             bool result = false;
             try
@@ -867,16 +987,18 @@
                 {
                     try
                     {
-                        //gLog.Verbose.Info.WriteLine("Removing old program with oid: '{0}'", old_program.oid);
+                        //gLog.Verbose.Info.WriteLine("Updating old program with oid: '{0}'", new_program.oid);
                         con.Open();
-                        string command_text = string.Format(@"DELETE FROM [{0}] WHERE [oid] = @oid;", TABLES.PROGRAMME);
+                        //string command_text = string.Format(@"UPDATE [{0}] SET [name]=@name,[sub_title]=@subtitle, WHERE [OID] = @oid", TABLES.PROGRAMME);
+                        string command_text = string.Empty;
+                        command_text = BuildGBPVRMultiDeleteCommand(list);
                         //gLog.Verbose.Debug.WriteLine("Executing Command: '{0}'", command_text);
                         using (SQLiteCommand cmd = new SQLiteCommand(command_text, con))
                         {
-                            cmd.Parameters.Add(new SQLiteParameter("oid", old_program.oid));
                             int rowsupdated = cmd.ExecuteNonQuery();
                             //gLog.Verbose.Info.WriteLine("Updated '{0}' rows", rowsupdated);
                         }
+
                         result = true;
                     }
                     catch (SQLiteException ex)
@@ -897,7 +1019,7 @@
             }
             return result;
         }
-        private bool UpdateProgramDatabaseEntry(IPROGRAMME new_program)
+        private bool UpdateProgramEntryDatabase(IEnumerable<IOldNewProgram> list)
         {
             bool result = false;
             try
@@ -910,31 +1032,10 @@
                         con.Open();
                         //string command_text = string.Format(@"UPDATE [{0}] SET [name]=@name,[sub_title]=@subtitle, WHERE [OID] = @oid", TABLES.PROGRAMME);
                         string command_text = string.Empty;
-                        StringBuilder builder = new StringBuilder();
-                        builder.AppendLine(string.Format("UPDATE [{0}]", TABLES.PROGRAMME));
-                        builder.Append("SET ");
-                        builder.AppendFormat("[name]=@name,");
-                        builder.AppendFormat("[sub_title]=@sub_title,");
-                        builder.AppendFormat("[description]=@description,");
-                        builder.AppendFormat("[start_time]=@start_time,");
-                        builder.AppendFormat("[end_time]=@end_time,");
-                        builder.AppendFormat("[channel_oid]=@channel_oid,");
-                        builder.AppendFormat("[unique_identifier]=@unique_identifier,");
-                        builder.AppendFormat("[rating]=@rating");
-                        builder.AppendLine(" WHERE [oid] = @oid");
-                        command_text = builder.ToString();
+                        command_text = BuildGBPVRMultiUpdateCommand(list);
                         //gLog.Verbose.Debug.WriteLine("Executing Command: '{0}'", command_text);
                         using (SQLiteCommand cmd = new SQLiteCommand(command_text, con))
                         {
-                            cmd.Parameters.Add(new SQLiteParameter("oid", new_program.oid));
-                            cmd.Parameters.Add(new SQLiteParameter("name", new_program.name));
-                            cmd.Parameters.Add(new SQLiteParameter("sub_title", new_program.sub_title));
-                            cmd.Parameters.Add(new SQLiteParameter("description", new_program.description));
-                            cmd.Parameters.Add(new SQLiteParameter("start_time", new_program.start_time));
-                            cmd.Parameters.Add(new SQLiteParameter("end_time", new_program.end_time));
-                            cmd.Parameters.Add(new SQLiteParameter("channel_oid", new_program.channel_oid));
-                            cmd.Parameters.Add(new SQLiteParameter("unique_identifier", new_program.unique_identifier));
-                            cmd.Parameters.Add(new SQLiteParameter("rating", new_program.rating));
                             int rowsupdated = cmd.ExecuteNonQuery();
                             //gLog.Verbose.Info.WriteLine("Updated '{0}' rows", rowsupdated);
                         }
@@ -959,5 +1060,146 @@
             }
             return result;
         }
+        private bool InsertProgramEntryDatabase(IEnumerable<IPROGRAMME> list)
+        {
+            bool result = false;
+            try
+            {
+                using (SQLiteConnection con = CreateConnection())
+                {
+                    try
+                    {
+                        //gLog.Verbose.Info.WriteLine("Updating old program with oid: '{0}'", new_program.oid);
+                        con.Open();
+                        //string command_text = string.Format(@"UPDATE [{0}] SET [name]=@name,[sub_title]=@subtitle, WHERE [OID] = @oid", TABLES.PROGRAMME);
+                        string command_text = string.Empty;
+                        command_text = BuildGBPVRMultiInsertCommand(list);
+                        //gLog.Verbose.Debug.WriteLine("Executing Command: '{0}'", command_text);
+                        using (SQLiteCommand cmd = new SQLiteCommand(command_text, con))
+                        {                          
+                            int rowsupdated = cmd.ExecuteNonQuery();
+                            //gLog.Verbose.Info.WriteLine("Updated '{0}' rows", rowsupdated);
+                        }
+
+                        result = true;
+                    }
+                    catch (SQLiteException ex)
+                    {
+                        gLog.Error.WriteLine(ex.ToString());
+                        result = false;
+                    }
+                    finally
+                    {
+                        con.Close();
+                    }
+                }
+            }
+            catch (Exception ex)
+            {
+                gLog.Error.WriteLine(ex.ToString());
+                result = false;
+            }
+            return result;
+        }
+
+        #region Multi-Delete Command Support
+        private string BuildGBPVRMultiDeleteCommand(IEnumerable<IPROGRAMME> list)
+        {
+            StringBuilder builder = new StringBuilder();
+            /*
+                insert into table1 (field1,field2) values (value1,value2);
+                insert into table1 (field1,field2) values (value1,value2);
+                insert into table1 (field1,field2) values (value1,value2);
+                insert into table1 (field1,field2) values (value1,value2)
+             */
+            builder.AppendLine("begin transaction;");
+            foreach (var t in list)
+            {
+                builder.AppendLine(BuildGBPVRSingleDeleteCommand(t));
+            }
+            builder.AppendLine("end transaction;");
+            return builder.ToString();
+        }
+        private string BuildGBPVRSingleDeleteCommand(IPROGRAMME program)
+        {
+            StringBuilder builder = new StringBuilder();
+            builder.AppendFormat("delete from {0} where oid={1};", TABLES.PROGRAMME, program.oid);
+            return builder.ToString();
+        }
+        #endregion
+        #region Multi-Update Command Support
+        private string BuildGBPVRMultiUpdateCommand(IEnumerable<IOldNewProgram> list)
+        {
+            StringBuilder builder = new StringBuilder();
+            /*
+                insert into table1 (field1,field2) values (value1,value2);
+                insert into table1 (field1,field2) values (value1,value2);
+                insert into table1 (field1,field2) values (value1,value2);
+                insert into table1 (field1,field2) values (value1,value2)
+             */
+            builder.AppendLine("begin transaction;");
+            foreach (var t in list)
+            {
+                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();
+        }
+        private string BuildGBPVRSingleUpdateCommand(IPROGRAMME program)
+        {
+            StringBuilder builder = new StringBuilder();
+            builder.AppendFormat("update {0} SET ", TABLES.PROGRAMME);
+            builder.AppendFormat("name=\"{0}\", ", program.name);
+            builder.AppendFormat("sub_title=\"{0}\", ", program.sub_title);
+            builder.AppendFormat("description=\"{0}\", ", program.description);
+            builder.AppendFormat("start_time='{0}', ", program.start_time.ToString("yyyy-MM-dd HH:mm:ss.fffffff"));
+            builder.AppendFormat("end_time='{0}', ", program.end_time.ToString("yyyy-MM-dd HH:mm:ss.fffffff"));
+            builder.AppendFormat("channel_oid={0}, ", program.channel_oid);
+            builder.AppendFormat("unique_identifier=\"{0}\", ", program.unique_identifier);
+            builder.AppendFormat("rating=\"{0}\" ", program.rating);
+            builder.AppendFormat("where oid={0};", program.oid);
+            return builder.ToString();
+        }
+        #endregion
+        #region Multi-Insert Command Support
+        private string BuildGBPVRMultiInsertCommand(IEnumerable<IPROGRAMME> list)
+        {
+            StringBuilder builder = new StringBuilder();
+            /*
+                insert into table1 (field1,field2) values (value1,value2);
+                insert into table1 (field1,field2) values (value1,value2);
+                insert into table1 (field1,field2) values (value1,value2);
+                insert into table1 (field1,field2) values (value1,value2)
+             */
+            builder.AppendLine("begin transaction;");
+            foreach (var t in list)
+            {
+                builder.AppendLine(BuildGBPVRSingleInsertCommand(t));
+            }
+            builder.AppendLine("end transaction;");
+            return builder.ToString();
+        }
+        
+        private string BuildGBPVRSingleInsertCommand(IPROGRAMME program)
+        {
+            StringBuilder builder = new StringBuilder();
+            builder.AppendFormat("insert into {0} (oid,name,sub_title,description,start_time,end_time,channel_oid,unique_identifier,rating) values (", TABLES.PROGRAMME);
+            builder.AppendFormat("{0},",program.oid);
+            builder.AppendFormat("\"{0}\",", program.name);
+            builder.AppendFormat("\"{0}\",", program.sub_title);
+            builder.AppendFormat("\"{0}\",", program.description);
+            builder.AppendFormat("'{0}',", program.start_time.ToString("yyyy/MM/dd HH:mm:ss.fffffff"));
+            builder.AppendFormat("'{0}',", program.end_time.ToString("yyyy/MM/dd HH:mm:ss.fffffff"));
+            builder.AppendFormat("{0},", program.channel_oid);
+            builder.AppendFormat("\"{0}\",", program.unique_identifier);
+            builder.AppendFormat("\"{0}\");", program.rating);
+            return builder.ToString();
+        }
+        #endregion
+
     }
 }

 

  ViewVC Help
Powered by ViewVC 1.1.22