Add some try/catch blocks around the sql commands.

This commit is contained in:
Olink 2020-05-25 03:07:54 -04:00
parent 96ad7a5dd8
commit df22a33132

View file

@ -84,6 +84,7 @@ namespace TShockAPI.DB
where WorldId = @0 where WorldId = @0
group by itemId"; group by itemId";
try {
using (var reader = database.QueryReader(sql, Main.worldID)) using (var reader = database.QueryReader(sql, Main.worldID))
{ {
while (reader.Read()) while (reader.Read())
@ -93,7 +94,11 @@ namespace TShockAPI.DB
sacrificedItems[itemId] = amount; sacrificedItems[itemId] = amount;
} }
} }
}
catch (Exception ex)
{
TShock.Log.Error(ex.ToString());
}
return sacrificedItems; return sacrificedItems;
} }
@ -111,7 +116,17 @@ namespace TShockAPI.DB
itemsSacrificed[itemId] = 0; itemsSacrificed[itemId] = 0;
var sql = @"insert into Research (WorldId, PlayerId, ItemId, AmountSacrificed, TimeSacrificed) values (@0, @1, @2, @3, @4)"; var sql = @"insert into Research (WorldId, PlayerId, ItemId, AmountSacrificed, TimeSacrificed) values (@0, @1, @2, @3, @4)";
var result = database.Query(sql, Main.worldID, player.Account.ID, itemId, amount, DateTime.Now);
var result = 0;
try
{
result = database.Query(sql, Main.worldID, player.Account.ID, itemId, amount, DateTime.Now);
}
catch (Exception ex)
{
TShock.Log.Error(ex.ToString());
}
if (result == 1) if (result == 1)
{ {
itemsSacrificed[itemId] += amount; itemsSacrificed[itemId] += amount;