Skip to content

Commit

Permalink
SiteController::db_query > fix InvalidParameterCount error
Browse files Browse the repository at this point in the history
  • Loading branch information
canewsin committed Jan 11, 2024
1 parent 851402b commit ba7f72d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/controllers/sites.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ impl SitesController {
query: &str,
params: Option<Value>,
) -> Result<Vec<Map<String, Value>>, Error> {
let has_params = params.is_some();
let (query, params) = if let Some(params) = params {
Self::parse_query(query, params)
} else {
Expand All @@ -187,8 +188,12 @@ impl SitesController {
.map(|s| s.to_string())
.collect::<Vec<String>>()
};
let res = stmt
.query_map(params![params], |row| {
let res = if has_params {
stmt.query(params![params])
} else {
stmt.query(params![])
};
let res = res?.mapped( |row| {
let mut data_map = Map::new();
let mut i = 0;
loop {
Expand All @@ -203,8 +208,7 @@ impl SitesController {
}
}
Ok(data_map)
})
.unwrap();
});
let res = res.filter_map(|e| e.ok()).collect::<Vec<_>>();
Ok(res)
}
Expand Down
7 changes: 7 additions & 0 deletions src/core/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ pub enum Error {
MsgPackDecoding(rmp_serde::decode::Error),
MailboxError,
ParseError,
SqliteError(rusqlite::Error),
}

impl From<std::io::Error> for Error {
Expand Down Expand Up @@ -88,3 +89,9 @@ impl From<zerucontent::ErrorKind> for Error {
Error::Err(format!("{:?}", err))
}
}

impl From<rusqlite::Error> for Error {
fn from(err: rusqlite::Error) -> Error {
Error::SqliteError(err)
}
}

0 comments on commit ba7f72d

Please sign in to comment.