aboutsummaryrefslogtreecommitdiffstats
path: root/src/sqlite.rs
diff options
context:
space:
mode:
authorTeddy Wing2022-03-13 02:46:31 +0100
committerTeddy Wing2022-03-13 02:46:31 +0100
commitc7f7ffa4488734c97f0be226fa7a5e2d79ca85e5 (patch)
treefb1ddf25e17a6fd26bdff147c6fac2fb19d2a5ff /src/sqlite.rs
parent2219c6dbd34903c1d32641cec56063b621d44c21 (diff)
downloadyaqlite-c7f7ffa4488734c97f0be226fa7a5e2d79ca85e5.tar.bz2
get_column_names(): Remove `unwrap()`s
Return a `Result` and wrap errors in a `thiserror` struct.
Diffstat (limited to 'src/sqlite.rs')
-rw-r--r--src/sqlite.rs18
1 files changed, 13 insertions, 5 deletions
diff --git a/src/sqlite.rs b/src/sqlite.rs
index bb2c5bb..1e3aeec 100644
--- a/src/sqlite.rs
+++ b/src/sqlite.rs
@@ -1,8 +1,16 @@
use rusqlite;
+use thiserror;
use std::collections::HashMap;
+#[derive(thiserror::Error, Debug)]
+pub enum SqliteError {
+ #[error("SQL error")]
+ Sqlite(#[from] rusqlite::Error),
+}
+
+
/// Get the fundamental SQLite datatype for a given type name.
///
/// Use the SQLite rules for type affinity described in:
@@ -43,7 +51,7 @@ pub struct Zero;
pub fn get_column_names(
dbconn: &rusqlite::Connection,
table_name: &str,
-) -> HashMap<String, Zero> {
+) -> Result<HashMap<String, Zero>, SqliteError> {
let mut column_names = HashMap::new();
let mut stmt = dbconn.prepare(
@@ -54,18 +62,18 @@ pub fn get_column_names(
"#,
table_name,
),
- ).unwrap();
+ )?;
let rows = stmt.query_map(
[],
|row| row.get(0),
- ).unwrap();
+ )?;
for row_result in rows {
- let row = row_result.unwrap();
+ let row = row_result?;
column_names.insert(row, Zero{});
}
- column_names
+ Ok(column_names)
}