Repair damanged SQLite databases by re-indexing

This commit is contained in:
hbeham
2013-11-24 13:30:20 +01:00
parent 728f9b3e5f
commit 2ec5cffe11
4 changed files with 31 additions and 14 deletions

View File

@@ -24,7 +24,7 @@ namespace ChanSort.Loader.Panasonic
private CypherMode cypherMode; private CypherMode cypherMode;
private byte[] fileHeader = new byte[0]; private byte[] fileHeader = new byte[0];
private int dbSizeOffset; private int dbSizeOffset;
private bool littleEndianByteOrder = false; private bool littleEndianByteOrder;
private string charEncoding; private string charEncoding;
enum CypherMode enum CypherMode
@@ -331,9 +331,10 @@ namespace ChanSort.Loader.Panasonic
using (var conn = new SQLiteConnection(channelConnString)) using (var conn = new SQLiteConnection(channelConnString))
{ {
conn.Open(); conn.Open();
InitCharacterEncoding(conn);
using (var cmd = conn.CreateCommand()) using (var cmd = conn.CreateCommand())
{ {
RepairCorruptedDatabaseImage(cmd);
InitCharacterEncoding(cmd);
this.ReadChannels(cmd); this.ReadChannels(cmd);
} }
} }
@@ -481,13 +482,18 @@ namespace ChanSort.Loader.Panasonic
#endregion #endregion
#region InitCharacterEncoding() #region InitCharacterEncoding()
private void InitCharacterEncoding(SQLiteConnection conn) private void InitCharacterEncoding(SQLiteCommand cmd)
{ {
using (var cmd = conn.CreateCommand()) cmd.CommandText = "PRAGMA encoding";
{ this.charEncoding = cmd.ExecuteScalar() as string;
cmd.CommandText = "PRAGMA encoding"; }
this.charEncoding = cmd.ExecuteScalar() as string; #endregion
}
#region RepairCorruptedDatabaseImage()
private void RepairCorruptedDatabaseImage(SQLiteCommand cmd)
{
cmd.CommandText = "REINDEX";
cmd.ExecuteNonQuery();
} }
#endregion #endregion
@@ -572,6 +578,7 @@ order by s.ntype,major_channel
this.WriteChannels(cmd, this.freesatChannels); this.WriteChannels(cmd, this.freesatChannels);
trans.Commit(); trans.Commit();
} }
this.RepairCorruptedDatabaseImage(cmd);
} }
} }

View File

@@ -55,6 +55,7 @@ namespace ChanSort.Loader.Toshiba
conn.Open(); conn.Open();
using (var cmd = conn.CreateCommand()) using (var cmd = conn.CreateCommand())
{ {
this.RepairCorruptedDatabaseImage(cmd);
this.ReadSatellites(cmd); this.ReadSatellites(cmd);
this.ReadTransponders(cmd); this.ReadTransponders(cmd);
} }
@@ -131,6 +132,14 @@ namespace ChanSort.Loader.Toshiba
} }
#endregion #endregion
#region RepairCorruptedDatabaseImage()
private void RepairCorruptedDatabaseImage(SQLiteCommand cmd)
{
cmd.CommandText = "REINDEX";
cmd.ExecuteNonQuery();
}
#endregion
#region ReadSatellites() #region ReadSatellites()
private void ReadSatellites(SQLiteCommand cmd) private void ReadSatellites(SQLiteCommand cmd)
{ {
@@ -302,6 +311,7 @@ namespace ChanSort.Loader.Toshiba
this.WriteChannels(cmd, "EuroSATChanList", this.satRadioChannels); this.WriteChannels(cmd, "EuroSATChanList", this.satRadioChannels);
trans.Commit(); trans.Commit();
} }
this.RepairCorruptedDatabaseImage(cmd);
} }
} }

View File

@@ -25,7 +25,7 @@ namespace ChanSort.Ui
{ {
public partial class MainForm : XtraForm public partial class MainForm : XtraForm
{ {
public const string AppVersion = "v2013-11-23"; public const string AppVersion = "v2013-11-24";
private const int MaxMruEntries = 10; private const int MaxMruEntries = 10;

View File

@@ -1,10 +1,7 @@
Version v2013-11-23 ======================================================= Version v2013-11-24 =======================================================
Changes: Changes:
- Channel lists can now be printed - Load and repair corrupted Panasonic and Toshiba SQLite channel lists
- Fix: Error when saving Toshiba and Panasonic channel list which contained
red proxy entries for missing channels after applying a reference list
- Fix: Modified Panasonic channel names were not written to the file
The complete change log can be found at the end of this document The complete change log can be found at the end of this document
@@ -113,6 +110,9 @@ OTHER DEALINGS IN THE SOFTWARE.
Change log ================================================================ Change log ================================================================
2013-11-24
- Load and repair corrupted Panasonic and Toshiba SQLite channel lists
2013-11-23 2013-11-23
- Channel lists can now be printed - Channel lists can now be printed
- Fix: Error when saving Toshiba and Panasonic channel list which contained - Fix: Error when saving Toshiba and Panasonic channel list which contained