2015-12-17 12:33:56 +08:00
|
|
|
//! Ensure we reject connections when SQLite is in single-threaded mode, as it
|
|
|
|
//! would violate safety if multiple Rust threads tried to use connections.
|
|
|
|
|
2019-01-30 06:59:41 +08:00
|
|
|
use rusqlite::ffi;
|
2015-12-17 12:33:56 +08:00
|
|
|
use rusqlite::Connection;
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_error_when_singlethread_mode() {
|
|
|
|
// put SQLite into single-threaded mode
|
|
|
|
unsafe {
|
2022-04-04 01:48:56 +08:00
|
|
|
// Note: macOS system SQLite seems to return an error if you attempt to
|
|
|
|
// reconfigure to single-threaded mode.
|
2017-02-10 09:12:24 +08:00
|
|
|
if ffi::sqlite3_config(ffi::SQLITE_CONFIG_SINGLETHREAD) != ffi::SQLITE_OK {
|
|
|
|
return;
|
|
|
|
}
|
2022-04-04 01:48:56 +08:00
|
|
|
assert_eq!(ffi::sqlite3_initialize(), ffi::SQLITE_OK);
|
2015-12-17 12:33:56 +08:00
|
|
|
}
|
2022-04-04 01:48:56 +08:00
|
|
|
let res = Connection::open_in_memory();
|
2022-07-31 13:00:37 +08:00
|
|
|
res.unwrap_err();
|
2015-12-17 12:33:56 +08:00
|
|
|
}
|