diff --git a/src/connection.rs b/src/connection.rs index 6d2d21f..b577da6 100644 --- a/src/connection.rs +++ b/src/connection.rs @@ -188,7 +188,7 @@ impl ConnectionFlags { /// Open the database for reading only. pub fn set_read_only(mut self) -> Self { - self.0 |= ffi::SQLITE_OPEN_READWRITE; + self.0 |= ffi::SQLITE_OPEN_READONLY; self } diff --git a/tests/lib.rs b/tests/lib.rs index 0c38b03..9e46bee 100644 --- a/tests/lib.rs +++ b/tests/lib.rs @@ -1,7 +1,7 @@ extern crate sqlite; extern crate temporary; -use sqlite::{Connection, State, Type, Value}; +use sqlite::{Connection, ConnectionFlags, State, Type, Value}; use std::path::Path; macro_rules! ok(($result:expr) => ($result.unwrap())); @@ -40,6 +40,22 @@ fn connection_iterate() { assert!(done); } +#[test] +fn connection_open_with_flags() { + use temporary::Directory; + + let directory = ok!(Directory::new("sqlite")); + let path = directory.path().join("database.sqlite3"); + setup_users(&path); + + let flags = ConnectionFlags::new().set_read_only(); + let connection = ok!(sqlite::open_with_flags(path, flags)); + match connection.execute("INSERT INTO users VALUES (2, 'Bob', NULL, NULL)") { + Err(_) => {}, + _ => unreachable!(), + } +} + #[test] fn connection_set_busy_handler() { use std::thread;