Try-catch is the best solution, since people might be using a blank dats.sqlite instead of the prepopulated one

This commit is contained in:
Matt Nadareski
2016-05-10 09:14:10 -07:00
parent b6ba03eabe
commit 188cb047ea

View File

@@ -128,7 +128,7 @@ COMMIT;";
string source = GetSourceFromFileName(Path.GetFileName(file)); string source = GetSourceFromFileName(Path.GetFileName(file));
int sourceid = 0; int sourceid = 0;
Dictionary<string, int> sources = new Dictionary<string, int>(); SortedDictionary<string, int> sources = new SortedDictionary<string, int>();
sources.Add("default", 0); sources.Add("default", 0);
query = "SELECT name, id FROM source"; query = "SELECT name, id FROM source";
using (SqliteCommand sslc = new SqliteCommand(query, dbc)) using (SqliteCommand sslc = new SqliteCommand(query, dbc))
@@ -207,15 +207,29 @@ COMMIT;";
} }
// Otherwise, get the ID // Otherwise, get the ID
else if (source != "" && sourceid == 0 && sources.ContainsKey(source)) else if (source != "" && sourceid == 0 && sources.ContainsKey(source))
{
try
{ {
sourceid = sources[source.ToLowerInvariant()]; sourceid = sources[source.ToLowerInvariant()];
} }
catch
{
sourceid = 0;
}
}
// Otherwise, we should already have an ID // Otherwise, we should already have an ID
} }
else else
{
try
{ {
sourceid = sources[source.ToLowerInvariant()]; sourceid = sources[source.ToLowerInvariant()];
} }
catch
{
sourceid = 0;
}
}
// Add the source and system link to the database // Add the source and system link to the database
string uquery = @"INSERT OR IGNORE INTO datsdata (id, key, value) string uquery = @"INSERT OR IGNORE INTO datsdata (id, key, value)