This commit is contained in:
QkoSad
2024-11-28 14:36:15 +02:00
parent 06ea52ead6
commit fd82786671
12 changed files with 22 additions and 213 deletions
+5 -5
View File
@@ -12,9 +12,9 @@ namespace Server
{
try
{
// Open the connection
// open connection
conn.Open();
// Prepare the SQL query
// prepare SQL query
MySqlCommand cmd = new MySqlCommand();
cmd.Connection = conn;
cmd.CommandText = @"SELECT p.name, SUM(t.time)
@@ -26,7 +26,7 @@ namespace Server
var queryString = request.QueryString;
string? userid = queryString["userid"];
cmd.Parameters.AddWithValue("@userid", userid);
// Execute the query and read the results
// execute query and read results
MySqlDataReader reader = cmd.ExecuteReader();
dynamic expando = new ExpandoObject();
while (reader.Read())
@@ -34,7 +34,7 @@ namespace Server
((IDictionary<string?, object>)expando)[reader["name"].ToString()] = reader["SUM(t.time)"];
}
// Serialize the data to JSON
// serialize JSON
string jsonResponse = JsonConvert.SerializeObject(expando);
// prepare response
byte[] buffer = Encoding.UTF8.GetBytes(jsonResponse);
@@ -45,13 +45,13 @@ namespace Server
}
catch (Exception ex)
{
// Handle any connection errors
string errorMessage = $"Error: {ex.Message}";
byte[] buffer = Encoding.UTF8.GetBytes(errorMessage);
response.ContentType = "text/plain";
response.ContentLength64 = buffer.Length;
response.OutputStream.Write(buffer, 0, buffer.Length);
}
// close db connection
conn.Close();
}
}