Skip to content

Commit

Permalink
Added more error messages to database actions
Browse files Browse the repository at this point in the history
  • Loading branch information
KarlOfDuty committed Jan 20, 2025
1 parent 5a2904b commit 18de718
Showing 1 changed file with 26 additions and 24 deletions.
50 changes: 26 additions & 24 deletions Database.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ public static long GetNumberOfTickets()
c.Open();
return (long)countTickets.ExecuteScalar();
}
catch (Exception e)
catch (MySqlException e)
{
Logger.Error("Error occured when attempting to count number of open tickets: " + e);
Logger.Error("Error occured when attempting to count number of open tickets.", e);
}

return -1;
Expand All @@ -54,9 +54,9 @@ public static long GetNumberOfClosedTickets()
c.Open();
return (long)countTickets.ExecuteScalar();
}
catch (Exception e)
catch (MySqlException e)
{
Logger.Error("Error occured when attempting to count number of open tickets: " + e);
Logger.Error("Error occured when attempting to count number of open tickets.", e);
}

return -1;
Expand Down Expand Up @@ -365,8 +365,9 @@ public static bool DeleteOpenTicket(uint ticketID)
deletion.Prepare();
return deletion.ExecuteNonQuery() > 0;
}
catch (MySqlException)
catch (MySqlException e)
{
Logger.Warn("Could not delete open ticket in database.", e);
return false;
}
}
Expand Down Expand Up @@ -403,8 +404,9 @@ public static bool Blacklist(ulong blacklistedID, ulong staffID)
cmd.Prepare();
return cmd.ExecuteNonQuery() > 0;
}
catch (MySqlException)
catch (MySqlException e)
{
Logger.Warn("Could not blacklist user in database.", e);
return false;
}
}
Expand All @@ -420,8 +422,9 @@ public static bool Unblacklist(ulong blacklistedID)
cmd.Prepare();
return cmd.ExecuteNonQuery() > 0;
}
catch (MySqlException)
catch (MySqlException e)
{
Logger.Warn("Could not unblacklist user in database.", e);
return false;
}
}
Expand All @@ -438,8 +441,9 @@ public static bool AssignStaff(Ticket ticket, ulong staffID)
update.Prepare();
return update.ExecuteNonQuery() > 0;
}
catch (MySqlException)
catch (MySqlException e)
{
Logger.Warn("Could not add staff to ticket in database.", e);
return false;
}
}
Expand All @@ -461,8 +465,9 @@ public static bool SetStaffActive(ulong staffID, bool active)
update.Prepare();
return update.ExecuteNonQuery() > 0;
}
catch (MySqlException)
catch (MySqlException e)
{
Logger.Warn("Could not set staff member as active in database.", e);
return false;
}
}
Expand All @@ -476,7 +481,6 @@ public static List<StaffMember> GetActiveStaff(params ulong[] ignoredUserIDs)
selection.Prepare();
MySqlDataReader results = selection.ExecuteReader();

// Check if staff exists in the database
if (!results.Read())
{
return new List<StaffMember>();
Expand All @@ -501,7 +505,6 @@ public static List<StaffMember> GetAllStaff(params ulong[] ignoredUserIDs)
selection.Prepare();
MySqlDataReader results = selection.ExecuteReader();

// Check if staff exist in the database
if (!results.Read())
{
return new List<StaffMember>();
Expand All @@ -526,7 +529,6 @@ public static bool IsStaff(ulong staffID)
selection.Prepare();
MySqlDataReader results = selection.ExecuteReader();

// Check if ticket exists in the database
if (!results.Read())
{
return false;
Expand All @@ -544,7 +546,6 @@ public static bool TryGetStaff(ulong staffID, out StaffMember staffMember)
selection.Prepare();
MySqlDataReader results = selection.ExecuteReader();

// Check if ticket exists in the database
if (!results.Read())
{
staffMember = null;
Expand All @@ -563,7 +564,6 @@ public static List<Message> GetAllMessages()
selection.Prepare();
MySqlDataReader results = selection.ExecuteReader();

// Check if messages exist in the database
if (!results.Read())
{
return new List<Message>();
Expand Down Expand Up @@ -612,8 +612,9 @@ public static bool AddMessage(string identifier, ulong userID, string message)
cmd.Prepare();
return cmd.ExecuteNonQuery() > 0;
}
catch (MySqlException)
catch (MySqlException e)
{
Logger.Error("Could not add message to database.", e);
return false;
}
}
Expand All @@ -629,8 +630,9 @@ public static bool RemoveMessage(string identifier)
cmd.Prepare();
return cmd.ExecuteNonQuery() > 0;
}
catch (MySqlException)
catch (MySqlException e)
{
Logger.Error("Could not remove message from database.", e);
return false;
}
}
Expand All @@ -643,7 +645,6 @@ public static List<Category> GetAllCategories()
selection.Prepare();
MySqlDataReader results = selection.ExecuteReader();

// Check if messages exist in the database
if (!results.Read())
{
return new List<Category>();
Expand All @@ -668,7 +669,6 @@ public static bool TryGetCategory(ulong categoryID, out Category message)
selection.Prepare();
MySqlDataReader results = selection.ExecuteReader();

// Check if ticket exists in the database
if (!results.Read())
{
message = null;
Expand All @@ -688,7 +688,6 @@ public static bool TryGetCategory(string name, out Category message)
selection.Prepare();
MySqlDataReader results = selection.ExecuteReader();

// Check if ticket exists in the database
if (!results.Read())
{
message = null;
Expand All @@ -711,8 +710,9 @@ public static bool AddCategory(string name, ulong categoryID)
cmd.Prepare();
return cmd.ExecuteNonQuery() > 0;
}
catch (MySqlException)
catch (MySqlException e)
{
Logger.Error("Could not add category to database.", e);
return false;
}
}
Expand All @@ -728,8 +728,9 @@ public static bool RemoveCategory(ulong categoryID)
cmd.Prepare();
return cmd.ExecuteNonQuery() > 0;
}
catch (MySqlException)
catch (MySqlException e)
{
Logger.Error("Could not remove category from database.", e);
return false;
}
}
Expand All @@ -743,7 +744,6 @@ public static string GetInterviewTemplateJSON(ulong categoryID)
selection.Prepare();
MySqlDataReader results = selection.ExecuteReader();

// Return a default template if it doesn't exist.
if (!results.Read())
{
return null;
Expand Down Expand Up @@ -824,8 +824,9 @@ public static bool SetInterviewTemplate(Template template)
cmd.Prepare();
return cmd.ExecuteNonQuery() > 0;
}
catch (MySqlException)
catch (MySqlException e)
{
Logger.Error("Could not set interview template in database.", e);
return false;
}
}
Expand Down Expand Up @@ -870,8 +871,9 @@ public static bool SaveInterview(Interview interview)
cmd.Prepare();
return cmd.ExecuteNonQuery() > 0;
}
catch (MySqlException)
catch (MySqlException e)
{
Logger.Error("Could not save interview to database.", e);
return false;
}
}
Expand Down

0 comments on commit 18de718

Please sign in to comment.