Test opening a read-only connection

This commit is contained in:
Ivan Ukhov 2019-06-08 20:42:31 +02:00
parent 9328fa0897
commit d1e9f8fd3e
2 changed files with 18 additions and 2 deletions

View File

@ -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
}

View File

@ -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;