mirror of
https://github.com/isar/rusqlite.git
synced 2025-01-19 20:50:51 +08:00
Fix non-bundled tests against macOS system SQLite
This commit is contained in:
parent
f8b9ad8907
commit
9699b4a210
23
src/lib.rs
23
src/lib.rs
@ -1515,15 +1515,28 @@ mod test {
|
|||||||
#[test]
|
#[test]
|
||||||
fn test_pragma_query_row() -> Result<()> {
|
fn test_pragma_query_row() -> Result<()> {
|
||||||
let db = Connection::open_in_memory()?;
|
let db = Connection::open_in_memory()?;
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
"memory",
|
"memory",
|
||||||
db.query_row::<String, _, _>("PRAGMA journal_mode", [], |r| r.get(0))?
|
db.query_row::<String, _, _>("PRAGMA journal_mode", [], |r| r.get(0))?
|
||||||
);
|
);
|
||||||
assert_eq!(
|
let mode = db.query_row::<String, _, _>("PRAGMA journal_mode=off", [], |r| r.get(0))?;
|
||||||
"off",
|
if cfg!(features = "bundled") {
|
||||||
db.query_row::<String, _, _>("PRAGMA journal_mode=off", [], |r| r.get(0))?
|
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(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -406,18 +406,20 @@ mod test {
|
|||||||
let db = Connection::open_in_memory()?;
|
let db = Connection::open_in_memory()?;
|
||||||
let journal_mode: String =
|
let journal_mode: String =
|
||||||
db.pragma_update_and_check(None, "journal_mode", "OFF", |row| row.get(0))?;
|
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
|
// Sanity checks to ensure the move to a generic `ToSql` wasn't breaking
|
||||||
assert_eq!(
|
let mode = db
|
||||||
"off",
|
.pragma_update_and_check(None, "journal_mode", &"OFF", |row| row.get::<_, String>(0))?;
|
||||||
db.pragma_update_and_check(None, "journal_mode", &"OFF", |row| row
|
assert!(mode == "off" || mode == "memory", "mode: {:?}", mode);
|
||||||
.get::<_, String>(0))?,
|
|
||||||
);
|
|
||||||
let param: &dyn crate::ToSql = &"OFF";
|
let param: &dyn crate::ToSql = &"OFF";
|
||||||
assert_eq!(
|
let mode =
|
||||||
"off",
|
db.pragma_update_and_check(None, "journal_mode", param, |row| row.get::<_, String>(0))?;
|
||||||
db.pragma_update_and_check(None, "journal_mode", param, |row| row.get::<_, String>(0))?,
|
assert!(mode == "off" || mode == "memory", "mode: {:?}", mode);
|
||||||
);
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5,17 +5,16 @@ use rusqlite::ffi;
|
|||||||
use rusqlite::Connection;
|
use rusqlite::Connection;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
#[should_panic]
|
|
||||||
fn test_error_when_singlethread_mode() {
|
fn test_error_when_singlethread_mode() {
|
||||||
// put SQLite into single-threaded mode
|
// put SQLite into single-threaded mode
|
||||||
unsafe {
|
unsafe {
|
||||||
|
// Note: macOS system SQLite seems to return an error if you attempt to
|
||||||
|
// reconfigure to single-threaded mode.
|
||||||
if ffi::sqlite3_config(ffi::SQLITE_CONFIG_SINGLETHREAD) != ffi::SQLITE_OK {
|
if ffi::sqlite3_config(ffi::SQLITE_CONFIG_SINGLETHREAD) != ffi::SQLITE_OK {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if ffi::sqlite3_initialize() != ffi::SQLITE_OK {
|
assert_eq!(ffi::sqlite3_initialize(), ffi::SQLITE_OK);
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
let res = Connection::open_in_memory();
|
||||||
let _ = Connection::open_in_memory().unwrap();
|
assert!(res.is_err());
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user