Skip to content

Commit

Permalink
Provide a minimal interface exposing SQLite's enable_load_extension
Browse files Browse the repository at this point in the history
This behavior is untested since we would need to add some extensions in
order to test it.

Fixes #1867
  • Loading branch information
sgrif committed Oct 7, 2018
1 parent db66040 commit 7af9457
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
10 changes: 10 additions & 0 deletions diesel/src/sqlite/connection/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,16 @@ impl SqliteConnection {
self.transaction_sql(f, "BEGIN EXCLUSIVE")
}

/// Enables the `load_extension` SQL function.
///
/// See the documentation for the [`enable_load_extension` C function] for
/// details.
///
/// [`enable_load_extension` C function]: https://www.sqlite.org/c3ref/enable_load_extension.html
pub fn enable_load_extension(&self) {
self.raw_connection.enable_load_extension();
}

fn transaction_sql<T, E, F>(&self, f: F, sql: &str) -> Result<T, E>
where
F: FnOnce() -> Result<T, E>,
Expand Down
4 changes: 4 additions & 0 deletions diesel/src/sqlite/connection/raw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,10 @@ impl RawConnection {
))
}
}

pub fn enable_load_extension(&self) {
unsafe { ffi::enable_load_extension(self.internal_connection.as_ptr(), true) }
}
}

impl Drop for RawConnection {
Expand Down

2 comments on commit 7af9457

@alamminsalo
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think extension loading could be tested automatically inside a dedicated docker image?

@sgrif
Copy link
Member Author

@sgrif sgrif commented on 7af9457 Nov 3, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@alamminsalo Feel free to open a PR

Please sign in to comment.