Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using NUtility;
- using NShared;
- using System;
- using System.Collections.Generic;
- using System.Data.Common;
- namespace NextTool
- {
- internal class TrimDescription
- {
- public TrimDescription()
- {
- string select = "SELECT oid, description, channel_oid FROM EPG_EVENT;";
- DbCommand command = Globals.con.CreateCommand();
- command.CommandText = select;
- DbDataReader reader = command.ExecuteReader();
- List<int> oids = new List<int>();
- while (reader.Read())
- {
- if (reader[1].ToString().Contains('\0'))
- {
- oids.Add(int.Parse(reader["oid"].ToString()));
- }
- }
- reader.Close();
- if (oids.Count > 0)
- {
- Logger.Error($"Found {oids.Count} bad records");
- Console.WriteLine($"Found {oids.Count} bad records");
- command.CommandText = "BEGIN TRANSACTION";
- command.ExecuteNonQuery();
- List<EPGEvent> events = new List<EPGEvent>();
- foreach (int oid in oids)
- {
- EPGEvent epgEvent = EPGEvent.LoadByOID(oid);
- if (epgEvent.Description.EndsWith('\0'))
- {
- bool fixedDescription = false;
- do
- {
- char a = epgEvent.Description[epgEvent.Description.Length - 1];
- if (a == 0 || a > 127)
- {
- epgEvent.Description = epgEvent.Description.TrimEnd(a);
- if (epgEvent.Description.Length == 0)
- fixedDescription = true;
- }
- else
- fixedDescription = true;
- } while (!fixedDescription && epgEvent.Description.Length > 0 );
- if (fixedDescription)
- {
- Logger.Debug($"Updating {oid} {epgEvent.Title}|{epgEvent.Description}");
- events.Add(epgEvent);
- command.CommandText = $"DELETE FROM EPG_EVENT where oid = '{oid}';";
- command.ExecuteNonQuery();
- }
- else
- Logger.Error($"Could not trim {oid} {epgEvent.Title} {epgEvent.Description}");
- }
- else
- Logger.Error($"Embedded NULL {oid} {epgEvent.Title} {epgEvent.Description}");
- }
- command.CommandText = "COMMIT";
- command.ExecuteNonQuery();
- if (events.Count > 0)
- {
- EPGManager manager = EPGManager.GetInstance();
- manager.AddEPGEvents(events);
- Logger.Error($"Updated {events.Count} records");
- Console.WriteLine($"Updated {events.Count} records");
- }
- DatabaseHelper.GetInstance().FreeConnection(Globals.con);
- return;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement