rust/hedgewars-server/src/server/database.rs
changeset 14785 a1077e8d26f4
parent 14779 f43ab2bd76ae
child 15074 c5a6e8566425
--- a/rust/hedgewars-server/src/server/database.rs	Wed Apr 10 19:30:08 2019 +0300
+++ b/rust/hedgewars-server/src/server/database.rs	Wed Apr 10 23:56:53 2019 +0300
@@ -16,6 +16,8 @@
             VALUES
             (:players, :rooms, UNIX_TIMESTAMP())";
 
+const GET_REPLAY_NAME_QUERY: &str = r"SELECT filename FROM achievements WHERE id = :id";
+
 struct ServerStatistics {
     rooms: u32,
     players: u32,
@@ -95,8 +97,19 @@
         Ok(())
     }
 
-    pub fn get_replay_name(&mut self, replay_id: u32) -> Result<String, ()> {
-        Err(())
+    pub fn get_replay_name(&mut self, replay_id: u32) -> Result<Option<String>, Error> {
+        if let Some(pool) = &self.pool {
+            if let Some(row) =
+                pool.first_exec(GET_REPLAY_NAME_QUERY, params! { "id" => replay_id })?
+            {
+                let (filename) = from_row_opt::<(String)>(row)?;
+                Ok(Some(filename))
+            } else {
+                Ok(None)
+            }
+        } else {
+            Err(DriverError::SetupError.into())
+        }
     }
 }