捕获数据库操作的所有异常

croire 3 years ago
parent 013c6f2fe7
commit 4a3f0d43eb

@ -103,6 +103,8 @@ namespace DownKyi.Core.Storage.Database
{
List<Cover> covers = new List<Cover>();
try
{
dbHelper.ExecuteQuery(sql, reader =>
{
while (reader.Read())
@ -118,6 +120,13 @@ namespace DownKyi.Core.Storage.Database
covers.Add(cover);
}
});
}
catch (Exception e)
{
Utils.Debugging.Console.PrintLine("Query()发生异常: {0}", e);
LogManager.Error($"{tableName}", e);
}
return covers;
}

@ -32,6 +32,8 @@ namespace DownKyi.Core.Storage.Database.Download
/// </summary>
/// <param name="obj"></param>
public void Insert(string uuid, object obj)
{
try
{
// 定义一个流
Stream stream = new MemoryStream();
@ -50,8 +52,6 @@ namespace DownKyi.Core.Storage.Database.Download
//关闭流
stream.Close();
try
{
string sql = $"insert into {tableName}(id, data) values (@id, @data)";
dbHelper.ExecuteNonQuery(sql, new Action<SQLiteParameterCollection>((para) =>
{
@ -85,6 +85,8 @@ namespace DownKyi.Core.Storage.Database.Download
}
public void Update(string uuid, object obj)
{
try
{
// 定义一个流
Stream stream = new MemoryStream();
@ -103,8 +105,6 @@ namespace DownKyi.Core.Storage.Database.Download
//关闭流
stream.Close();
try
{
string sql = $"update {tableName} set data=@data where id glob @id";
dbHelper.ExecuteNonQuery(sql, new Action<SQLiteParameterCollection>((para) =>
{
@ -160,6 +160,8 @@ namespace DownKyi.Core.Storage.Database.Download
{
Dictionary<string, object> objects = new Dictionary<string, object>();
try
{
dbHelper.ExecuteQuery(sql, reader =>
{
while (reader.Read())
@ -176,6 +178,13 @@ namespace DownKyi.Core.Storage.Database.Download
objects.Add((string)reader["id"], obj);
}
});
}
catch (Exception e)
{
Utils.Debugging.Console.PrintLine("Query()发生异常: {0}", e);
LogManager.Error($"{tableName}", e);
}
return objects;
}

@ -90,6 +90,8 @@ namespace DownKyi.Core.Storage.Database
{
List<Header> headers = new List<Header>();
try
{
dbHelper.ExecuteQuery(sql, reader =>
{
while (reader.Read())
@ -104,6 +106,13 @@ namespace DownKyi.Core.Storage.Database
headers.Add(header);
}
});
}
catch (Exception e)
{
Utils.Debugging.Console.PrintLine("Query()发生异常: {0}", e);
LogManager.Error($"{tableName}", e);
}
return headers;
}

Loading…
Cancel
Save