diff --git a/src/database.rs b/src/database.rs index 7b44e34..9241fa2 100644 --- a/src/database.rs +++ b/src/database.rs @@ -132,6 +132,10 @@ pub fn delete_dataset(connection: &Connection, dataset: &str) -> sqlite::Result< } pub fn rename_dataset(connection: &Connection, old: &str, new: &str) -> sqlite::Result<()> { + if old == new { + return Ok(()); + } + let query = format!( r#"UPDATE datasets SET name = '{1}' WHERE name = '{0}'; ALTER TABLE "{0}_players" RENAME TO "{1}_players"; diff --git a/src/main.rs b/src/main.rs index 8174e1f..efc3b08 100644 --- a/src/main.rs +++ b/src/main.rs @@ -472,7 +472,19 @@ fn dataset_rename(old: Option, new: Option) { let connection = open_datasets(&config_dir).unwrap_or_else(|_| error("Could not open datasets file", 2)); - rename_dataset(&connection, &old, &new).unwrap(); + + match rename_dataset(&connection, &old, &new) { + Ok(()) => (), + Err(sqlite::Error { + code: Some(1), + message: _, + }) => error(&format!("Dataset {:?} does not exist", &old), 1), + Err(sqlite::Error { + code: Some(19), + message: _, + }) => error(&format!("Dataset {:?} already exists", &new), 1), + Err(_) => error("Unknown error occurred", 2), + }; } // Players