- self.con.query_row(\r
- "SELECT name FROM sqlite_master WHERE type='table' AND name='versions'",\r
- rusqlite::NO_PARAMS,\r
- |row| Ok(dbg!("test"))\r
- )\r
+ while Connection::update_to_next_version(version, &tx)? {\r
+ version += 1;\r
+ }\r
+\r
+ tx.commit()?;\r
+\r
+ Ok(())\r
+ }\r
+\r
+ fn update_to_next_version(current_version: u32, tx: &rusqlite::Transaction) -> Result<bool, DBError> {\r
+ let next_version = current_version + 1;\r
+\r
+ if next_version <= CURRENT_DB_VERSION {\r
+ println!("Update to version {}...", next_version);\r
+ }\r
+\r
+ fn ok(updated: bool) -> Result<bool, DBError> {\r
+ if updated {\r
+ println!("Version updated");\r
+ }\r
+ Ok(updated)\r
+ }\r
+\r
+ match next_version {\r
+ 1 => {\r
+ tx.execute_batch(&load_sql_file(next_version)?)?;\r
+\r
+ ok(true)\r
+ }\r
+\r
+ // Version 1 doesn't exist yet.\r
+ 2 =>\r
+ ok(false),\r
+\r
+ v =>\r
+ Err(DBError::UnsupportedVersion(v)),\r
+ }\r