diff --git a/src/dictionary.rs b/src/dictionary.rs index f3694a0..3cbd8e5 100644 --- a/src/dictionary.rs +++ b/src/dictionary.rs @@ -105,10 +105,10 @@ fn deduplicate(entries: &Vec) -> Vec { } fn write_to_database(dict: &Vec) { - let conn = Connection::open(get_db_path()).unwrap(); - + let mut conn = Connection::open(get_db_path()).unwrap(); + let tx = conn.transaction().unwrap(); for line in dict.iter() { - match conn.execute("INSERT OR REPLACE INTO cards (id, hieroglyph, reading, translation) VALUES ((SELECT id FROM cards WHERE hieroglyph = ?1), ?1, ?2, ?3)", [&line.hieroglyph, &line.reading, &line.translation]) { + match tx.execute("INSERT OR REPLACE INTO cards (id, hieroglyph, reading, translation) VALUES ((SELECT id FROM cards WHERE hieroglyph = ?1), ?1, ?2, ?3)", [&line.hieroglyph, &line.reading, &line.translation]) { Ok(_) => (), Err(e) => { println!("{e}" ); @@ -116,12 +116,13 @@ fn write_to_database(dict: &Vec) { } }; } + tx.commit().unwrap(); } pub fn import(path: &String) { let dictionary = read_and_parse(path); let dictionary = deduplicate(&dictionary); - // write_to_database(&dictionary); + write_to_database(&dictionary); } // pub fn write_to_file(path: &String, dict: &Vec) { diff --git a/src/ui/cards/edit/imp.rs b/src/ui/cards/edit/imp.rs index c41f0ba..ad6f865 100644 --- a/src/ui/cards/edit/imp.rs +++ b/src/ui/cards/edit/imp.rs @@ -114,7 +114,10 @@ impl MemoryCardsEditScene { .unwrap(); let cards_iter = stmt .query_map([], |row| { - let image_path: String = row.get(0).unwrap(); + let image_path: String = match row.get(0){ + Ok(path) => path, + Err(_) => String::from("") + }; let image_path: String = get_images_store_path() + &image_path; let hieroglyph: String = row.get(1).unwrap(); let reading: String = row.get(2).unwrap(); diff --git a/src/widgets/card_display/mod.rs b/src/widgets/card_display/mod.rs index b101cff..c9e5728 100644 --- a/src/widgets/card_display/mod.rs +++ b/src/widgets/card_display/mod.rs @@ -45,7 +45,10 @@ impl CardDisplay { let random_card_iter = stmt.query_map((), |row| { Ok( Card { - imagename: row.get(0).unwrap(), + imagename: match row.get(0) { + Ok(value) => value, + Err(e) => String::from("") + }, hieroglyph: row.get(1).unwrap() } )