Add better error handling for dataset rename command
This commit is contained in:
parent
4f240b318d
commit
fc7e6df283
|
@ -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";
|
||||
|
|
14
src/main.rs
14
src/main.rs
|
@ -472,7 +472,19 @@ fn dataset_rename(old: Option<String>, new: Option<String>) {
|
|||
|
||||
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
|
||||
|
|
Loading…
Reference in a new issue