mirror of
https://github.com/isar/rusqlite.git
synced 2024-11-25 10:31:37 +08:00
Add example loading extension
This commit is contained in:
parent
8051b048db
commit
d7f2d55bfb
1
.github/workflows/main.yml
vendored
1
.github/workflows/main.yml
vendored
@ -67,6 +67,7 @@ jobs:
|
|||||||
|
|
||||||
- name: loadable extension
|
- name: loadable extension
|
||||||
run: cargo build --example loadable_extension --features "loadable_extension modern_sqlite functions vtab trace"
|
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
|
# TODO: move into own action for better caching
|
||||||
- name: Static build
|
- name: Static build
|
||||||
|
@ -162,6 +162,10 @@ name = "loadable_extension"
|
|||||||
crate-type = ["cdylib"]
|
crate-type = ["cdylib"]
|
||||||
required-features = ["loadable_extension", "modern_sqlite", "functions", "vtab", "trace"]
|
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]
|
[package.metadata.docs.rs]
|
||||||
features = ["modern-full"]
|
features = ["modern-full"]
|
||||||
all-features = false
|
all-features = false
|
||||||
|
19
examples/load_extension.rs
Normal file
19
examples/load_extension.rs
Normal file
@ -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(())
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user