From 7a7ff8f80efc60ec61fe393038125ae42a3c9ac6 Mon Sep 17 00:00:00 2001 From: Sophie Tauchert <999eagle@999eagle.moe> Date: Tue, 26 Mar 2019 21:20:06 +0100 Subject: [PATCH] Add function to open a read only connection --- src/connection.rs | 18 ++++++++++++++++++ src/lib.rs | 6 ++++++ 2 files changed, 24 insertions(+) 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`.