From d7f2d55bfbffdfbd260dd8dac448b0b0eb551dc8 Mon Sep 17 00:00:00 2001 From: gwenn Date: Fri, 14 Jul 2023 11:07:59 +0200 Subject: [PATCH] Add example loading extension --- .github/workflows/main.yml | 1 + Cargo.toml | 4 ++++ examples/load_extension.rs | 19 +++++++++++++++++++ 3 files changed, 24 insertions(+) create mode 100644 examples/load_extension.rs diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index abed5ff..4b75b87 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -67,6 +67,7 @@ jobs: - name: loadable extension run: cargo build --example loadable_extension --features "loadable_extension modern_sqlite functions vtab trace" + run: cargo run --example load_extension --features "load_extension bundled functions vtab trace" # TODO: move into own action for better caching - name: Static build diff --git a/Cargo.toml b/Cargo.toml index ae4df7a..eb2a1b9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -162,6 +162,10 @@ name = "loadable_extension" crate-type = ["cdylib"] required-features = ["loadable_extension", "modern_sqlite", "functions", "vtab", "trace"] +[[example]] +name = "load_extension" +required-features = ["load_extension", "bundled", "functions", "vtab", "trace"] + [package.metadata.docs.rs] features = ["modern-full"] all-features = false diff --git a/examples/load_extension.rs b/examples/load_extension.rs new file mode 100644 index 0000000..e23a991 --- /dev/null +++ b/examples/load_extension.rs @@ -0,0 +1,19 @@ +//! Ensure loadable_extension.rs works. + +use rusqlite::{Connection, Result}; + +fn main() -> Result<()> { + let db = Connection::open_in_memory()?; + + unsafe { + db.load_extension_enable()?; + db.load_extension("target/debug/examples/libloadable_extension", None)?; + db.load_extension_disable()?; + } + + let str = db.query_row("SELECT rusqlite_test_function()", [], |row| { + row.get::<_, String>(0) + })?; + assert_eq!(&str, "Rusqlite extension loaded correctly!"); + Ok(()) +}