Repository: cantino/mcfly (language: rust)

Issue:
Deleting all items causes unwrap panic
This is an edge case from a new machine with no commands (!) yet run, but also reproducible if you F2 delete every command... upon pressing ctrl+R:
```
❱ thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: InvalidColumnType(0, Null)', /Users/me/.cargo/registry/src/github.com-1ecc6299db9ec823/rusqlite-0.15.0/src/row.rs:149:31
```
Once I run a command then ctrl+R runs without panic.

expectation: either errors with a message saying "no commands in history" or show the empty list.


Discussion / hints:
Thanks!

Fix patch:
diff --git a/src/history/history.rs b/src/history/history.rs
index 54c9f318..87a4c932 100644
--- a/src/history/history.rs
+++ b/src/history/history.rs
@@ -446,7 +446,7 @@ impl History {
         let (mut when_run_min, when_run_max): (f64, f64) = self
             .connection
             .query_row(
-                "SELECT MIN(when_run), MAX(when_run) FROM commands",
+                "SELECT IFNULL(MIN(when_run), 0), IFNULL(MAX(when_run), 0) FROM commands",
                 NO_PARAMS,
                 |row| (row.get(0), row.get(1)),
             )
@@ -471,14 +471,14 @@ impl History {
 
         let max_length: f64 = self
             .connection
-            .query_row("SELECT MAX(LENGTH(cmd)) FROM commands", NO_PARAMS, |row| {
+            .query_row("SELECT IFNULL(MAX(LENGTH(cmd)), 0) FROM commands", NO_PARAMS, |row| {
                 row.get(0)
             })
             .unwrap_or(100.0);
 
         let max_id: i64 = self
             .connection
-            .query_row("SELECT MAX(id) FROM commands", NO_PARAMS, |row| {
+            .query_row("SELECT IFNULL(MAX(id), 0) FROM commands", NO_PARAMS, |row| {
                 row.get(0)
             })
             .unwrap_or(0);


Test patch: