mirror of
https://github.com/isar/rusqlite.git
synced 2025-08-20 12:59:28 +08:00
Fix non-bundled tests against macOS system SQLite
This commit is contained in:
23
src/lib.rs
23
src/lib.rs
@@ -1515,15 +1515,28 @@ mod test {
|
||||
#[test]
|
||||
fn test_pragma_query_row() -> Result<()> {
|
||||
let db = Connection::open_in_memory()?;
|
||||
|
||||
assert_eq!(
|
||||
"memory",
|
||||
db.query_row::<String, _, _>("PRAGMA journal_mode", [], |r| r.get(0))?
|
||||
);
|
||||
assert_eq!(
|
||||
"off",
|
||||
db.query_row::<String, _, _>("PRAGMA journal_mode=off", [], |r| r.get(0))?
|
||||
);
|
||||
let mode = db.query_row::<String, _, _>("PRAGMA journal_mode=off", [], |r| r.get(0))?;
|
||||
if cfg!(features = "bundled") {
|
||||
assert_eq!(mode, "off");
|
||||
} else {
|
||||
// Note: system SQLite on macOS defaults to "off" rather than
|
||||
// "memory" for the journal mode (which cannot be changed for
|
||||
// in-memory connections). This seems like it's *probably* legal
|
||||
// according to the docs below, so we relax this test when not
|
||||
// bundling:
|
||||
//
|
||||
// From https://www.sqlite.org/pragma.html#pragma_journal_mode
|
||||
// > Note that the journal_mode for an in-memory database is either
|
||||
// > MEMORY or OFF and can not be changed to a different value. An
|
||||
// > attempt to change the journal_mode of an in-memory database to
|
||||
// > any setting other than MEMORY or OFF is ignored.
|
||||
assert!(mode == "memory" || mode == "off", "Got mode {:?}", mode);
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
@@ -406,18 +406,20 @@ mod test {
|
||||
let db = Connection::open_in_memory()?;
|
||||
let journal_mode: String =
|
||||
db.pragma_update_and_check(None, "journal_mode", "OFF", |row| row.get(0))?;
|
||||
assert_eq!("off", &journal_mode);
|
||||
assert!(
|
||||
journal_mode == "off" || journal_mode == "memory",
|
||||
"mode: {:?}",
|
||||
journal_mode,
|
||||
);
|
||||
// Sanity checks to ensure the move to a generic `ToSql` wasn't breaking
|
||||
assert_eq!(
|
||||
"off",
|
||||
db.pragma_update_and_check(None, "journal_mode", &"OFF", |row| row
|
||||
.get::<_, String>(0))?,
|
||||
);
|
||||
let mode = db
|
||||
.pragma_update_and_check(None, "journal_mode", &"OFF", |row| row.get::<_, String>(0))?;
|
||||
assert!(mode == "off" || mode == "memory", "mode: {:?}", mode);
|
||||
|
||||
let param: &dyn crate::ToSql = &"OFF";
|
||||
assert_eq!(
|
||||
"off",
|
||||
db.pragma_update_and_check(None, "journal_mode", param, |row| row.get::<_, String>(0))?,
|
||||
);
|
||||
let mode =
|
||||
db.pragma_update_and_check(None, "journal_mode", param, |row| row.get::<_, String>(0))?;
|
||||
assert!(mode == "off" || mode == "memory", "mode: {:?}", mode);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user