diff --git a/src/connection.rs b/src/connection.rs index 4e42971..cb55a23 100644 --- a/src/connection.rs +++ b/src/connection.rs @@ -33,6 +33,24 @@ impl Connection { }) } + /// Open a read-only connection to an existing database. + pub fn open_readonly>(path: T) -> Result { + let mut raw = 0 as *mut _; + unsafe { + ok!(ffi::sqlite3_open_v2( + path_to_cstr!(path.as_ref()).as_ptr(), + &mut raw, + ffi::SQLITE_OPEN_READONLY, + 0 as *const _, + )); + } + Ok(Connection { + raw: raw, + busy_callback: None, + phantom: PhantomData, + }) + } + /// Execute a statement without processing the resulting rows if any. #[inline] pub fn execute>(&self, statement: T) -> Result<()> { diff --git a/src/lib.rs b/src/lib.rs index 82b0838..84dcb5d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -303,6 +303,12 @@ pub fn open>(path: T) -> Result { Connection::open(path) } +/// Open a read-only connection to an existing database. +#[inline] +pub fn open_readonly>(path: T) -> Result { + Connection::open_readonly(path) +} + /// Return the version number of SQLite. /// /// For instance, the version `3.8.11.1` corresponds to the integer `3008011`.