iterator error was because it must return a rusqlite::Result. use rusqlite macro for empty params

This commit is contained in:
Conrad Dean 2019-07-22 07:40:59 -04:00
parent a25f476734
commit e3bd1cb77e
2 changed files with 18 additions and 18 deletions

View file

@ -215,7 +215,7 @@ pub struct AevRows<'conn, F> {
/// for now it's convenient to avoid error handling. /// for now it's convenient to avoid error handling.
impl<'conn, F> Iterator for AevRows<'conn, F> impl<'conn, F> Iterator for AevRows<'conn, F>
where where
F: FnMut(&rusqlite::Row) -> Result<Aev>, F: FnMut(&rusqlite::Row) -> rusqlite::Result<Aev>,
{ {
type Item = Aev; type Item = Aev;
fn next(&mut self) -> Option<Aev> { fn next(&mut self) -> Option<Aev> {

View file

@ -256,7 +256,7 @@ lazy_static! {
/// Mentat manages its own SQL schema version using the user version. See the [SQLite /// Mentat manages its own SQL schema version using the user version. See the [SQLite
/// documentation](https://www.sqlite.org/pragma.html#pragma_user_version). /// documentation](https://www.sqlite.org/pragma.html#pragma_user_version).
fn set_user_version(conn: &rusqlite::Connection, version: i32) -> Result<()> { fn set_user_version(conn: &rusqlite::Connection, version: i32) -> Result<()> {
conn.execute(&format!("PRAGMA user_version = {}", version), &[]) conn.execute(&format!("PRAGMA user_version = {}", version), rusqlite::params![])
.context(DbErrorKind::CouldNotSetVersionPragma)?; .context(DbErrorKind::CouldNotSetVersionPragma)?;
Ok(()) Ok(())
} }
@ -267,7 +267,7 @@ fn set_user_version(conn: &rusqlite::Connection, version: i32) -> Result<()> {
/// documentation](https://www.sqlite.org/pragma.html#pragma_user_version). /// documentation](https://www.sqlite.org/pragma.html#pragma_user_version).
fn get_user_version(conn: &rusqlite::Connection) -> Result<i32> { fn get_user_version(conn: &rusqlite::Connection) -> Result<i32> {
let v = conn let v = conn
.query_row("PRAGMA user_version", &[], |row| row.get(0)) .query_row("PRAGMA user_version", rusqlite::params![], |row| row.get(0))
.context(DbErrorKind::CouldNotGetVersionPragma)?; .context(DbErrorKind::CouldNotGetVersionPragma)?;
Ok(v) Ok(v)
} }
@ -279,7 +279,7 @@ pub fn create_empty_current_version(
let tx = conn.transaction_with_behavior(TransactionBehavior::Exclusive)?; let tx = conn.transaction_with_behavior(TransactionBehavior::Exclusive)?;
for statement in (&V1_STATEMENTS).iter() { for statement in (&V1_STATEMENTS).iter() {
tx.execute(statement, &[])?; tx.execute(statement, rusqlite::params![])?;
} }
set_user_version(&tx, CURRENT_VERSION)?; set_user_version(&tx, CURRENT_VERSION)?;
@ -295,7 +295,7 @@ pub fn create_empty_current_version(
fn create_current_partition_view(conn: &rusqlite::Connection) -> Result<()> { fn create_current_partition_view(conn: &rusqlite::Connection) -> Result<()> {
let mut stmt = conn.prepare("SELECT part, end FROM known_parts ORDER BY end ASC")?; let mut stmt = conn.prepare("SELECT part, end FROM known_parts ORDER BY end ASC")?;
let known_parts: Result<Vec<(String, i64)>> = stmt let known_parts: Result<Vec<(String, i64)>> = stmt
.query_and_then(&[], |row| Ok((row.get(0)?, row.get(1)?)))? .query_and_then(rusqlite::params![], |row| Ok((row.get(0)?, row.get(1)?)))?
.collect(); .collect();
let mut case = vec![]; let mut case = vec![];
@ -314,7 +314,7 @@ fn create_current_partition_view(conn: &rusqlite::Connection) -> Result<()> {
::TIMELINE_MAIN ::TIMELINE_MAIN
); );
conn.execute(&view_stmt, &[])?; conn.execute(&view_stmt, rusqlite::params![])?;
Ok(()) Ok(())
} }
@ -491,7 +491,7 @@ pub(crate) fn read_materialized_view(
) -> Result<Vec<(Entid, Entid, TypedValue)>> { ) -> Result<Vec<(Entid, Entid, TypedValue)>> {
let mut stmt: rusqlite::Statement = let mut stmt: rusqlite::Statement =
conn.prepare(format!("SELECT e, a, v, value_type_tag FROM {}", table).as_str())?; conn.prepare(format!("SELECT e, a, v, value_type_tag FROM {}", table).as_str())?;
let m: Result<Vec<_>> = stmt.query_and_then(&[], row_to_datom_assertion)?.collect(); let m: Result<Vec<_>> = stmt.query_and_then(rusqlite::params![], row_to_datom_assertion)?.collect();
m m
} }
@ -532,7 +532,7 @@ pub fn read_partition_map(conn: &rusqlite::Connection) -> Result<PartitionMap> {
part NOT IN (SELECT part FROM parts)", part NOT IN (SELECT part FROM parts)",
)?; )?;
let m = stmt let m = stmt
.query_and_then(&[], |row| -> Result<(String, Partition)> { .query_and_then(rusqlite::params![], |row| -> Result<(String, Partition)> {
Ok(( Ok((
row.get(0)?, row.get(0)?,
Partition::new(row.get(1)?, row.get(2)?, row.get(3)?, row.get(4)?), Partition::new(row.get(1)?, row.get(2)?, row.get(3)?, row.get(4)?),
@ -660,7 +660,7 @@ fn search(conn: &rusqlite::Connection) -> Result<()> {
t.a0 = d.a"#; t.a0 = d.a"#;
let mut stmt = conn.prepare_cached(s)?; let mut stmt = conn.prepare_cached(s)?;
stmt.execute(&[]).context(DbErrorKind::CouldNotSearch)?; stmt.execute(rusqlite::params![]).context(DbErrorKind::CouldNotSearch)?;
Ok(()) Ok(())
} }
@ -718,7 +718,7 @@ fn update_datoms(conn: &rusqlite::Connection, tx: Entid) -> Result<()> {
DELETE FROM datoms WHERE rowid IN ids"#; DELETE FROM datoms WHERE rowid IN ids"#;
let mut stmt = conn.prepare_cached(s)?; let mut stmt = conn.prepare_cached(s)?;
stmt.execute(&[]) stmt.execute(rusqlite::params![])
.context(DbErrorKind::DatomsUpdateFailedToRetract)?; .context(DbErrorKind::DatomsUpdateFailedToRetract)?;
// Insert datoms that were added and not already present. We also must expand our bitfield into // Insert datoms that were added and not already present. We also must expand our bitfield into
@ -873,7 +873,7 @@ impl MentatStoring for rusqlite::Connection {
for statement in &statements { for statement in &statements {
let mut stmt = self.prepare_cached(statement)?; let mut stmt = self.prepare_cached(statement)?;
stmt.execute(&[]) stmt.execute(rusqlite::params![])
.context(DbErrorKind::FailedToCreateTempTables)?; .context(DbErrorKind::FailedToCreateTempTables)?;
} }
@ -1073,7 +1073,7 @@ impl MentatStoring for rusqlite::Connection {
let mut stmt = self.prepare_cached( let mut stmt = self.prepare_cached(
"UPDATE fulltext_values SET searchid = NULL WHERE searchid IS NOT NULL", "UPDATE fulltext_values SET searchid = NULL WHERE searchid IS NOT NULL",
)?; )?;
stmt.execute(&[]) stmt.execute(rusqlite::params![])
.context(DbErrorKind::FtsFailedToDropSearchIds)?; .context(DbErrorKind::FtsFailedToDropSearchIds)?;
results.map(|_| ()) results.map(|_| ())
} }
@ -1114,7 +1114,7 @@ impl MentatStoring for rusqlite::Connection {
let mut stmt = self.prepare_cached(&sql_stmt)?; let mut stmt = self.prepare_cached(&sql_stmt)?;
let m: Result<Vec<_>> = stmt let m: Result<Vec<_>> = stmt
.query_and_then(&[], row_to_transaction_assertion)? .query_and_then(rusqlite::params![], row_to_transaction_assertion)?
.collect(); .collect();
m m
} }
@ -1178,14 +1178,14 @@ pub fn update_metadata(
// TODO: use concat! to avoid creating String instances. // TODO: use concat! to avoid creating String instances.
if !metadata_report.idents_altered.is_empty() { if !metadata_report.idents_altered.is_empty() {
// Idents is the materialized view of the [entid :db/ident ident] slice of datoms. // Idents is the materialized view of the [entid :db/ident ident] slice of datoms.
conn.execute(format!("DELETE FROM idents").as_str(), &[])?; conn.execute(format!("DELETE FROM idents").as_str(), rusqlite::params![])?;
conn.execute( conn.execute(
format!( format!(
"INSERT INTO idents SELECT e, a, v, value_type_tag FROM datoms WHERE a IN {}", "INSERT INTO idents SELECT e, a, v, value_type_tag FROM datoms WHERE a IN {}",
entids::IDENTS_SQL_LIST.as_str() entids::IDENTS_SQL_LIST.as_str()
) )
.as_str(), .as_str(),
&[], rusqlite::params![],
)?; )?;
} }
@ -1200,7 +1200,7 @@ pub fn update_metadata(
|| !metadata_report.attributes_altered.is_empty() || !metadata_report.attributes_altered.is_empty()
|| !metadata_report.idents_altered.is_empty() || !metadata_report.idents_altered.is_empty()
{ {
conn.execute(format!("DELETE FROM schema").as_str(), &[])?; conn.execute(format!("DELETE FROM schema").as_str(), rusqlite::params![])?;
// NB: we're using :db/valueType as a placeholder for the entire schema-defining set. // NB: we're using :db/valueType as a placeholder for the entire schema-defining set.
let s = format!( let s = format!(
r#" r#"
@ -1213,7 +1213,7 @@ pub fn update_metadata(
entids::DB_VALUE_TYPE, entids::DB_VALUE_TYPE,
entids::SCHEMA_SQL_LIST.as_str() entids::SCHEMA_SQL_LIST.as_str()
); );
conn.execute(&s, &[])?; conn.execute(&s, rusqlite::params![])?;
} }
let mut index_stmt = conn.prepare("UPDATE datoms SET index_avet = ? WHERE a = ?")?; let mut index_stmt = conn.prepare("UPDATE datoms SET index_avet = ? WHERE a = ?")?;
@ -3317,7 +3317,7 @@ mod tests {
let sqlite = new_connection_with_key("../fixtures/v1encrypted.db", secret_key) let sqlite = new_connection_with_key("../fixtures/v1encrypted.db", secret_key)
.expect("Failed to find test DB"); .expect("Failed to find test DB");
sqlite sqlite
.query_row("SELECT COUNT(*) FROM sqlite_master", &[], |row| { .query_row("SELECT COUNT(*) FROM sqlite_master", rusqlite::params![], |row| {
row.get::<_, i64>(0) row.get::<_, i64>(0)
}) })
.expect("Failed to execute sql query on encrypted DB"); .expect("Failed to execute sql query on encrypted DB");