ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/xmltv_parser/trunk/GBPVRProgramDatabaseFixer/SQLLITE.cs
(Generate patch)

Comparing trunk/GBPVRProgramDatabaseFixer/SQLLITE.cs (file contents):
Revision 158 by william, Thu Mar 14 19:36:01 2013 UTC vs.
Revision 159 by william, Thu Mar 14 20:26:05 2013 UTC

# Line 12 | Line 12 | namespace GBPVRProgramDatabaseFixer
12      internal class SQLLITE
13      {
14          #region DATABASE DEFINITIONS
15 +
16 +        public interface ICHANNEL
17 +        {
18 +            Int64 oid { get; }
19 +            String name { get; }
20 +            String channelID { get; }
21 +            Int64 channel_number { get; }
22 +            String favourite_channel { get; }
23 +            String display_name { get; }
24 +        }
25 +        private class CHANNEL : ICHANNEL
26 +        {
27 +            public CHANNEL()
28 +            {
29 +                BaseDatabaseDefinition<CHANNEL>.CreateDefault(this);
30 +            }
31 +            //public RECORDING_SCHEDULE(SQLiteDataReader r, int index) { BaseDatabaseDefinition<RECORDING_SCHEDULE>.Create(this, r, index); }
32 +
33 +            public static void Create(ref CHANNEL instance, SQLiteDataReader r, int index)
34 +            {
35 +                BaseDatabaseDefinition<CHANNEL>.Create(ref instance, r, index);
36 +            }
37 +            #region ICHANNEL members
38 +            public Int64 oid { get; set; }
39 +            public String name { get; set; }
40 +            public String channelID { get; set; }
41 +            public Int64 channel_number { get; set; }
42 +            public String favourite_channel { get; set; }
43 +            public String display_name { get; set; }
44 +            #endregion
45 +        }
46          public interface IRECORDING_SCHEDULE
47          {
48              Int64 oid { get; }
# Line 182 | Line 213 | namespace GBPVRProgramDatabaseFixer
213          {
214              public const string RECORDING_SCHEDULE = "RECORDING_SCHEDULE";
215              public const string PROGRAMME = "PROGRAMME";
216 +            public const string CHANNEL = "CHANNEL";
217          }
218  
219          //public SQLLite() { }
# Line 196 | Line 228 | namespace GBPVRProgramDatabaseFixer
228                  return;
229              }
230              ConnectionTest();
231 +            ReadChannelData();
232              ReadRecodringScheduleData();
233              ReadProgrammeData();
234              OnCreatedInstance(this, new EventArgs());
# Line 214 | Line 247 | namespace GBPVRProgramDatabaseFixer
247          private string Database;
248          public List<IPROGRAMME> Programs { get; private set; }
249          public List<IRECORDING_SCHEDULE> Recordings { get; private set; }
250 +        public List<ICHANNEL> Channels { get; private set; }
251          #endregion
252  
253  
# Line 233 | Line 267 | namespace GBPVRProgramDatabaseFixer
267                  using (SQLiteConnection con = CreateConnection())
268                  {
269                      con.Open();
270 <                    string command_text = string.Format("select * from {0};", TABLES.PROGRAMME);
270 >                    string command_text = string.Format("select * from {0};", TABLES.CHANNEL);
271                      gLog.Verbose.Debug.WriteLine("Executing Command: '{0}'", command_text);
272                      using (SQLiteCommand cmd = new SQLiteCommand(command_text, con))
273                      {
# Line 288 | Line 322 | namespace GBPVRProgramDatabaseFixer
322                  return false;
323              }
324          }
325 <
325 >        private void ReadChannelData()
326 >        {
327 >            try
328 >            {
329 >                List<ICHANNEL> channels = new List<ICHANNEL>();
330 >                using (SQLiteConnection con = CreateConnection())
331 >                {
332 >                    con.Open();
333 >                    string command_text = string.Format("select * from {0};", TABLES.CHANNEL);
334 >                    gLog.Verbose.Debug.WriteLine("Executing Command: '{0}'", command_text);
335 >                    using (SQLiteCommand cmd = new SQLiteCommand(command_text, con))
336 >                    {
337 >                        using (SQLiteDataReader r = cmd.ExecuteReader())
338 >                        {
339 >                            if (!r.HasRows)
340 >                            {
341 >                                gLog.Warn.WriteLine("Query: '{0}' returned no rows.", cmd.CommandText);
342 >                            }
343 >                            else
344 >                            {
345 >                                while (r.Read())
346 >                                {
347 >                                    CHANNEL channel = new CHANNEL();
348 >                                    for (int i = 0; i < r.FieldCount; i++)
349 >                                    {
350 >                                        CHANNEL.Create(ref channel, r, i);
351 >                                    }
352 >                                    channels.Add(channel);
353 >                                }
354 >                            }
355 >                        }
356 >                    }
357 >                    con.Clone();
358 >                }
359 >                this.Channels = channels;
360 >            }
361 >            catch (Exception ex)
362 >            {
363 >                gLog.Error.WriteLine(ex.ToString());
364 >            }
365 >        }
366          private void ReadProgrammeData()
367          {
368              try
# Line 357 | Line 431 | namespace GBPVRProgramDatabaseFixer
431                                      {
432                                          RECORDING_SCHEDULE.Create(ref recording, r, i);
433                                      }
360
434                                      recordings.Add(recording);
435                                  }
436                              }
# Line 372 | Line 445 | namespace GBPVRProgramDatabaseFixer
445                  gLog.Error.WriteLine(ex.ToString());
446              }
447          }
448 +
449      }
450   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines