/* This Source Code Form is subject to the terms of the Mozilla Public *License,v.2.0.IfacopyoftheMPLwasnotdistributedwiththis
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
/// Maintenance tasks to run on an SQLite database connection. #[derive(Debug)] pubstruct Maintenance<'a> {
conn: &'a rusqlite::Connection,
}
/// Quickly checks the database for consistency, without verifying indexes /// or checking for `UNIQUE` constraint violations. pubfn quick_check(&self) -> Result<(), MaintenanceError> { // We're interested in an `ok` / not OK result, so ask // SQLite to stop the analysis as soon as it finds 1 error. let ok = self.conn.query_row("PRAGMA quick_check(1)", [], |row| {
Ok(row.get::<_, String>(0)? == "ok")
})?; match ok { true => Ok(()), false => Err(MaintenanceError::QuickCheck),
}
}
/// Checks the database for consistency. pubfn integrity_check(&self) -> Result<(), MaintenanceError> { let ok = self
.conn
.query_row("PRAGMA integrity_check(1)", [], |row| {
Ok(row.get::<_, String>(0)? == "ok")
})?; match ok { true => Ok(()), false => Err(MaintenanceError::IntegrityCheck),
}
}
/// Checks for foreign key constraint violations. pubfn foreign_key_check(&self) -> Result<(), MaintenanceError> { // A foreign key check returns no rows on success. let ok = self
.conn
.prepare("PRAGMA foreign_key_check")
.and_then(|mut statement| Ok(statement.query([])?.next()?.is_none()))?; match ok { true => Ok(()), false => Err(MaintenanceError::ForeignKeyCheck),
}
}
/// Deletes and recreates all database indexes. pubfn reindex(&self) -> Result<(), MaintenanceError> { self.conn.execute_batch("REINDEX")?;
Ok(())
}
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.