diff --git a/Cargo.lock b/Cargo.lock index 12c99d3..2fad33f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2830,8 +2830,6 @@ dependencies = [ [[package]] name = "sqlite-wasm-rs" version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "84473e8335ed2f167c6f8040970d976990fb66aa62292ae58735de6d61ecfb73" dependencies = [ "fragile", "js-sys", diff --git a/Cargo.toml b/Cargo.toml index c955b5b..10d7b5b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -55,3 +55,6 @@ wasm-bindgen-test = "0.3" [profile.release] opt-level = "z" lto = true + +[patch.crates-io] +sqlite-wasm-rs = { path = "vendor/sqlite-wasm-rs" } diff --git a/vendor/sqlite-wasm-rs/Cargo.toml b/vendor/sqlite-wasm-rs/Cargo.toml new file mode 100644 index 0000000..d407a98 --- /dev/null +++ b/vendor/sqlite-wasm-rs/Cargo.toml @@ -0,0 +1,116 @@ +# THIS FILE IS AUTOMATICALLY GENERATED BY CARGO +# +# When uploading crates to the registry Cargo will automatically +# "normalize" Cargo.toml files for maximal compatibility +# with all versions of Cargo and also rewrite `path` dependencies +# to registry (e.g., crates.io) dependencies. +# +# If you are reading this file be aware that the original Cargo.toml +# will likely look very different (and much more reasonable). +# See Cargo.toml.orig for the original contents. + +[package] +edition = "2021" +name = "sqlite-wasm-rs" +version = "0.3.0" +authors = ["Spxg "] +build = "build.rs" +autolib = false +autobins = false +autoexamples = false +autotests = false +autobenches = false +description = "Provide sqlite solution for wasm32-unknown-unknown target." +readme = "README.md" +keywords = [ + "sqlite", + "sqlite-wasm", + "wasm", + "webassembly", + "javascript", +] +categories = [ + "development-tools::ffi", + "wasm", + "database", +] +license = "MIT" +repository = "https://github.com/Spxg/sqlite-wasm-rs" + +[package.metadata.docs.rs] +targets = ["wasm32-unknown-unknown"] + +[features] +buildtime-bindgen = ["bindgen"] +bundled = ["xshell"] +custom-libc = ["sqlite-wasm-libc"] +default = ["bundled"] +precompiled = [] + +[lib] +name = "sqlite_wasm_rs" +path = "src/lib.rs" + +[[test]] +name = "main" +path = "tests/main.rs" + +[dependencies.fragile] +version = "2.0.0" + +[dependencies.js-sys] +version = "0.3.76" + +[dependencies.once_cell] +version = "1.20.2" + +[dependencies.sqlite-wasm-libc] +version = "0.1.0" +optional = true + +[dependencies.thiserror] +version = "2.0.11" + +[dependencies.tokio] +version = "1.42.0" +features = ["sync"] + +[dependencies.wasm-bindgen] +version = "0.2.99" + +[dependencies.wasm-bindgen-futures] +version = "0.4.49" + +[dependencies.web-sys] +version = "0.3.77" +features = [ + "Performance", + "Window", + "Navigator", + "StorageManager", + "FileSystemSyncAccessHandle", + "FileSystemDirectoryHandle", + "FileSystemGetDirectoryOptions", + "FileSystemReadWriteOptions", + "SharedWorkerGlobalScope", + "ServiceWorkerGlobalScope", + "WorkerGlobalScope", + "WorkerNavigator", + "FileSystemGetFileOptions", + "FileSystemFileHandle", + "Url", +] + +[dev-dependencies.wasm-bindgen-test] +version = "0.3.49" + +[build-dependencies.bindgen] +version = "0.71" +optional = true + +[build-dependencies.xshell] +version = "0.2.7" +optional = true + +[target.'cfg(target_feature = "atomics")'.dependencies.parking_lot] +version = "0.12.3" diff --git a/vendor/sqlite-wasm-rs/LICENSE b/vendor/sqlite-wasm-rs/LICENSE new file mode 100644 index 0000000..8839511 --- /dev/null +++ b/vendor/sqlite-wasm-rs/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2024 Spxg + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/vendor/sqlite-wasm-rs/README.md b/vendor/sqlite-wasm-rs/README.md new file mode 100644 index 0000000..a104d96 --- /dev/null +++ b/vendor/sqlite-wasm-rs/README.md @@ -0,0 +1,103 @@ +# SQLite Wasm Rust + +[![Crates.io](https://img.shields.io/crates/v/sqlite-wasm-rs.svg)](https://crates.io/crates/sqlite-wasm-rs) + +Provide sqlite solution for `wasm32-unknown-unknown` target. + +## Usage + +```toml +[dependencies] +# using `bundled` default feature causes us to automatically compile and link in an up to date +# +# requires the emscripten toolchain +sqlite-wasm-rs = "0.3" +``` + +```toml +[dependencies] +# using precompiled binaries +sqlite-wasm-rs = { version = "0.3", default-features = false, features = ["precompiled"] } +``` + +```rust +use sqlite_wasm_rs::export::{self as ffi, install_opfs_sahpool}; + +async fn open_db() -> anyhow::Result<()> { + // open with memory vfs + let mut db = std::ptr::null_mut(); + let ret = unsafe { + ffi::sqlite3_open_v2( + c"mem.db".as_ptr().cast(), + &mut db as *mut _, + ffi::SQLITE_OPEN_READWRITE | ffi::SQLITE_OPEN_CREATE, + std::ptr::null() + ) + }; + assert_eq!(ffi::SQLITE_OK, ret); + + // install opfs-sahpool persistent vfs and set as default vfs + install_opfs_sahpool(None, true).await?; + + // open with opfs-sahpool vfs + let mut db = std::ptr::null_mut(); + let ret = unsafe { + ffi::sqlite3_open_v2( + c"opfs-sahpool.db".as_ptr().cast(), + &mut db as *mut _, + ffi::SQLITE_OPEN_READWRITE | ffi::SQLITE_OPEN_CREATE, + std::ptr::null() + ) + }; + assert_eq!(ffi::SQLITE_OK, ret); +} +``` + +## About multithreading + +This library is not thread-safe: + +* `JsValue` is not cross-threaded, see [`Ensure that JsValue isn't considered Send`](https://github.com/rustwasm/wasm-bindgen/pull/955) for details. +* sqlite is compiled with `-DSQLITE_THREADSAFE=0` + +## About VFS + +The following vfs have been implemented: + +* [`memory-vfs`](https://github.com/Spxg/sqlite-wasm-rs/blob/master/sqlite-wasm-rs/src/shim/vfs/memory.rs): as the default vfs, no additional conditions are required, just use. +* [`opfs-sahpool`](https://github.com/Spxg/sqlite-wasm-rs/blob/master/sqlite-wasm-rs/src/shim/vfs/sahpool.rs): ported from sqlite-wasm, it provides the best performance persistent storage method. + +See + +## Use external libc + +As mentioned above, sqlite is now directly linked to emscripten's libc. But we provide the ability to customize libc. + +Cargo provides a [`links`](https://doc.rust-lang.org/cargo/reference/manifest.html#the-links-field) field that can be used to specify which library to link to. + +We created a new [`sqlite-wasm-libc`](https://github.com/Spxg/sqlite-wasm-rs/tree/master/sqlite-wasm-libc) library with no implementation and only a `links = "libc"` configuration. + +Then with the help of [`Overriding Build Scripts`](https://doc.rust-lang.org/cargo/reference/build-scripts.html#overriding-build-scripts), you can overriding its configuration in your crate and link sqlite to your custom libc. + +More see [`custom-libc example`](https://github.com/Spxg/sqlite-wasm-rs/tree/master/examples/custom-libc). + +## Why provide precompiled library + +In the `shim` feature, since `wasm32-unknown-unknown` does not have libc, emscripten is used here for compilation, otherwise we need to copy a bunch of c headers required for sqlite3 compilation, which is a bit of a hack for me. If sqlite3 is compiled at compile time, the emscripten toolchain is required, and we cannot assume that all users have it installed. (Believe me, because rust mainly supports the `wasm32-unknown-unknown` target, most people do not have the emscripten toolchain). Considering that wasm is cross-platform, vendor compilation products are acceptable. + +About security issues: + +* You can specify the bundled feature to compile sqlite locally, which requires the emscripten toolchain. +* Currently all precompiled products are compiled and committed through Github Actions, which can be tracked, downloaded and compared. + +Precompile workflow: + +Change History: + +Actions: + +## Related Project + +* [`sqlite-wasm`](https://github.com/sqlite/sqlite-wasm): SQLite Wasm conveniently wrapped as an ES Module. +* [`sqlite-web-rs`](https://github.com/xmtp/sqlite-web-rs): A SQLite WebAssembly backend for Diesel. +* [`rusqlite`](https://github.com/rusqlite/rusqlite): Ergonomic bindings to SQLite for Rust. diff --git a/vendor/sqlite-wasm-rs/VFS.md b/vendor/sqlite-wasm-rs/VFS.md new file mode 100644 index 0000000..28c5a71 --- /dev/null +++ b/vendor/sqlite-wasm-rs/VFS.md @@ -0,0 +1,91 @@ +# memory + +Data is stored in memory, this is the default vfs + +```rust +use sqlite_wasm_rs::export as ffi; + +// open with memory vfs +let mut db = std::ptr::null_mut(); +let ret = unsafe { + ffi::sqlite3_open_v2( + c"mem.db".as_ptr().cast(), + &mut db as *mut _, + ffi::SQLITE_OPEN_READWRITE | ffi::SQLITE_OPEN_CREATE, + std::ptr::null() + ) +}; +assert_eq!(ffi::SQLITE_OK, ret); +``` + +# opfs-sahpool + +Persistent vfs, ported from sqlite-wasm, see for details + +```rust +use sqlite_wasm_rs::export::{self as ffi, install_opfs_sahpool}; + +// install opfs-sahpool persistent vfs and set as default vfs +install_opfs_sahpool(None, true).await?; + +// open with opfs-sahpool vfs +let mut db = std::ptr::null_mut(); +let ret = unsafe { + ffi::sqlite3_open_v2( + c"opfs-sahpool.db".as_ptr().cast(), + &mut db as *mut _, + ffi::SQLITE_OPEN_READWRITE | ffi::SQLITE_OPEN_CREATE, + std::ptr::null() + ) +}; +assert_eq!(ffi::SQLITE_OK, ret); + +let mut db = std::ptr::null_mut(); +let ret = unsafe { + ffi::sqlite3_open_v2( + c"file:opfs-sahpool.db?vfs=opfs-sahpool".as_ptr().cast(), + &mut db as *mut _, + ffi::SQLITE_OPEN_READWRITE | ffi::SQLITE_OPEN_CREATE, + std::ptr::null() + ) +}; +assert_eq!(ffi::SQLITE_OK, ret); + +let mut db = std::ptr::null_mut(); +let ret = unsafe { + ffi::sqlite3_open_v2( + c"opfs-sahpool.db".as_ptr().cast(), + &mut db as *mut _, + ffi::SQLITE_OPEN_READWRITE | ffi::SQLITE_OPEN_CREATE, + c"opfs-sahpool".as_ptr().cast() + ) +}; +assert_eq!(ffi::SQLITE_OK, ret); +``` + +Support custom vfs and directory + +```rust +use sqlite_wasm_rs::export::{ + self as ffi, + install_opfs_sahpool, + OpfsSAHPoolCfgBuilder +}; + +let cfg = OpfsSAHPoolCfgBuilder::new() + .vfs_name("custom-vfs") + .directory("custom/abc") + .build(); +install_opfs_sahpool(Some(&cfg), true).await?; + +let mut db = std::ptr::null_mut(); +let ret = unsafe { + ffi::sqlite3_open_v2( + c"custom-vfs.db".as_ptr().cast(), + &mut db as *mut _, + ffi::SQLITE_OPEN_READWRITE | ffi::SQLITE_OPEN_CREATE, + std::ptr::null() + ) +}; +assert_eq!(ffi::SQLITE_OK, ret); +``` diff --git a/vendor/sqlite-wasm-rs/build.rs b/vendor/sqlite-wasm-rs/build.rs new file mode 100644 index 0000000..a77f42b --- /dev/null +++ b/vendor/sqlite-wasm-rs/build.rs @@ -0,0 +1,253 @@ +#![allow(deprecated)] + +#[cfg(feature = "bundled")] +static COMMON: [&str; 7] = [ + // wasm is single-threaded + "-DSQLITE_THREADSAFE=0", + "-DSQLITE_TEMP_STORE=2", + "-DSQLITE_OS_OTHER", + "-DSQLITE_ENABLE_MATH_FUNCTIONS", + "-DSQLITE_USE_URI=1", + "-DSQLITE_OMIT_DEPRECATED", + // there is no dlopen on this platform. + "-DSQLITE_OMIT_LOAD_EXTENSION", +]; + +#[cfg(feature = "bundled")] +static FULL_FEATURED: [&str; 12] = [ + "-DSQLITE_ENABLE_BYTECODE_VTAB", + "-DSQLITE_ENABLE_DBPAGE_VTAB", + "-DSQLITE_ENABLE_DBSTAT_VTAB", + "-DSQLITE_ENABLE_FTS5", + "-DSQLITE_ENABLE_MATH_FUNCTIONS", + "-DSQLITE_ENABLE_OFFSET_SQL_FUNC", + "-DSQLITE_ENABLE_PREUPDATE_HOOK", + "-DSQLITE_ENABLE_RTREE", + "-DSQLITE_ENABLE_SESSION", + "-DSQLITE_ENABLE_STMTVTAB", + "-DSQLITE_ENABLE_UNKNOWN_SQL_FUNCTION", + "-DSQLITE_ENABLE_COLUMN_METADATA", +]; + +#[cfg(all(not(feature = "bundled"), feature = "precompiled"))] +fn main() { + let path = std::env::current_dir().unwrap().join("library"); + let lib_path = path.to_str().unwrap(); + println!("cargo::rerun-if-changed=library"); + static_linking(lib_path); +} + +#[cfg(all(not(feature = "precompiled"), feature = "bundled"))] +fn main() { + const UPDATE_LIB_ENV: &str = "SQLITE_WASM_RS_UPDATE_PREBUILD"; + + println!("cargo::rerun-if-env-changed={UPDATE_LIB_ENV}"); + println!("cargo::rerun-if-changed=source"); + + let update_precompiled = std::env::var(UPDATE_LIB_ENV).is_ok(); + let output = std::env::var("OUT_DIR").expect("OUT_DIR env not set"); + + #[cfg(feature = "buildtime-bindgen")] + bindgen(&output); + + compile(&output, update_precompiled); + + if update_precompiled { + std::fs::copy( + format!("{output}/libsqlite3linked.a"), + "library/libsqlite3linked.a", + ) + .unwrap(); + std::fs::copy(format!("{output}/libsqlite3.a"), "library/libsqlite3.a").unwrap(); + + #[cfg(feature = "buildtime-bindgen")] + std::fs::copy( + format!("{output}/bindings.rs"), + "src/shim/libsqlite3/bindings.rs", + ) + .unwrap(); + } + static_linking(&output); +} + +#[cfg(all(not(feature = "bundled"), not(feature = "precompiled")))] +fn main() { + panic!( + " +must set `bundled` or `precompiled` feature +" + ); +} + +#[cfg(all(feature = "bundled", feature = "precompiled"))] +fn main() { + panic!( + " +`bundled` feature and `precompiled` feature can't use together +" + ); +} + +#[cfg(any(feature = "bundled", feature = "precompiled"))] +fn static_linking(lib_path: &str) { + println!("cargo:rustc-link-search=native={lib_path}"); + if cfg!(feature = "custom-libc") { + println!("cargo:rustc-link-lib=static=sqlite3"); + } else { + println!("cargo:rustc-link-lib=static=sqlite3linked"); + } +} + +#[cfg(all(feature = "bundled", feature = "buildtime-bindgen"))] +fn bindgen(output: &str) { + use bindgen::{ + callbacks::{IntKind, ParseCallbacks}, + RustEdition::Edition2021, + RustTarget, + }; + + #[derive(Debug)] + struct SqliteTypeChooser; + + impl ParseCallbacks for SqliteTypeChooser { + fn int_macro(&self, name: &str, _value: i64) -> Option { + if name == "SQLITE_SERIALIZE_NOCOPY" + || name.starts_with("SQLITE_DESERIALIZE_") + || name.starts_with("SQLITE_PREPARE_") + || name.starts_with("SQLITE_TRACE_") + { + Some(IntKind::UInt) + } else { + None + } + } + } + + let mut bindings = bindgen::builder() + .default_macro_constant_type(bindgen::MacroTypeVariation::Signed) + .disable_nested_struct_naming() + .generate_cstr(true) + .trust_clang_mangling(false) + .header("source/sqlite3.h") + .parse_callbacks(Box::new(SqliteTypeChooser)); + + bindings = bindings + .blocklist_function("sqlite3_auto_extension") + .raw_line( + r#"extern "C" { + pub fn sqlite3_auto_extension( + xEntryPoint: ::std::option::Option< + unsafe extern "C" fn( + db: *mut sqlite3, + pzErrMsg: *mut *mut ::std::os::raw::c_char, + _: *const sqlite3_api_routines, + ) -> ::std::os::raw::c_int, + >, + ) -> ::std::os::raw::c_int; +}"#, + ) + .blocklist_function("sqlite3_cancel_auto_extension") + .raw_line( + r#"extern "C" { + pub fn sqlite3_cancel_auto_extension( + xEntryPoint: ::std::option::Option< + unsafe extern "C" fn( + db: *mut sqlite3, + pzErrMsg: *mut *mut ::std::os::raw::c_char, + _: *const sqlite3_api_routines, + ) -> ::std::os::raw::c_int, + >, + ) -> ::std::os::raw::c_int; +}"#, + ) + // there is no dlopen on this platform. + .blocklist_function("sqlite3_load_extension") + .blocklist_function("sqlite3_enable_load_extension") + // DSQLITE_OMIT_DEPRECATED + .blocklist_function("sqlite3_profile") + .blocklist_function("sqlite3_trace") + // DSQLITE_THREADSAFE=0 + .blocklist_function("sqlite3_unlock_notify") + .blocklist_function(".*16.*") + .blocklist_function("sqlite3_close_v2") + .blocklist_function("sqlite3_create_collation") + .blocklist_function("sqlite3_create_function") + .blocklist_function("sqlite3_create_module") + .blocklist_function("sqlite3_prepare"); + + bindings = bindings.clang_args(FULL_FEATURED); + + bindings = bindings + .blocklist_function("sqlite3_vmprintf") + .blocklist_function("sqlite3_vsnprintf") + .blocklist_function("sqlite3_str_vappendf") + .blocklist_type("va_list") + .blocklist_item("__.*"); + + bindings = bindings + .rust_edition(Edition2021) + .rust_target(RustTarget::Stable_1_77) + // Unfortunately, we need to specify the target + // because `wasm32-unknown-unknown` cannot codegen anything. + .clang_arg("--target=x86_64-unknown-linux-gnu"); + + let bindings = bindings + .layout_tests(false) + .formatter(bindgen::Formatter::Prettyplease) + .generate() + .unwrap(); + + bindings + .write_to_file(format!("{output}/bindings.rs")) + .unwrap(); +} + +#[cfg(feature = "bundled")] +fn compile(output: &str, build_all: bool) { + use xshell::{cmd, Shell}; + + #[cfg(target_os = "windows")] + const CC: &str = "emcc.bat"; + #[cfg(target_os = "windows")] + const AR: &str = "emar.bat"; + + #[cfg(not(target_os = "windows"))] + const CC: &str = "emcc"; + #[cfg(not(target_os = "windows"))] + const AR: &str = "emar"; + + let sh = Shell::new().unwrap(); + + if cmd!(sh, "{CC} -v").read().is_err() { + panic!(" +It looks like you don't have the emscripten toolchain: https://emscripten.org/docs/getting_started/downloads.html, +or use the precompiled binaries via the `default-features = false` and `precompiled` feature flag. +"); + } + + if !cfg!(feature = "custom-libc") || build_all { + cmd!(sh, "{CC} {COMMON...} {FULL_FEATURED...} source/sqlite3.c source/wasm-shim.c -o {output}/sqlite3.o -I source -r -Oz -lc").read().unwrap(); + + cmd!( + sh, + "{AR} rcs {output}/libsqlite3linked.a {output}/sqlite3.o" + ) + .read() + .unwrap(); + } + + if cfg!(feature = "custom-libc") || build_all { + cmd!( + sh, + "{CC} {COMMON...} {FULL_FEATURED...} source/sqlite3.c -o {output}/sqlite3.o -r -Oz" + ) + .read() + .unwrap(); + + cmd!(sh, "{AR} rcs {output}/libsqlite3.a {output}/sqlite3.o") + .read() + .unwrap(); + } + + let _ = std::fs::remove_file(format!("{output}/sqlite3.o")); +} diff --git a/vendor/sqlite-wasm-rs/library/README.md b/vendor/sqlite-wasm-rs/library/README.md new file mode 100644 index 0000000..e26cda8 --- /dev/null +++ b/vendor/sqlite-wasm-rs/library/README.md @@ -0,0 +1,7 @@ +This folder stores precompiled products and runs compilation through Github Actions + +Precompile workflow: + +Change History: + +Actions: diff --git a/vendor/sqlite-wasm-rs/library/libsqlite3.a b/vendor/sqlite-wasm-rs/library/libsqlite3.a new file mode 100644 index 0000000..c8ad314 Binary files /dev/null and b/vendor/sqlite-wasm-rs/library/libsqlite3.a differ diff --git a/vendor/sqlite-wasm-rs/library/libsqlite3linked.a b/vendor/sqlite-wasm-rs/library/libsqlite3linked.a new file mode 100644 index 0000000..544492b Binary files /dev/null and b/vendor/sqlite-wasm-rs/library/libsqlite3linked.a differ diff --git a/vendor/sqlite-wasm-rs/src/fragile.rs b/vendor/sqlite-wasm-rs/src/fragile.rs new file mode 100644 index 0000000..61c878f --- /dev/null +++ b/vendor/sqlite-wasm-rs/src/fragile.rs @@ -0,0 +1,36 @@ +//! A [`FragileComfirmed`] wraps a non sendable `T` to be safely send to other threads. +//! +//! Once the value has been wrapped it can be sent to other threads but access +//! to the value on those threads will fail. + +use std::ops::{Deref, DerefMut}; + +use fragile::Fragile; + +pub struct FragileComfirmed { + fragile: Fragile, +} + +unsafe impl Send for FragileComfirmed {} +unsafe impl Sync for FragileComfirmed {} + +impl FragileComfirmed { + pub fn new(t: T) -> Self { + FragileComfirmed { + fragile: Fragile::new(t), + } + } +} + +impl Deref for FragileComfirmed { + type Target = T; + fn deref(&self) -> &Self::Target { + self.fragile.get() + } +} + +impl DerefMut for FragileComfirmed { + fn deref_mut(&mut self) -> &mut Self::Target { + self.fragile.get_mut() + } +} diff --git a/vendor/sqlite-wasm-rs/src/lib.rs b/vendor/sqlite-wasm-rs/src/lib.rs new file mode 100644 index 0000000..1c3c49b --- /dev/null +++ b/vendor/sqlite-wasm-rs/src/lib.rs @@ -0,0 +1,8 @@ +#![doc = include_str!("../README.md")] + +pub(crate) mod fragile; +pub(crate) mod locker; + +mod shim; + +pub use shim::export; diff --git a/vendor/sqlite-wasm-rs/src/locker.rs b/vendor/sqlite-wasm-rs/src/locker.rs new file mode 100644 index 0000000..d4e85d7 --- /dev/null +++ b/vendor/sqlite-wasm-rs/src/locker.rs @@ -0,0 +1,64 @@ +//! Wrap the Mutex and Rwlock lock. +//! +//! In a single thread, when atomics is not enabled, use the lock provided by the standard library. +//! There will be no deadlock unless there is a recursive call. +//! +//! In multithreading, when atomics is enabled, use parking_lot, it will not cause lock poisoning + +#[cfg(target_feature = "atomics")] +use parking_lot::{Mutex as Mutex0, RwLock as RwLock0}; + +#[cfg(target_feature = "atomics")] +pub use parking_lot::{MutexGuard, RwLockReadGuard, RwLockWriteGuard}; + +#[cfg(not(target_feature = "atomics"))] +use std::sync::{Mutex as Mutex0, RwLock as RwLock0}; + +#[cfg(not(target_feature = "atomics"))] +pub use std::sync::{MutexGuard, RwLockReadGuard, RwLockWriteGuard}; + +pub struct RwLock(RwLock0); + +impl RwLock { + pub fn new(t: T) -> Self { + Self(RwLock0::new(t)) + } + + #[cfg(target_feature = "atomics")] + pub fn read(&self) -> RwLockReadGuard<'_, T> { + self.0.read() + } + + #[cfg(not(target_feature = "atomics"))] + pub fn read(&self) -> RwLockReadGuard<'_, T> { + self.0.read().unwrap() + } + + #[cfg(target_feature = "atomics")] + pub fn write(&self) -> RwLockWriteGuard<'_, T> { + self.0.write() + } + + #[cfg(not(target_feature = "atomics"))] + pub fn write(&self) -> RwLockWriteGuard<'_, T> { + self.0.write().unwrap() + } +} + +pub struct Mutex(Mutex0); + +impl Mutex { + pub fn new(t: T) -> Self { + Self(Mutex0::new(t)) + } + + #[cfg(target_feature = "atomics")] + pub fn lock(&self) -> MutexGuard<'_, T> { + self.0.lock() + } + + #[cfg(not(target_feature = "atomics"))] + pub fn lock(&self) -> MutexGuard<'_, T> { + self.0.lock().unwrap() + } +} diff --git a/vendor/sqlite-wasm-rs/src/shim/impl.rs b/vendor/sqlite-wasm-rs/src/shim/impl.rs new file mode 100644 index 0000000..c6e5b8d --- /dev/null +++ b/vendor/sqlite-wasm-rs/src/shim/impl.rs @@ -0,0 +1,179 @@ +//! This module fills in the external functions needed to link to `sqlite.o` + +use js_sys::Date; +use wasm_bindgen::JsCast; +use web_sys::{ServiceWorkerGlobalScope, SharedWorkerGlobalScope, WorkerGlobalScope}; + +pub type time_t = std::os::raw::c_longlong; + +#[repr(C)] +pub struct tm { + pub tm_sec: std::os::raw::c_int, + pub tm_min: std::os::raw::c_int, + pub tm_hour: std::os::raw::c_int, + pub tm_mday: std::os::raw::c_int, + pub tm_mon: std::os::raw::c_int, + pub tm_year: std::os::raw::c_int, + pub tm_wday: std::os::raw::c_int, + pub tm_yday: std::os::raw::c_int, + pub tm_isdst: std::os::raw::c_int, + pub tm_gmtoff: std::os::raw::c_long, + pub tm_zone: *mut std::os::raw::c_char, +} + +const INT53_MAX: time_t = 9007199254740992; +const INT53_MIN: time_t = -9007199254740992; + +fn yday_from_date(date: &Date) -> u32 { + const MONTH_DAYS_LEAP_CUMULATIVE: [u32; 12] = + [0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335]; + + const MONTH_DAYS_REGULAR_CUMULATIVE: [u32; 12] = + [0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334]; + + let year = date.get_full_year(); + let leap = year % 4 == 0 && (year % 100 != 0 || year % 400 == 0); + + let month_days_cumulative = if leap { + MONTH_DAYS_LEAP_CUMULATIVE + } else { + MONTH_DAYS_REGULAR_CUMULATIVE + }; + month_days_cumulative[date.get_month() as usize] + date.get_date() - 1 +} + +/// https://github.com/sqlite/sqlite-wasm/blob/7c1b309c3bd07d8e6d92f82344108cebbd14f161/sqlite-wasm/jswasm/sqlite3-bundler-friendly.mjs#L3404 +#[no_mangle] +pub unsafe extern "C" fn rust_sqlite_wasm_shim_localtime_js(t: time_t, tm: *mut tm) { + assert!(!(INT53_MIN..=INT53_MAX).contains(&t), "wrong time range"); + + let date = Date::new(&(t * 1000).into()); + (*tm).tm_sec = date.get_seconds() as _; + (*tm).tm_min = date.get_minutes() as _; + (*tm).tm_hour = date.get_hours() as _; + (*tm).tm_mday = date.get_date() as _; + (*tm).tm_mon = date.get_month() as _; + (*tm).tm_year = (date.get_full_year() - 1900) as _; + (*tm).tm_wday = date.get_day() as _; + (*tm).tm_yday = yday_from_date(&date) as _; + + let start = Date::new_with_year_month_day(date.get_full_year(), 0, 1); + let summer_offset = + Date::new_with_year_month_day(date.get_full_year(), 6, 1).get_timezone_offset(); + let winter_offset = start.get_timezone_offset(); + (*tm).tm_isdst = i32::from( + summer_offset != winter_offset + && date.get_timezone_offset() == winter_offset.min(summer_offset), + ); + + (*tm).tm_gmtoff = (date.get_timezone_offset() * 60.0) as _; +} + +/// https://github.com/sqlite/sqlite-wasm/blob/7c1b309c3bd07d8e6d92f82344108cebbd14f161/sqlite-wasm/jswasm/sqlite3-bundler-friendly.mjs#L3460 +#[no_mangle] +pub unsafe extern "C" fn rust_sqlite_wasm_shim_tzset_js( + timezone: *mut std::os::raw::c_longlong, + daylight: *mut std::os::raw::c_int, + std_name: *mut std::os::raw::c_char, + dst_name: *mut std::os::raw::c_char, +) { + unsafe fn set_name(name: String, dst: *mut std::os::raw::c_char) { + for (idx, byte) in name.bytes().enumerate() { + *dst.add(idx) = byte as _; + } + *dst.add(name.len()) = 0; + } + + fn extract_zone(timezone_offset: f64) -> String { + let sign = if timezone_offset >= 0.0 { '-' } else { '+' }; + let offset = timezone_offset.abs(); + let hours = format!("{:02}", (offset / 60.0).floor() as i32); + let minutes = format!("{:02}", (offset % 60.0) as i32); + format!("UTC{sign}{hours}{minutes}") + } + + let current_year = Date::new_0().get_full_year(); + let winter = Date::new_with_year_month_day(current_year, 0, 1); + let summer = Date::new_with_year_month_day(current_year, 6, 1); + let winter_offset = winter.get_timezone_offset(); + let summer_offset = summer.get_timezone_offset(); + + let std_timezone_offset = winter_offset.max(summer_offset); + *timezone = (std_timezone_offset * 60.0) as _; + *daylight = i32::from(winter_offset != summer_offset); + + let winter_name = extract_zone(winter_offset); + let summer_name = extract_zone(summer_offset); + + if summer_offset < winter_offset { + set_name(winter_name, std_name); + set_name(summer_name, dst_name); + } else { + set_name(winter_name, dst_name); + set_name(summer_name, std_name); + } +} + +/// https://github.com/sqlite/sqlite-wasm/blob/7c1b309c3bd07d8e6d92f82344108cebbd14f161/sqlite-wasm/jswasm/sqlite3-bundler-friendly.mjs#L3496 +#[no_mangle] +pub unsafe extern "C" fn rust_sqlite_wasm_shim_emscripten_get_now() -> std::os::raw::c_double { + let performance = if let Some(window) = web_sys::window() { + window.performance() + } else if let Ok(worker) = js_sys::global().dyn_into::() { + worker.performance() + } else if let Ok(worker) = js_sys::global().dyn_into::() { + worker.performance() + } else if let Ok(worker) = js_sys::global().dyn_into::() { + worker.performance() + } else { + panic!("sqlite not run in main_thread or web worker"); + } + .expect("performance should be available"); + performance.now() +} + +#[no_mangle] +pub unsafe extern "C" fn sqlite3_os_init() -> std::os::raw::c_int { + super::vfs::memory::install_memory_vfs() +} + +// https://github.com/alexcrichton/dlmalloc-rs/blob/fb116603713825b43b113cc734bb7d663cb64be9/src/dlmalloc.rs#L141 +const ALIGN: usize = std::mem::size_of::() * 2; + +#[no_mangle] +pub unsafe extern "C" fn rust_sqlite_wasm_shim_malloc(size: usize) -> *mut u8 { + let layout = std::alloc::Layout::from_size_align_unchecked(size + ALIGN, ALIGN); + let ptr = std::alloc::alloc(layout); + + if ptr.is_null() { + return std::ptr::null_mut(); + } + *ptr.cast::() = size; + + ptr.add(ALIGN) +} + +#[no_mangle] +pub unsafe extern "C" fn rust_sqlite_wasm_shim_free(ptr: *mut u8) { + let ptr = ptr.sub(ALIGN); + let size = *(ptr.cast::()); + + let layout = std::alloc::Layout::from_size_align_unchecked(size + ALIGN, ALIGN); + std::alloc::dealloc(ptr, layout); +} + +#[no_mangle] +pub unsafe extern "C" fn rust_sqlite_wasm_shim_realloc(ptr: *mut u8, new_size: usize) -> *mut u8 { + let ptr = ptr.sub(ALIGN); + let size = *(ptr.cast::()); + + let layout = std::alloc::Layout::from_size_align_unchecked(size + ALIGN, ALIGN); + let ptr = std::alloc::realloc(ptr, layout, new_size + ALIGN); + + if ptr.is_null() { + return std::ptr::null_mut(); + } + *ptr.cast::() = new_size; + + ptr.add(ALIGN) +} diff --git a/vendor/sqlite-wasm-rs/src/shim/libsqlite3/bindings.rs b/vendor/sqlite-wasm-rs/src/shim/libsqlite3/bindings.rs new file mode 100644 index 0000000..9c20aad --- /dev/null +++ b/vendor/sqlite-wasm-rs/src/shim/libsqlite3/bindings.rs @@ -0,0 +1,3608 @@ +/* automatically generated by rust-bindgen 0.71.1 */ + +extern "C" { + pub fn sqlite3_auto_extension( + xEntryPoint: ::std::option::Option< + unsafe extern "C" fn( + db: *mut sqlite3, + pzErrMsg: *mut *mut ::std::os::raw::c_char, + _: *const sqlite3_api_routines, + ) -> ::std::os::raw::c_int, + >, + ) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn sqlite3_cancel_auto_extension( + xEntryPoint: ::std::option::Option< + unsafe extern "C" fn( + db: *mut sqlite3, + pzErrMsg: *mut *mut ::std::os::raw::c_char, + _: *const sqlite3_api_routines, + ) -> ::std::os::raw::c_int, + >, + ) -> ::std::os::raw::c_int; +} + +pub const SQLITE_VERSION: &::std::ffi::CStr = c"3.49.0"; +pub const SQLITE_VERSION_NUMBER: i32 = 3049000; +pub const SQLITE_SOURCE_ID: &::std::ffi::CStr = c"2025-02-06 11:55:18 4a7dd425dc2a0e5082a9049c9b4a9d4f199a71583d014c24b4cfe276c5a77cde"; +pub const SQLITE_OK: i32 = 0; +pub const SQLITE_ERROR: i32 = 1; +pub const SQLITE_INTERNAL: i32 = 2; +pub const SQLITE_PERM: i32 = 3; +pub const SQLITE_ABORT: i32 = 4; +pub const SQLITE_BUSY: i32 = 5; +pub const SQLITE_LOCKED: i32 = 6; +pub const SQLITE_NOMEM: i32 = 7; +pub const SQLITE_READONLY: i32 = 8; +pub const SQLITE_INTERRUPT: i32 = 9; +pub const SQLITE_IOERR: i32 = 10; +pub const SQLITE_CORRUPT: i32 = 11; +pub const SQLITE_NOTFOUND: i32 = 12; +pub const SQLITE_FULL: i32 = 13; +pub const SQLITE_CANTOPEN: i32 = 14; +pub const SQLITE_PROTOCOL: i32 = 15; +pub const SQLITE_EMPTY: i32 = 16; +pub const SQLITE_SCHEMA: i32 = 17; +pub const SQLITE_TOOBIG: i32 = 18; +pub const SQLITE_CONSTRAINT: i32 = 19; +pub const SQLITE_MISMATCH: i32 = 20; +pub const SQLITE_MISUSE: i32 = 21; +pub const SQLITE_NOLFS: i32 = 22; +pub const SQLITE_AUTH: i32 = 23; +pub const SQLITE_FORMAT: i32 = 24; +pub const SQLITE_RANGE: i32 = 25; +pub const SQLITE_NOTADB: i32 = 26; +pub const SQLITE_NOTICE: i32 = 27; +pub const SQLITE_WARNING: i32 = 28; +pub const SQLITE_ROW: i32 = 100; +pub const SQLITE_DONE: i32 = 101; +pub const SQLITE_ERROR_MISSING_COLLSEQ: i32 = 257; +pub const SQLITE_ERROR_RETRY: i32 = 513; +pub const SQLITE_ERROR_SNAPSHOT: i32 = 769; +pub const SQLITE_IOERR_READ: i32 = 266; +pub const SQLITE_IOERR_SHORT_READ: i32 = 522; +pub const SQLITE_IOERR_WRITE: i32 = 778; +pub const SQLITE_IOERR_FSYNC: i32 = 1034; +pub const SQLITE_IOERR_DIR_FSYNC: i32 = 1290; +pub const SQLITE_IOERR_TRUNCATE: i32 = 1546; +pub const SQLITE_IOERR_FSTAT: i32 = 1802; +pub const SQLITE_IOERR_UNLOCK: i32 = 2058; +pub const SQLITE_IOERR_RDLOCK: i32 = 2314; +pub const SQLITE_IOERR_DELETE: i32 = 2570; +pub const SQLITE_IOERR_BLOCKED: i32 = 2826; +pub const SQLITE_IOERR_NOMEM: i32 = 3082; +pub const SQLITE_IOERR_ACCESS: i32 = 3338; +pub const SQLITE_IOERR_CHECKRESERVEDLOCK: i32 = 3594; +pub const SQLITE_IOERR_LOCK: i32 = 3850; +pub const SQLITE_IOERR_CLOSE: i32 = 4106; +pub const SQLITE_IOERR_DIR_CLOSE: i32 = 4362; +pub const SQLITE_IOERR_SHMOPEN: i32 = 4618; +pub const SQLITE_IOERR_SHMSIZE: i32 = 4874; +pub const SQLITE_IOERR_SHMLOCK: i32 = 5130; +pub const SQLITE_IOERR_SHMMAP: i32 = 5386; +pub const SQLITE_IOERR_SEEK: i32 = 5642; +pub const SQLITE_IOERR_DELETE_NOENT: i32 = 5898; +pub const SQLITE_IOERR_MMAP: i32 = 6154; +pub const SQLITE_IOERR_GETTEMPPATH: i32 = 6410; +pub const SQLITE_IOERR_CONVPATH: i32 = 6666; +pub const SQLITE_IOERR_VNODE: i32 = 6922; +pub const SQLITE_IOERR_AUTH: i32 = 7178; +pub const SQLITE_IOERR_BEGIN_ATOMIC: i32 = 7434; +pub const SQLITE_IOERR_COMMIT_ATOMIC: i32 = 7690; +pub const SQLITE_IOERR_ROLLBACK_ATOMIC: i32 = 7946; +pub const SQLITE_IOERR_DATA: i32 = 8202; +pub const SQLITE_IOERR_CORRUPTFS: i32 = 8458; +pub const SQLITE_IOERR_IN_PAGE: i32 = 8714; +pub const SQLITE_LOCKED_SHAREDCACHE: i32 = 262; +pub const SQLITE_LOCKED_VTAB: i32 = 518; +pub const SQLITE_BUSY_RECOVERY: i32 = 261; +pub const SQLITE_BUSY_SNAPSHOT: i32 = 517; +pub const SQLITE_BUSY_TIMEOUT: i32 = 773; +pub const SQLITE_CANTOPEN_NOTEMPDIR: i32 = 270; +pub const SQLITE_CANTOPEN_ISDIR: i32 = 526; +pub const SQLITE_CANTOPEN_FULLPATH: i32 = 782; +pub const SQLITE_CANTOPEN_CONVPATH: i32 = 1038; +pub const SQLITE_CANTOPEN_DIRTYWAL: i32 = 1294; +pub const SQLITE_CANTOPEN_SYMLINK: i32 = 1550; +pub const SQLITE_CORRUPT_VTAB: i32 = 267; +pub const SQLITE_CORRUPT_SEQUENCE: i32 = 523; +pub const SQLITE_CORRUPT_INDEX: i32 = 779; +pub const SQLITE_READONLY_RECOVERY: i32 = 264; +pub const SQLITE_READONLY_CANTLOCK: i32 = 520; +pub const SQLITE_READONLY_ROLLBACK: i32 = 776; +pub const SQLITE_READONLY_DBMOVED: i32 = 1032; +pub const SQLITE_READONLY_CANTINIT: i32 = 1288; +pub const SQLITE_READONLY_DIRECTORY: i32 = 1544; +pub const SQLITE_ABORT_ROLLBACK: i32 = 516; +pub const SQLITE_CONSTRAINT_CHECK: i32 = 275; +pub const SQLITE_CONSTRAINT_COMMITHOOK: i32 = 531; +pub const SQLITE_CONSTRAINT_FOREIGNKEY: i32 = 787; +pub const SQLITE_CONSTRAINT_FUNCTION: i32 = 1043; +pub const SQLITE_CONSTRAINT_NOTNULL: i32 = 1299; +pub const SQLITE_CONSTRAINT_PRIMARYKEY: i32 = 1555; +pub const SQLITE_CONSTRAINT_TRIGGER: i32 = 1811; +pub const SQLITE_CONSTRAINT_UNIQUE: i32 = 2067; +pub const SQLITE_CONSTRAINT_VTAB: i32 = 2323; +pub const SQLITE_CONSTRAINT_ROWID: i32 = 2579; +pub const SQLITE_CONSTRAINT_PINNED: i32 = 2835; +pub const SQLITE_CONSTRAINT_DATATYPE: i32 = 3091; +pub const SQLITE_NOTICE_RECOVER_WAL: i32 = 283; +pub const SQLITE_NOTICE_RECOVER_ROLLBACK: i32 = 539; +pub const SQLITE_NOTICE_RBU: i32 = 795; +pub const SQLITE_WARNING_AUTOINDEX: i32 = 284; +pub const SQLITE_AUTH_USER: i32 = 279; +pub const SQLITE_OK_LOAD_PERMANENTLY: i32 = 256; +pub const SQLITE_OK_SYMLINK: i32 = 512; +pub const SQLITE_OPEN_READONLY: i32 = 1; +pub const SQLITE_OPEN_READWRITE: i32 = 2; +pub const SQLITE_OPEN_CREATE: i32 = 4; +pub const SQLITE_OPEN_DELETEONCLOSE: i32 = 8; +pub const SQLITE_OPEN_EXCLUSIVE: i32 = 16; +pub const SQLITE_OPEN_AUTOPROXY: i32 = 32; +pub const SQLITE_OPEN_URI: i32 = 64; +pub const SQLITE_OPEN_MEMORY: i32 = 128; +pub const SQLITE_OPEN_MAIN_DB: i32 = 256; +pub const SQLITE_OPEN_TEMP_DB: i32 = 512; +pub const SQLITE_OPEN_TRANSIENT_DB: i32 = 1024; +pub const SQLITE_OPEN_MAIN_JOURNAL: i32 = 2048; +pub const SQLITE_OPEN_TEMP_JOURNAL: i32 = 4096; +pub const SQLITE_OPEN_SUBJOURNAL: i32 = 8192; +pub const SQLITE_OPEN_SUPER_JOURNAL: i32 = 16384; +pub const SQLITE_OPEN_NOMUTEX: i32 = 32768; +pub const SQLITE_OPEN_FULLMUTEX: i32 = 65536; +pub const SQLITE_OPEN_SHAREDCACHE: i32 = 131072; +pub const SQLITE_OPEN_PRIVATECACHE: i32 = 262144; +pub const SQLITE_OPEN_WAL: i32 = 524288; +pub const SQLITE_OPEN_NOFOLLOW: i32 = 16777216; +pub const SQLITE_OPEN_EXRESCODE: i32 = 33554432; +pub const SQLITE_OPEN_MASTER_JOURNAL: i32 = 16384; +pub const SQLITE_IOCAP_ATOMIC: i32 = 1; +pub const SQLITE_IOCAP_ATOMIC512: i32 = 2; +pub const SQLITE_IOCAP_ATOMIC1K: i32 = 4; +pub const SQLITE_IOCAP_ATOMIC2K: i32 = 8; +pub const SQLITE_IOCAP_ATOMIC4K: i32 = 16; +pub const SQLITE_IOCAP_ATOMIC8K: i32 = 32; +pub const SQLITE_IOCAP_ATOMIC16K: i32 = 64; +pub const SQLITE_IOCAP_ATOMIC32K: i32 = 128; +pub const SQLITE_IOCAP_ATOMIC64K: i32 = 256; +pub const SQLITE_IOCAP_SAFE_APPEND: i32 = 512; +pub const SQLITE_IOCAP_SEQUENTIAL: i32 = 1024; +pub const SQLITE_IOCAP_UNDELETABLE_WHEN_OPEN: i32 = 2048; +pub const SQLITE_IOCAP_POWERSAFE_OVERWRITE: i32 = 4096; +pub const SQLITE_IOCAP_IMMUTABLE: i32 = 8192; +pub const SQLITE_IOCAP_BATCH_ATOMIC: i32 = 16384; +pub const SQLITE_IOCAP_SUBPAGE_READ: i32 = 32768; +pub const SQLITE_LOCK_NONE: i32 = 0; +pub const SQLITE_LOCK_SHARED: i32 = 1; +pub const SQLITE_LOCK_RESERVED: i32 = 2; +pub const SQLITE_LOCK_PENDING: i32 = 3; +pub const SQLITE_LOCK_EXCLUSIVE: i32 = 4; +pub const SQLITE_SYNC_NORMAL: i32 = 2; +pub const SQLITE_SYNC_FULL: i32 = 3; +pub const SQLITE_SYNC_DATAONLY: i32 = 16; +pub const SQLITE_FCNTL_LOCKSTATE: i32 = 1; +pub const SQLITE_FCNTL_GET_LOCKPROXYFILE: i32 = 2; +pub const SQLITE_FCNTL_SET_LOCKPROXYFILE: i32 = 3; +pub const SQLITE_FCNTL_LAST_ERRNO: i32 = 4; +pub const SQLITE_FCNTL_SIZE_HINT: i32 = 5; +pub const SQLITE_FCNTL_CHUNK_SIZE: i32 = 6; +pub const SQLITE_FCNTL_FILE_POINTER: i32 = 7; +pub const SQLITE_FCNTL_SYNC_OMITTED: i32 = 8; +pub const SQLITE_FCNTL_WIN32_AV_RETRY: i32 = 9; +pub const SQLITE_FCNTL_PERSIST_WAL: i32 = 10; +pub const SQLITE_FCNTL_OVERWRITE: i32 = 11; +pub const SQLITE_FCNTL_VFSNAME: i32 = 12; +pub const SQLITE_FCNTL_POWERSAFE_OVERWRITE: i32 = 13; +pub const SQLITE_FCNTL_PRAGMA: i32 = 14; +pub const SQLITE_FCNTL_BUSYHANDLER: i32 = 15; +pub const SQLITE_FCNTL_TEMPFILENAME: i32 = 16; +pub const SQLITE_FCNTL_MMAP_SIZE: i32 = 18; +pub const SQLITE_FCNTL_TRACE: i32 = 19; +pub const SQLITE_FCNTL_HAS_MOVED: i32 = 20; +pub const SQLITE_FCNTL_SYNC: i32 = 21; +pub const SQLITE_FCNTL_COMMIT_PHASETWO: i32 = 22; +pub const SQLITE_FCNTL_WIN32_SET_HANDLE: i32 = 23; +pub const SQLITE_FCNTL_WAL_BLOCK: i32 = 24; +pub const SQLITE_FCNTL_ZIPVFS: i32 = 25; +pub const SQLITE_FCNTL_RBU: i32 = 26; +pub const SQLITE_FCNTL_VFS_POINTER: i32 = 27; +pub const SQLITE_FCNTL_JOURNAL_POINTER: i32 = 28; +pub const SQLITE_FCNTL_WIN32_GET_HANDLE: i32 = 29; +pub const SQLITE_FCNTL_PDB: i32 = 30; +pub const SQLITE_FCNTL_BEGIN_ATOMIC_WRITE: i32 = 31; +pub const SQLITE_FCNTL_COMMIT_ATOMIC_WRITE: i32 = 32; +pub const SQLITE_FCNTL_ROLLBACK_ATOMIC_WRITE: i32 = 33; +pub const SQLITE_FCNTL_LOCK_TIMEOUT: i32 = 34; +pub const SQLITE_FCNTL_DATA_VERSION: i32 = 35; +pub const SQLITE_FCNTL_SIZE_LIMIT: i32 = 36; +pub const SQLITE_FCNTL_CKPT_DONE: i32 = 37; +pub const SQLITE_FCNTL_RESERVE_BYTES: i32 = 38; +pub const SQLITE_FCNTL_CKPT_START: i32 = 39; +pub const SQLITE_FCNTL_EXTERNAL_READER: i32 = 40; +pub const SQLITE_FCNTL_CKSM_FILE: i32 = 41; +pub const SQLITE_FCNTL_RESET_CACHE: i32 = 42; +pub const SQLITE_FCNTL_NULL_IO: i32 = 43; +pub const SQLITE_GET_LOCKPROXYFILE: i32 = 2; +pub const SQLITE_SET_LOCKPROXYFILE: i32 = 3; +pub const SQLITE_LAST_ERRNO: i32 = 4; +pub const SQLITE_ACCESS_EXISTS: i32 = 0; +pub const SQLITE_ACCESS_READWRITE: i32 = 1; +pub const SQLITE_ACCESS_READ: i32 = 2; +pub const SQLITE_SHM_UNLOCK: i32 = 1; +pub const SQLITE_SHM_LOCK: i32 = 2; +pub const SQLITE_SHM_SHARED: i32 = 4; +pub const SQLITE_SHM_EXCLUSIVE: i32 = 8; +pub const SQLITE_SHM_NLOCK: i32 = 8; +pub const SQLITE_CONFIG_SINGLETHREAD: i32 = 1; +pub const SQLITE_CONFIG_MULTITHREAD: i32 = 2; +pub const SQLITE_CONFIG_SERIALIZED: i32 = 3; +pub const SQLITE_CONFIG_MALLOC: i32 = 4; +pub const SQLITE_CONFIG_GETMALLOC: i32 = 5; +pub const SQLITE_CONFIG_SCRATCH: i32 = 6; +pub const SQLITE_CONFIG_PAGECACHE: i32 = 7; +pub const SQLITE_CONFIG_HEAP: i32 = 8; +pub const SQLITE_CONFIG_MEMSTATUS: i32 = 9; +pub const SQLITE_CONFIG_MUTEX: i32 = 10; +pub const SQLITE_CONFIG_GETMUTEX: i32 = 11; +pub const SQLITE_CONFIG_LOOKASIDE: i32 = 13; +pub const SQLITE_CONFIG_PCACHE: i32 = 14; +pub const SQLITE_CONFIG_GETPCACHE: i32 = 15; +pub const SQLITE_CONFIG_LOG: i32 = 16; +pub const SQLITE_CONFIG_URI: i32 = 17; +pub const SQLITE_CONFIG_PCACHE2: i32 = 18; +pub const SQLITE_CONFIG_GETPCACHE2: i32 = 19; +pub const SQLITE_CONFIG_COVERING_INDEX_SCAN: i32 = 20; +pub const SQLITE_CONFIG_SQLLOG: i32 = 21; +pub const SQLITE_CONFIG_MMAP_SIZE: i32 = 22; +pub const SQLITE_CONFIG_WIN32_HEAPSIZE: i32 = 23; +pub const SQLITE_CONFIG_PCACHE_HDRSZ: i32 = 24; +pub const SQLITE_CONFIG_PMASZ: i32 = 25; +pub const SQLITE_CONFIG_STMTJRNL_SPILL: i32 = 26; +pub const SQLITE_CONFIG_SMALL_MALLOC: i32 = 27; +pub const SQLITE_CONFIG_SORTERREF_SIZE: i32 = 28; +pub const SQLITE_CONFIG_MEMDB_MAXSIZE: i32 = 29; +pub const SQLITE_CONFIG_ROWID_IN_VIEW: i32 = 30; +pub const SQLITE_DBCONFIG_MAINDBNAME: i32 = 1000; +pub const SQLITE_DBCONFIG_LOOKASIDE: i32 = 1001; +pub const SQLITE_DBCONFIG_ENABLE_FKEY: i32 = 1002; +pub const SQLITE_DBCONFIG_ENABLE_TRIGGER: i32 = 1003; +pub const SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER: i32 = 1004; +pub const SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION: i32 = 1005; +pub const SQLITE_DBCONFIG_NO_CKPT_ON_CLOSE: i32 = 1006; +pub const SQLITE_DBCONFIG_ENABLE_QPSG: i32 = 1007; +pub const SQLITE_DBCONFIG_TRIGGER_EQP: i32 = 1008; +pub const SQLITE_DBCONFIG_RESET_DATABASE: i32 = 1009; +pub const SQLITE_DBCONFIG_DEFENSIVE: i32 = 1010; +pub const SQLITE_DBCONFIG_WRITABLE_SCHEMA: i32 = 1011; +pub const SQLITE_DBCONFIG_LEGACY_ALTER_TABLE: i32 = 1012; +pub const SQLITE_DBCONFIG_DQS_DML: i32 = 1013; +pub const SQLITE_DBCONFIG_DQS_DDL: i32 = 1014; +pub const SQLITE_DBCONFIG_ENABLE_VIEW: i32 = 1015; +pub const SQLITE_DBCONFIG_LEGACY_FILE_FORMAT: i32 = 1016; +pub const SQLITE_DBCONFIG_TRUSTED_SCHEMA: i32 = 1017; +pub const SQLITE_DBCONFIG_STMT_SCANSTATUS: i32 = 1018; +pub const SQLITE_DBCONFIG_REVERSE_SCANORDER: i32 = 1019; +pub const SQLITE_DBCONFIG_ENABLE_ATTACH_CREATE: i32 = 1020; +pub const SQLITE_DBCONFIG_ENABLE_ATTACH_WRITE: i32 = 1021; +pub const SQLITE_DBCONFIG_ENABLE_COMMENTS: i32 = 1022; +pub const SQLITE_DBCONFIG_MAX: i32 = 1022; +pub const SQLITE_DENY: i32 = 1; +pub const SQLITE_IGNORE: i32 = 2; +pub const SQLITE_CREATE_INDEX: i32 = 1; +pub const SQLITE_CREATE_TABLE: i32 = 2; +pub const SQLITE_CREATE_TEMP_INDEX: i32 = 3; +pub const SQLITE_CREATE_TEMP_TABLE: i32 = 4; +pub const SQLITE_CREATE_TEMP_TRIGGER: i32 = 5; +pub const SQLITE_CREATE_TEMP_VIEW: i32 = 6; +pub const SQLITE_CREATE_TRIGGER: i32 = 7; +pub const SQLITE_CREATE_VIEW: i32 = 8; +pub const SQLITE_DELETE: i32 = 9; +pub const SQLITE_DROP_INDEX: i32 = 10; +pub const SQLITE_DROP_TABLE: i32 = 11; +pub const SQLITE_DROP_TEMP_INDEX: i32 = 12; +pub const SQLITE_DROP_TEMP_TABLE: i32 = 13; +pub const SQLITE_DROP_TEMP_TRIGGER: i32 = 14; +pub const SQLITE_DROP_TEMP_VIEW: i32 = 15; +pub const SQLITE_DROP_TRIGGER: i32 = 16; +pub const SQLITE_DROP_VIEW: i32 = 17; +pub const SQLITE_INSERT: i32 = 18; +pub const SQLITE_PRAGMA: i32 = 19; +pub const SQLITE_READ: i32 = 20; +pub const SQLITE_SELECT: i32 = 21; +pub const SQLITE_TRANSACTION: i32 = 22; +pub const SQLITE_UPDATE: i32 = 23; +pub const SQLITE_ATTACH: i32 = 24; +pub const SQLITE_DETACH: i32 = 25; +pub const SQLITE_ALTER_TABLE: i32 = 26; +pub const SQLITE_REINDEX: i32 = 27; +pub const SQLITE_ANALYZE: i32 = 28; +pub const SQLITE_CREATE_VTABLE: i32 = 29; +pub const SQLITE_DROP_VTABLE: i32 = 30; +pub const SQLITE_FUNCTION: i32 = 31; +pub const SQLITE_SAVEPOINT: i32 = 32; +pub const SQLITE_COPY: i32 = 0; +pub const SQLITE_RECURSIVE: i32 = 33; +pub const SQLITE_TRACE_STMT: ::std::os::raw::c_uint = 1; +pub const SQLITE_TRACE_PROFILE: ::std::os::raw::c_uint = 2; +pub const SQLITE_TRACE_ROW: ::std::os::raw::c_uint = 4; +pub const SQLITE_TRACE_CLOSE: ::std::os::raw::c_uint = 8; +pub const SQLITE_LIMIT_LENGTH: i32 = 0; +pub const SQLITE_LIMIT_SQL_LENGTH: i32 = 1; +pub const SQLITE_LIMIT_COLUMN: i32 = 2; +pub const SQLITE_LIMIT_EXPR_DEPTH: i32 = 3; +pub const SQLITE_LIMIT_COMPOUND_SELECT: i32 = 4; +pub const SQLITE_LIMIT_VDBE_OP: i32 = 5; +pub const SQLITE_LIMIT_FUNCTION_ARG: i32 = 6; +pub const SQLITE_LIMIT_ATTACHED: i32 = 7; +pub const SQLITE_LIMIT_LIKE_PATTERN_LENGTH: i32 = 8; +pub const SQLITE_LIMIT_VARIABLE_NUMBER: i32 = 9; +pub const SQLITE_LIMIT_TRIGGER_DEPTH: i32 = 10; +pub const SQLITE_LIMIT_WORKER_THREADS: i32 = 11; +pub const SQLITE_PREPARE_PERSISTENT: ::std::os::raw::c_uint = 1; +pub const SQLITE_PREPARE_NORMALIZE: ::std::os::raw::c_uint = 2; +pub const SQLITE_PREPARE_NO_VTAB: ::std::os::raw::c_uint = 4; +pub const SQLITE_PREPARE_DONT_LOG: ::std::os::raw::c_uint = 16; +pub const SQLITE_INTEGER: i32 = 1; +pub const SQLITE_FLOAT: i32 = 2; +pub const SQLITE_BLOB: i32 = 4; +pub const SQLITE_NULL: i32 = 5; +pub const SQLITE_TEXT: i32 = 3; +pub const SQLITE3_TEXT: i32 = 3; +pub const SQLITE_UTF8: i32 = 1; +pub const SQLITE_UTF16LE: i32 = 2; +pub const SQLITE_UTF16BE: i32 = 3; +pub const SQLITE_UTF16: i32 = 4; +pub const SQLITE_ANY: i32 = 5; +pub const SQLITE_UTF16_ALIGNED: i32 = 8; +pub const SQLITE_DETERMINISTIC: i32 = 2048; +pub const SQLITE_DIRECTONLY: i32 = 524288; +pub const SQLITE_SUBTYPE: i32 = 1048576; +pub const SQLITE_INNOCUOUS: i32 = 2097152; +pub const SQLITE_RESULT_SUBTYPE: i32 = 16777216; +pub const SQLITE_SELFORDER1: i32 = 33554432; +pub const SQLITE_WIN32_DATA_DIRECTORY_TYPE: i32 = 1; +pub const SQLITE_WIN32_TEMP_DIRECTORY_TYPE: i32 = 2; +pub const SQLITE_TXN_NONE: i32 = 0; +pub const SQLITE_TXN_READ: i32 = 1; +pub const SQLITE_TXN_WRITE: i32 = 2; +pub const SQLITE_INDEX_SCAN_UNIQUE: i32 = 1; +pub const SQLITE_INDEX_SCAN_HEX: i32 = 2; +pub const SQLITE_INDEX_CONSTRAINT_EQ: i32 = 2; +pub const SQLITE_INDEX_CONSTRAINT_GT: i32 = 4; +pub const SQLITE_INDEX_CONSTRAINT_LE: i32 = 8; +pub const SQLITE_INDEX_CONSTRAINT_LT: i32 = 16; +pub const SQLITE_INDEX_CONSTRAINT_GE: i32 = 32; +pub const SQLITE_INDEX_CONSTRAINT_MATCH: i32 = 64; +pub const SQLITE_INDEX_CONSTRAINT_LIKE: i32 = 65; +pub const SQLITE_INDEX_CONSTRAINT_GLOB: i32 = 66; +pub const SQLITE_INDEX_CONSTRAINT_REGEXP: i32 = 67; +pub const SQLITE_INDEX_CONSTRAINT_NE: i32 = 68; +pub const SQLITE_INDEX_CONSTRAINT_ISNOT: i32 = 69; +pub const SQLITE_INDEX_CONSTRAINT_ISNOTNULL: i32 = 70; +pub const SQLITE_INDEX_CONSTRAINT_ISNULL: i32 = 71; +pub const SQLITE_INDEX_CONSTRAINT_IS: i32 = 72; +pub const SQLITE_INDEX_CONSTRAINT_LIMIT: i32 = 73; +pub const SQLITE_INDEX_CONSTRAINT_OFFSET: i32 = 74; +pub const SQLITE_INDEX_CONSTRAINT_FUNCTION: i32 = 150; +pub const SQLITE_MUTEX_FAST: i32 = 0; +pub const SQLITE_MUTEX_RECURSIVE: i32 = 1; +pub const SQLITE_MUTEX_STATIC_MAIN: i32 = 2; +pub const SQLITE_MUTEX_STATIC_MEM: i32 = 3; +pub const SQLITE_MUTEX_STATIC_MEM2: i32 = 4; +pub const SQLITE_MUTEX_STATIC_OPEN: i32 = 4; +pub const SQLITE_MUTEX_STATIC_PRNG: i32 = 5; +pub const SQLITE_MUTEX_STATIC_LRU: i32 = 6; +pub const SQLITE_MUTEX_STATIC_LRU2: i32 = 7; +pub const SQLITE_MUTEX_STATIC_PMEM: i32 = 7; +pub const SQLITE_MUTEX_STATIC_APP1: i32 = 8; +pub const SQLITE_MUTEX_STATIC_APP2: i32 = 9; +pub const SQLITE_MUTEX_STATIC_APP3: i32 = 10; +pub const SQLITE_MUTEX_STATIC_VFS1: i32 = 11; +pub const SQLITE_MUTEX_STATIC_VFS2: i32 = 12; +pub const SQLITE_MUTEX_STATIC_VFS3: i32 = 13; +pub const SQLITE_MUTEX_STATIC_MASTER: i32 = 2; +pub const SQLITE_TESTCTRL_FIRST: i32 = 5; +pub const SQLITE_TESTCTRL_PRNG_SAVE: i32 = 5; +pub const SQLITE_TESTCTRL_PRNG_RESTORE: i32 = 6; +pub const SQLITE_TESTCTRL_PRNG_RESET: i32 = 7; +pub const SQLITE_TESTCTRL_FK_NO_ACTION: i32 = 7; +pub const SQLITE_TESTCTRL_BITVEC_TEST: i32 = 8; +pub const SQLITE_TESTCTRL_FAULT_INSTALL: i32 = 9; +pub const SQLITE_TESTCTRL_BENIGN_MALLOC_HOOKS: i32 = 10; +pub const SQLITE_TESTCTRL_PENDING_BYTE: i32 = 11; +pub const SQLITE_TESTCTRL_ASSERT: i32 = 12; +pub const SQLITE_TESTCTRL_ALWAYS: i32 = 13; +pub const SQLITE_TESTCTRL_RESERVE: i32 = 14; +pub const SQLITE_TESTCTRL_JSON_SELFCHECK: i32 = 14; +pub const SQLITE_TESTCTRL_OPTIMIZATIONS: i32 = 15; +pub const SQLITE_TESTCTRL_ISKEYWORD: i32 = 16; +pub const SQLITE_TESTCTRL_GETOPT: i32 = 16; +pub const SQLITE_TESTCTRL_SCRATCHMALLOC: i32 = 17; +pub const SQLITE_TESTCTRL_INTERNAL_FUNCTIONS: i32 = 17; +pub const SQLITE_TESTCTRL_LOCALTIME_FAULT: i32 = 18; +pub const SQLITE_TESTCTRL_EXPLAIN_STMT: i32 = 19; +pub const SQLITE_TESTCTRL_ONCE_RESET_THRESHOLD: i32 = 19; +pub const SQLITE_TESTCTRL_NEVER_CORRUPT: i32 = 20; +pub const SQLITE_TESTCTRL_VDBE_COVERAGE: i32 = 21; +pub const SQLITE_TESTCTRL_BYTEORDER: i32 = 22; +pub const SQLITE_TESTCTRL_ISINIT: i32 = 23; +pub const SQLITE_TESTCTRL_SORTER_MMAP: i32 = 24; +pub const SQLITE_TESTCTRL_IMPOSTER: i32 = 25; +pub const SQLITE_TESTCTRL_PARSER_COVERAGE: i32 = 26; +pub const SQLITE_TESTCTRL_RESULT_INTREAL: i32 = 27; +pub const SQLITE_TESTCTRL_PRNG_SEED: i32 = 28; +pub const SQLITE_TESTCTRL_EXTRA_SCHEMA_CHECKS: i32 = 29; +pub const SQLITE_TESTCTRL_SEEK_COUNT: i32 = 30; +pub const SQLITE_TESTCTRL_TRACEFLAGS: i32 = 31; +pub const SQLITE_TESTCTRL_TUNE: i32 = 32; +pub const SQLITE_TESTCTRL_LOGEST: i32 = 33; +pub const SQLITE_TESTCTRL_USELONGDOUBLE: i32 = 34; +pub const SQLITE_TESTCTRL_LAST: i32 = 34; +pub const SQLITE_STATUS_MEMORY_USED: i32 = 0; +pub const SQLITE_STATUS_PAGECACHE_USED: i32 = 1; +pub const SQLITE_STATUS_PAGECACHE_OVERFLOW: i32 = 2; +pub const SQLITE_STATUS_SCRATCH_USED: i32 = 3; +pub const SQLITE_STATUS_SCRATCH_OVERFLOW: i32 = 4; +pub const SQLITE_STATUS_MALLOC_SIZE: i32 = 5; +pub const SQLITE_STATUS_PARSER_STACK: i32 = 6; +pub const SQLITE_STATUS_PAGECACHE_SIZE: i32 = 7; +pub const SQLITE_STATUS_SCRATCH_SIZE: i32 = 8; +pub const SQLITE_STATUS_MALLOC_COUNT: i32 = 9; +pub const SQLITE_DBSTATUS_LOOKASIDE_USED: i32 = 0; +pub const SQLITE_DBSTATUS_CACHE_USED: i32 = 1; +pub const SQLITE_DBSTATUS_SCHEMA_USED: i32 = 2; +pub const SQLITE_DBSTATUS_STMT_USED: i32 = 3; +pub const SQLITE_DBSTATUS_LOOKASIDE_HIT: i32 = 4; +pub const SQLITE_DBSTATUS_LOOKASIDE_MISS_SIZE: i32 = 5; +pub const SQLITE_DBSTATUS_LOOKASIDE_MISS_FULL: i32 = 6; +pub const SQLITE_DBSTATUS_CACHE_HIT: i32 = 7; +pub const SQLITE_DBSTATUS_CACHE_MISS: i32 = 8; +pub const SQLITE_DBSTATUS_CACHE_WRITE: i32 = 9; +pub const SQLITE_DBSTATUS_DEFERRED_FKS: i32 = 10; +pub const SQLITE_DBSTATUS_CACHE_USED_SHARED: i32 = 11; +pub const SQLITE_DBSTATUS_CACHE_SPILL: i32 = 12; +pub const SQLITE_DBSTATUS_MAX: i32 = 12; +pub const SQLITE_STMTSTATUS_FULLSCAN_STEP: i32 = 1; +pub const SQLITE_STMTSTATUS_SORT: i32 = 2; +pub const SQLITE_STMTSTATUS_AUTOINDEX: i32 = 3; +pub const SQLITE_STMTSTATUS_VM_STEP: i32 = 4; +pub const SQLITE_STMTSTATUS_REPREPARE: i32 = 5; +pub const SQLITE_STMTSTATUS_RUN: i32 = 6; +pub const SQLITE_STMTSTATUS_FILTER_MISS: i32 = 7; +pub const SQLITE_STMTSTATUS_FILTER_HIT: i32 = 8; +pub const SQLITE_STMTSTATUS_MEMUSED: i32 = 99; +pub const SQLITE_CHECKPOINT_PASSIVE: i32 = 0; +pub const SQLITE_CHECKPOINT_FULL: i32 = 1; +pub const SQLITE_CHECKPOINT_RESTART: i32 = 2; +pub const SQLITE_CHECKPOINT_TRUNCATE: i32 = 3; +pub const SQLITE_VTAB_CONSTRAINT_SUPPORT: i32 = 1; +pub const SQLITE_VTAB_INNOCUOUS: i32 = 2; +pub const SQLITE_VTAB_DIRECTONLY: i32 = 3; +pub const SQLITE_VTAB_USES_ALL_SCHEMAS: i32 = 4; +pub const SQLITE_ROLLBACK: i32 = 1; +pub const SQLITE_FAIL: i32 = 3; +pub const SQLITE_REPLACE: i32 = 5; +pub const SQLITE_SCANSTAT_NLOOP: i32 = 0; +pub const SQLITE_SCANSTAT_NVISIT: i32 = 1; +pub const SQLITE_SCANSTAT_EST: i32 = 2; +pub const SQLITE_SCANSTAT_NAME: i32 = 3; +pub const SQLITE_SCANSTAT_EXPLAIN: i32 = 4; +pub const SQLITE_SCANSTAT_SELECTID: i32 = 5; +pub const SQLITE_SCANSTAT_PARENTID: i32 = 6; +pub const SQLITE_SCANSTAT_NCYCLE: i32 = 7; +pub const SQLITE_SCANSTAT_COMPLEX: i32 = 1; +pub const SQLITE_SERIALIZE_NOCOPY: ::std::os::raw::c_uint = 1; +pub const SQLITE_DESERIALIZE_FREEONCLOSE: ::std::os::raw::c_uint = 1; +pub const SQLITE_DESERIALIZE_RESIZEABLE: ::std::os::raw::c_uint = 2; +pub const SQLITE_DESERIALIZE_READONLY: ::std::os::raw::c_uint = 4; +pub const NOT_WITHIN: i32 = 0; +pub const PARTLY_WITHIN: i32 = 1; +pub const FULLY_WITHIN: i32 = 2; +pub const SQLITE_SESSION_OBJCONFIG_SIZE: i32 = 1; +pub const SQLITE_SESSION_OBJCONFIG_ROWID: i32 = 2; +pub const SQLITE_CHANGESETSTART_INVERT: i32 = 2; +pub const SQLITE_CHANGESETAPPLY_NOSAVEPOINT: i32 = 1; +pub const SQLITE_CHANGESETAPPLY_INVERT: i32 = 2; +pub const SQLITE_CHANGESETAPPLY_IGNORENOOP: i32 = 4; +pub const SQLITE_CHANGESETAPPLY_FKNOACTION: i32 = 8; +pub const SQLITE_CHANGESET_DATA: i32 = 1; +pub const SQLITE_CHANGESET_NOTFOUND: i32 = 2; +pub const SQLITE_CHANGESET_CONFLICT: i32 = 3; +pub const SQLITE_CHANGESET_CONSTRAINT: i32 = 4; +pub const SQLITE_CHANGESET_FOREIGN_KEY: i32 = 5; +pub const SQLITE_CHANGESET_OMIT: i32 = 0; +pub const SQLITE_CHANGESET_REPLACE: i32 = 1; +pub const SQLITE_CHANGESET_ABORT: i32 = 2; +pub const SQLITE_SESSION_CONFIG_STRMSIZE: i32 = 1; +pub const FTS5_TOKENIZE_QUERY: i32 = 1; +pub const FTS5_TOKENIZE_PREFIX: i32 = 2; +pub const FTS5_TOKENIZE_DOCUMENT: i32 = 4; +pub const FTS5_TOKENIZE_AUX: i32 = 8; +pub const FTS5_TOKEN_COLOCATED: i32 = 1; +extern "C" { + pub static sqlite3_version: [::std::os::raw::c_char; 0usize]; +} +extern "C" { + pub fn sqlite3_libversion() -> *const ::std::os::raw::c_char; +} +extern "C" { + pub fn sqlite3_sourceid() -> *const ::std::os::raw::c_char; +} +extern "C" { + pub fn sqlite3_libversion_number() -> ::std::os::raw::c_int; +} +extern "C" { + pub fn sqlite3_compileoption_used( + zOptName: *const ::std::os::raw::c_char, + ) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn sqlite3_compileoption_get( + N: ::std::os::raw::c_int, + ) -> *const ::std::os::raw::c_char; +} +extern "C" { + pub fn sqlite3_threadsafe() -> ::std::os::raw::c_int; +} +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct sqlite3 { + _unused: [u8; 0], +} +pub type sqlite_int64 = ::std::os::raw::c_longlong; +pub type sqlite_uint64 = ::std::os::raw::c_ulonglong; +pub type sqlite3_int64 = sqlite_int64; +pub type sqlite3_uint64 = sqlite_uint64; +extern "C" { + pub fn sqlite3_close(arg1: *mut sqlite3) -> ::std::os::raw::c_int; +} +pub type sqlite3_callback = ::std::option::Option< + unsafe extern "C" fn( + arg1: *mut ::std::os::raw::c_void, + arg2: ::std::os::raw::c_int, + arg3: *mut *mut ::std::os::raw::c_char, + arg4: *mut *mut ::std::os::raw::c_char, + ) -> ::std::os::raw::c_int, +>; +extern "C" { + pub fn sqlite3_exec( + arg1: *mut sqlite3, + sql: *const ::std::os::raw::c_char, + callback: ::std::option::Option< + unsafe extern "C" fn( + arg1: *mut ::std::os::raw::c_void, + arg2: ::std::os::raw::c_int, + arg3: *mut *mut ::std::os::raw::c_char, + arg4: *mut *mut ::std::os::raw::c_char, + ) -> ::std::os::raw::c_int, + >, + arg2: *mut ::std::os::raw::c_void, + errmsg: *mut *mut ::std::os::raw::c_char, + ) -> ::std::os::raw::c_int; +} +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct sqlite3_file { + pub pMethods: *const sqlite3_io_methods, +} +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct sqlite3_io_methods { + pub iVersion: ::std::os::raw::c_int, + pub xClose: ::std::option::Option< + unsafe extern "C" fn(arg1: *mut sqlite3_file) -> ::std::os::raw::c_int, + >, + pub xRead: ::std::option::Option< + unsafe extern "C" fn( + arg1: *mut sqlite3_file, + arg2: *mut ::std::os::raw::c_void, + iAmt: ::std::os::raw::c_int, + iOfst: sqlite3_int64, + ) -> ::std::os::raw::c_int, + >, + pub xWrite: ::std::option::Option< + unsafe extern "C" fn( + arg1: *mut sqlite3_file, + arg2: *const ::std::os::raw::c_void, + iAmt: ::std::os::raw::c_int, + iOfst: sqlite3_int64, + ) -> ::std::os::raw::c_int, + >, + pub xTruncate: ::std::option::Option< + unsafe extern "C" fn( + arg1: *mut sqlite3_file, + size: sqlite3_int64, + ) -> ::std::os::raw::c_int, + >, + pub xSync: ::std::option::Option< + unsafe extern "C" fn( + arg1: *mut sqlite3_file, + flags: ::std::os::raw::c_int, + ) -> ::std::os::raw::c_int, + >, + pub xFileSize: ::std::option::Option< + unsafe extern "C" fn( + arg1: *mut sqlite3_file, + pSize: *mut sqlite3_int64, + ) -> ::std::os::raw::c_int, + >, + pub xLock: ::std::option::Option< + unsafe extern "C" fn( + arg1: *mut sqlite3_file, + arg2: ::std::os::raw::c_int, + ) -> ::std::os::raw::c_int, + >, + pub xUnlock: ::std::option::Option< + unsafe extern "C" fn( + arg1: *mut sqlite3_file, + arg2: ::std::os::raw::c_int, + ) -> ::std::os::raw::c_int, + >, + pub xCheckReservedLock: ::std::option::Option< + unsafe extern "C" fn( + arg1: *mut sqlite3_file, + pResOut: *mut ::std::os::raw::c_int, + ) -> ::std::os::raw::c_int, + >, + pub xFileControl: ::std::option::Option< + unsafe extern "C" fn( + arg1: *mut sqlite3_file, + op: ::std::os::raw::c_int, + pArg: *mut ::std::os::raw::c_void, + ) -> ::std::os::raw::c_int, + >, + pub xSectorSize: ::std::option::Option< + unsafe extern "C" fn(arg1: *mut sqlite3_file) -> ::std::os::raw::c_int, + >, + pub xDeviceCharacteristics: ::std::option::Option< + unsafe extern "C" fn(arg1: *mut sqlite3_file) -> ::std::os::raw::c_int, + >, + pub xShmMap: ::std::option::Option< + unsafe extern "C" fn( + arg1: *mut sqlite3_file, + iPg: ::std::os::raw::c_int, + pgsz: ::std::os::raw::c_int, + arg2: ::std::os::raw::c_int, + arg3: *mut *mut ::std::os::raw::c_void, + ) -> ::std::os::raw::c_int, + >, + pub xShmLock: ::std::option::Option< + unsafe extern "C" fn( + arg1: *mut sqlite3_file, + offset: ::std::os::raw::c_int, + n: ::std::os::raw::c_int, + flags: ::std::os::raw::c_int, + ) -> ::std::os::raw::c_int, + >, + pub xShmBarrier: ::std::option::Option< + unsafe extern "C" fn(arg1: *mut sqlite3_file), + >, + pub xShmUnmap: ::std::option::Option< + unsafe extern "C" fn( + arg1: *mut sqlite3_file, + deleteFlag: ::std::os::raw::c_int, + ) -> ::std::os::raw::c_int, + >, + pub xFetch: ::std::option::Option< + unsafe extern "C" fn( + arg1: *mut sqlite3_file, + iOfst: sqlite3_int64, + iAmt: ::std::os::raw::c_int, + pp: *mut *mut ::std::os::raw::c_void, + ) -> ::std::os::raw::c_int, + >, + pub xUnfetch: ::std::option::Option< + unsafe extern "C" fn( + arg1: *mut sqlite3_file, + iOfst: sqlite3_int64, + p: *mut ::std::os::raw::c_void, + ) -> ::std::os::raw::c_int, + >, +} +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct sqlite3_mutex { + _unused: [u8; 0], +} +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct sqlite3_api_routines { + _unused: [u8; 0], +} +pub type sqlite3_filename = *const ::std::os::raw::c_char; +pub type sqlite3_syscall_ptr = ::std::option::Option; +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct sqlite3_vfs { + pub iVersion: ::std::os::raw::c_int, + pub szOsFile: ::std::os::raw::c_int, + pub mxPathname: ::std::os::raw::c_int, + pub pNext: *mut sqlite3_vfs, + pub zName: *const ::std::os::raw::c_char, + pub pAppData: *mut ::std::os::raw::c_void, + pub xOpen: ::std::option::Option< + unsafe extern "C" fn( + arg1: *mut sqlite3_vfs, + zName: sqlite3_filename, + arg2: *mut sqlite3_file, + flags: ::std::os::raw::c_int, + pOutFlags: *mut ::std::os::raw::c_int, + ) -> ::std::os::raw::c_int, + >, + pub xDelete: ::std::option::Option< + unsafe extern "C" fn( + arg1: *mut sqlite3_vfs, + zName: *const ::std::os::raw::c_char, + syncDir: ::std::os::raw::c_int, + ) -> ::std::os::raw::c_int, + >, + pub xAccess: ::std::option::Option< + unsafe extern "C" fn( + arg1: *mut sqlite3_vfs, + zName: *const ::std::os::raw::c_char, + flags: ::std::os::raw::c_int, + pResOut: *mut ::std::os::raw::c_int, + ) -> ::std::os::raw::c_int, + >, + pub xFullPathname: ::std::option::Option< + unsafe extern "C" fn( + arg1: *mut sqlite3_vfs, + zName: *const ::std::os::raw::c_char, + nOut: ::std::os::raw::c_int, + zOut: *mut ::std::os::raw::c_char, + ) -> ::std::os::raw::c_int, + >, + pub xDlOpen: ::std::option::Option< + unsafe extern "C" fn( + arg1: *mut sqlite3_vfs, + zFilename: *const ::std::os::raw::c_char, + ) -> *mut ::std::os::raw::c_void, + >, + pub xDlError: ::std::option::Option< + unsafe extern "C" fn( + arg1: *mut sqlite3_vfs, + nByte: ::std::os::raw::c_int, + zErrMsg: *mut ::std::os::raw::c_char, + ), + >, + pub xDlSym: ::std::option::Option< + unsafe extern "C" fn( + arg1: *mut sqlite3_vfs, + arg2: *mut ::std::os::raw::c_void, + zSymbol: *const ::std::os::raw::c_char, + ) -> ::std::option::Option< + unsafe extern "C" fn( + arg1: *mut sqlite3_vfs, + arg2: *mut ::std::os::raw::c_void, + zSymbol: *const ::std::os::raw::c_char, + ), + >, + >, + pub xDlClose: ::std::option::Option< + unsafe extern "C" fn(arg1: *mut sqlite3_vfs, arg2: *mut ::std::os::raw::c_void), + >, + pub xRandomness: ::std::option::Option< + unsafe extern "C" fn( + arg1: *mut sqlite3_vfs, + nByte: ::std::os::raw::c_int, + zOut: *mut ::std::os::raw::c_char, + ) -> ::std::os::raw::c_int, + >, + pub xSleep: ::std::option::Option< + unsafe extern "C" fn( + arg1: *mut sqlite3_vfs, + microseconds: ::std::os::raw::c_int, + ) -> ::std::os::raw::c_int, + >, + pub xCurrentTime: ::std::option::Option< + unsafe extern "C" fn( + arg1: *mut sqlite3_vfs, + arg2: *mut f64, + ) -> ::std::os::raw::c_int, + >, + pub xGetLastError: ::std::option::Option< + unsafe extern "C" fn( + arg1: *mut sqlite3_vfs, + arg2: ::std::os::raw::c_int, + arg3: *mut ::std::os::raw::c_char, + ) -> ::std::os::raw::c_int, + >, + pub xCurrentTimeInt64: ::std::option::Option< + unsafe extern "C" fn( + arg1: *mut sqlite3_vfs, + arg2: *mut sqlite3_int64, + ) -> ::std::os::raw::c_int, + >, + pub xSetSystemCall: ::std::option::Option< + unsafe extern "C" fn( + arg1: *mut sqlite3_vfs, + zName: *const ::std::os::raw::c_char, + arg2: sqlite3_syscall_ptr, + ) -> ::std::os::raw::c_int, + >, + pub xGetSystemCall: ::std::option::Option< + unsafe extern "C" fn( + arg1: *mut sqlite3_vfs, + zName: *const ::std::os::raw::c_char, + ) -> sqlite3_syscall_ptr, + >, + pub xNextSystemCall: ::std::option::Option< + unsafe extern "C" fn( + arg1: *mut sqlite3_vfs, + zName: *const ::std::os::raw::c_char, + ) -> *const ::std::os::raw::c_char, + >, +} +extern "C" { + pub fn sqlite3_initialize() -> ::std::os::raw::c_int; +} +extern "C" { + pub fn sqlite3_shutdown() -> ::std::os::raw::c_int; +} +extern "C" { + pub fn sqlite3_os_init() -> ::std::os::raw::c_int; +} +extern "C" { + pub fn sqlite3_os_end() -> ::std::os::raw::c_int; +} +extern "C" { + pub fn sqlite3_config(arg1: ::std::os::raw::c_int, ...) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn sqlite3_db_config( + arg1: *mut sqlite3, + op: ::std::os::raw::c_int, + ... + ) -> ::std::os::raw::c_int; +} +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct sqlite3_mem_methods { + pub xMalloc: ::std::option::Option< + unsafe extern "C" fn(arg1: ::std::os::raw::c_int) -> *mut ::std::os::raw::c_void, + >, + pub xFree: ::std::option::Option< + unsafe extern "C" fn(arg1: *mut ::std::os::raw::c_void), + >, + pub xRealloc: ::std::option::Option< + unsafe extern "C" fn( + arg1: *mut ::std::os::raw::c_void, + arg2: ::std::os::raw::c_int, + ) -> *mut ::std::os::raw::c_void, + >, + pub xSize: ::std::option::Option< + unsafe extern "C" fn(arg1: *mut ::std::os::raw::c_void) -> ::std::os::raw::c_int, + >, + pub xRoundup: ::std::option::Option< + unsafe extern "C" fn(arg1: ::std::os::raw::c_int) -> ::std::os::raw::c_int, + >, + pub xInit: ::std::option::Option< + unsafe extern "C" fn(arg1: *mut ::std::os::raw::c_void) -> ::std::os::raw::c_int, + >, + pub xShutdown: ::std::option::Option< + unsafe extern "C" fn(arg1: *mut ::std::os::raw::c_void), + >, + pub pAppData: *mut ::std::os::raw::c_void, +} +extern "C" { + pub fn sqlite3_extended_result_codes( + arg1: *mut sqlite3, + onoff: ::std::os::raw::c_int, + ) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn sqlite3_last_insert_rowid(arg1: *mut sqlite3) -> sqlite3_int64; +} +extern "C" { + pub fn sqlite3_set_last_insert_rowid(arg1: *mut sqlite3, arg2: sqlite3_int64); +} +extern "C" { + pub fn sqlite3_changes(arg1: *mut sqlite3) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn sqlite3_changes64(arg1: *mut sqlite3) -> sqlite3_int64; +} +extern "C" { + pub fn sqlite3_total_changes(arg1: *mut sqlite3) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn sqlite3_total_changes64(arg1: *mut sqlite3) -> sqlite3_int64; +} +extern "C" { + pub fn sqlite3_interrupt(arg1: *mut sqlite3); +} +extern "C" { + pub fn sqlite3_is_interrupted(arg1: *mut sqlite3) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn sqlite3_complete(sql: *const ::std::os::raw::c_char) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn sqlite3_busy_handler( + arg1: *mut sqlite3, + arg2: ::std::option::Option< + unsafe extern "C" fn( + arg1: *mut ::std::os::raw::c_void, + arg2: ::std::os::raw::c_int, + ) -> ::std::os::raw::c_int, + >, + arg3: *mut ::std::os::raw::c_void, + ) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn sqlite3_busy_timeout( + arg1: *mut sqlite3, + ms: ::std::os::raw::c_int, + ) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn sqlite3_get_table( + db: *mut sqlite3, + zSql: *const ::std::os::raw::c_char, + pazResult: *mut *mut *mut ::std::os::raw::c_char, + pnRow: *mut ::std::os::raw::c_int, + pnColumn: *mut ::std::os::raw::c_int, + pzErrmsg: *mut *mut ::std::os::raw::c_char, + ) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn sqlite3_free_table(result: *mut *mut ::std::os::raw::c_char); +} +extern "C" { + pub fn sqlite3_mprintf( + arg1: *const ::std::os::raw::c_char, + ... + ) -> *mut ::std::os::raw::c_char; +} +extern "C" { + pub fn sqlite3_snprintf( + arg1: ::std::os::raw::c_int, + arg2: *mut ::std::os::raw::c_char, + arg3: *const ::std::os::raw::c_char, + ... + ) -> *mut ::std::os::raw::c_char; +} +extern "C" { + pub fn sqlite3_malloc(arg1: ::std::os::raw::c_int) -> *mut ::std::os::raw::c_void; +} +extern "C" { + pub fn sqlite3_malloc64(arg1: sqlite3_uint64) -> *mut ::std::os::raw::c_void; +} +extern "C" { + pub fn sqlite3_realloc( + arg1: *mut ::std::os::raw::c_void, + arg2: ::std::os::raw::c_int, + ) -> *mut ::std::os::raw::c_void; +} +extern "C" { + pub fn sqlite3_realloc64( + arg1: *mut ::std::os::raw::c_void, + arg2: sqlite3_uint64, + ) -> *mut ::std::os::raw::c_void; +} +extern "C" { + pub fn sqlite3_free(arg1: *mut ::std::os::raw::c_void); +} +extern "C" { + pub fn sqlite3_msize(arg1: *mut ::std::os::raw::c_void) -> sqlite3_uint64; +} +extern "C" { + pub fn sqlite3_memory_used() -> sqlite3_int64; +} +extern "C" { + pub fn sqlite3_memory_highwater(resetFlag: ::std::os::raw::c_int) -> sqlite3_int64; +} +extern "C" { + pub fn sqlite3_randomness(N: ::std::os::raw::c_int, P: *mut ::std::os::raw::c_void); +} +extern "C" { + pub fn sqlite3_set_authorizer( + arg1: *mut sqlite3, + xAuth: ::std::option::Option< + unsafe extern "C" fn( + arg1: *mut ::std::os::raw::c_void, + arg2: ::std::os::raw::c_int, + arg3: *const ::std::os::raw::c_char, + arg4: *const ::std::os::raw::c_char, + arg5: *const ::std::os::raw::c_char, + arg6: *const ::std::os::raw::c_char, + ) -> ::std::os::raw::c_int, + >, + pUserData: *mut ::std::os::raw::c_void, + ) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn sqlite3_trace_v2( + arg1: *mut sqlite3, + uMask: ::std::os::raw::c_uint, + xCallback: ::std::option::Option< + unsafe extern "C" fn( + arg1: ::std::os::raw::c_uint, + arg2: *mut ::std::os::raw::c_void, + arg3: *mut ::std::os::raw::c_void, + arg4: *mut ::std::os::raw::c_void, + ) -> ::std::os::raw::c_int, + >, + pCtx: *mut ::std::os::raw::c_void, + ) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn sqlite3_progress_handler( + arg1: *mut sqlite3, + arg2: ::std::os::raw::c_int, + arg3: ::std::option::Option< + unsafe extern "C" fn( + arg1: *mut ::std::os::raw::c_void, + ) -> ::std::os::raw::c_int, + >, + arg4: *mut ::std::os::raw::c_void, + ); +} +extern "C" { + pub fn sqlite3_open( + filename: *const ::std::os::raw::c_char, + ppDb: *mut *mut sqlite3, + ) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn sqlite3_open_v2( + filename: *const ::std::os::raw::c_char, + ppDb: *mut *mut sqlite3, + flags: ::std::os::raw::c_int, + zVfs: *const ::std::os::raw::c_char, + ) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn sqlite3_uri_parameter( + z: sqlite3_filename, + zParam: *const ::std::os::raw::c_char, + ) -> *const ::std::os::raw::c_char; +} +extern "C" { + pub fn sqlite3_uri_boolean( + z: sqlite3_filename, + zParam: *const ::std::os::raw::c_char, + bDefault: ::std::os::raw::c_int, + ) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn sqlite3_uri_int64( + arg1: sqlite3_filename, + arg2: *const ::std::os::raw::c_char, + arg3: sqlite3_int64, + ) -> sqlite3_int64; +} +extern "C" { + pub fn sqlite3_uri_key( + z: sqlite3_filename, + N: ::std::os::raw::c_int, + ) -> *const ::std::os::raw::c_char; +} +extern "C" { + pub fn sqlite3_filename_database( + arg1: sqlite3_filename, + ) -> *const ::std::os::raw::c_char; +} +extern "C" { + pub fn sqlite3_filename_journal( + arg1: sqlite3_filename, + ) -> *const ::std::os::raw::c_char; +} +extern "C" { + pub fn sqlite3_filename_wal(arg1: sqlite3_filename) -> *const ::std::os::raw::c_char; +} +extern "C" { + pub fn sqlite3_database_file_object( + arg1: *const ::std::os::raw::c_char, + ) -> *mut sqlite3_file; +} +extern "C" { + pub fn sqlite3_create_filename( + zDatabase: *const ::std::os::raw::c_char, + zJournal: *const ::std::os::raw::c_char, + zWal: *const ::std::os::raw::c_char, + nParam: ::std::os::raw::c_int, + azParam: *mut *const ::std::os::raw::c_char, + ) -> sqlite3_filename; +} +extern "C" { + pub fn sqlite3_free_filename(arg1: sqlite3_filename); +} +extern "C" { + pub fn sqlite3_errcode(db: *mut sqlite3) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn sqlite3_extended_errcode(db: *mut sqlite3) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn sqlite3_errmsg(arg1: *mut sqlite3) -> *const ::std::os::raw::c_char; +} +extern "C" { + pub fn sqlite3_errstr(arg1: ::std::os::raw::c_int) -> *const ::std::os::raw::c_char; +} +extern "C" { + pub fn sqlite3_error_offset(db: *mut sqlite3) -> ::std::os::raw::c_int; +} +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct sqlite3_stmt { + _unused: [u8; 0], +} +extern "C" { + pub fn sqlite3_limit( + arg1: *mut sqlite3, + id: ::std::os::raw::c_int, + newVal: ::std::os::raw::c_int, + ) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn sqlite3_prepare_v2( + db: *mut sqlite3, + zSql: *const ::std::os::raw::c_char, + nByte: ::std::os::raw::c_int, + ppStmt: *mut *mut sqlite3_stmt, + pzTail: *mut *const ::std::os::raw::c_char, + ) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn sqlite3_prepare_v3( + db: *mut sqlite3, + zSql: *const ::std::os::raw::c_char, + nByte: ::std::os::raw::c_int, + prepFlags: ::std::os::raw::c_uint, + ppStmt: *mut *mut sqlite3_stmt, + pzTail: *mut *const ::std::os::raw::c_char, + ) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn sqlite3_sql(pStmt: *mut sqlite3_stmt) -> *const ::std::os::raw::c_char; +} +extern "C" { + pub fn sqlite3_expanded_sql(pStmt: *mut sqlite3_stmt) -> *mut ::std::os::raw::c_char; +} +extern "C" { + pub fn sqlite3_stmt_readonly(pStmt: *mut sqlite3_stmt) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn sqlite3_stmt_isexplain(pStmt: *mut sqlite3_stmt) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn sqlite3_stmt_explain( + pStmt: *mut sqlite3_stmt, + eMode: ::std::os::raw::c_int, + ) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn sqlite3_stmt_busy(arg1: *mut sqlite3_stmt) -> ::std::os::raw::c_int; +} +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct sqlite3_value { + _unused: [u8; 0], +} +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct sqlite3_context { + _unused: [u8; 0], +} +extern "C" { + pub fn sqlite3_bind_blob( + arg1: *mut sqlite3_stmt, + arg2: ::std::os::raw::c_int, + arg3: *const ::std::os::raw::c_void, + n: ::std::os::raw::c_int, + arg4: ::std::option::Option< + unsafe extern "C" fn(arg1: *mut ::std::os::raw::c_void), + >, + ) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn sqlite3_bind_blob64( + arg1: *mut sqlite3_stmt, + arg2: ::std::os::raw::c_int, + arg3: *const ::std::os::raw::c_void, + arg4: sqlite3_uint64, + arg5: ::std::option::Option< + unsafe extern "C" fn(arg1: *mut ::std::os::raw::c_void), + >, + ) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn sqlite3_bind_double( + arg1: *mut sqlite3_stmt, + arg2: ::std::os::raw::c_int, + arg3: f64, + ) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn sqlite3_bind_int( + arg1: *mut sqlite3_stmt, + arg2: ::std::os::raw::c_int, + arg3: ::std::os::raw::c_int, + ) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn sqlite3_bind_int64( + arg1: *mut sqlite3_stmt, + arg2: ::std::os::raw::c_int, + arg3: sqlite3_int64, + ) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn sqlite3_bind_null( + arg1: *mut sqlite3_stmt, + arg2: ::std::os::raw::c_int, + ) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn sqlite3_bind_text( + arg1: *mut sqlite3_stmt, + arg2: ::std::os::raw::c_int, + arg3: *const ::std::os::raw::c_char, + arg4: ::std::os::raw::c_int, + arg5: ::std::option::Option< + unsafe extern "C" fn(arg1: *mut ::std::os::raw::c_void), + >, + ) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn sqlite3_bind_text64( + arg1: *mut sqlite3_stmt, + arg2: ::std::os::raw::c_int, + arg3: *const ::std::os::raw::c_char, + arg4: sqlite3_uint64, + arg5: ::std::option::Option< + unsafe extern "C" fn(arg1: *mut ::std::os::raw::c_void), + >, + encoding: ::std::os::raw::c_uchar, + ) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn sqlite3_bind_value( + arg1: *mut sqlite3_stmt, + arg2: ::std::os::raw::c_int, + arg3: *const sqlite3_value, + ) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn sqlite3_bind_pointer( + arg1: *mut sqlite3_stmt, + arg2: ::std::os::raw::c_int, + arg3: *mut ::std::os::raw::c_void, + arg4: *const ::std::os::raw::c_char, + arg5: ::std::option::Option< + unsafe extern "C" fn(arg1: *mut ::std::os::raw::c_void), + >, + ) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn sqlite3_bind_zeroblob( + arg1: *mut sqlite3_stmt, + arg2: ::std::os::raw::c_int, + n: ::std::os::raw::c_int, + ) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn sqlite3_bind_zeroblob64( + arg1: *mut sqlite3_stmt, + arg2: ::std::os::raw::c_int, + arg3: sqlite3_uint64, + ) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn sqlite3_bind_parameter_count( + arg1: *mut sqlite3_stmt, + ) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn sqlite3_bind_parameter_name( + arg1: *mut sqlite3_stmt, + arg2: ::std::os::raw::c_int, + ) -> *const ::std::os::raw::c_char; +} +extern "C" { + pub fn sqlite3_bind_parameter_index( + arg1: *mut sqlite3_stmt, + zName: *const ::std::os::raw::c_char, + ) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn sqlite3_clear_bindings(arg1: *mut sqlite3_stmt) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn sqlite3_column_count(pStmt: *mut sqlite3_stmt) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn sqlite3_column_name( + arg1: *mut sqlite3_stmt, + N: ::std::os::raw::c_int, + ) -> *const ::std::os::raw::c_char; +} +extern "C" { + pub fn sqlite3_column_database_name( + arg1: *mut sqlite3_stmt, + arg2: ::std::os::raw::c_int, + ) -> *const ::std::os::raw::c_char; +} +extern "C" { + pub fn sqlite3_column_table_name( + arg1: *mut sqlite3_stmt, + arg2: ::std::os::raw::c_int, + ) -> *const ::std::os::raw::c_char; +} +extern "C" { + pub fn sqlite3_column_origin_name( + arg1: *mut sqlite3_stmt, + arg2: ::std::os::raw::c_int, + ) -> *const ::std::os::raw::c_char; +} +extern "C" { + pub fn sqlite3_column_decltype( + arg1: *mut sqlite3_stmt, + arg2: ::std::os::raw::c_int, + ) -> *const ::std::os::raw::c_char; +} +extern "C" { + pub fn sqlite3_step(arg1: *mut sqlite3_stmt) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn sqlite3_data_count(pStmt: *mut sqlite3_stmt) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn sqlite3_column_blob( + arg1: *mut sqlite3_stmt, + iCol: ::std::os::raw::c_int, + ) -> *const ::std::os::raw::c_void; +} +extern "C" { + pub fn sqlite3_column_double( + arg1: *mut sqlite3_stmt, + iCol: ::std::os::raw::c_int, + ) -> f64; +} +extern "C" { + pub fn sqlite3_column_int( + arg1: *mut sqlite3_stmt, + iCol: ::std::os::raw::c_int, + ) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn sqlite3_column_int64( + arg1: *mut sqlite3_stmt, + iCol: ::std::os::raw::c_int, + ) -> sqlite3_int64; +} +extern "C" { + pub fn sqlite3_column_text( + arg1: *mut sqlite3_stmt, + iCol: ::std::os::raw::c_int, + ) -> *const ::std::os::raw::c_uchar; +} +extern "C" { + pub fn sqlite3_column_value( + arg1: *mut sqlite3_stmt, + iCol: ::std::os::raw::c_int, + ) -> *mut sqlite3_value; +} +extern "C" { + pub fn sqlite3_column_bytes( + arg1: *mut sqlite3_stmt, + iCol: ::std::os::raw::c_int, + ) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn sqlite3_column_type( + arg1: *mut sqlite3_stmt, + iCol: ::std::os::raw::c_int, + ) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn sqlite3_finalize(pStmt: *mut sqlite3_stmt) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn sqlite3_reset(pStmt: *mut sqlite3_stmt) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn sqlite3_create_function_v2( + db: *mut sqlite3, + zFunctionName: *const ::std::os::raw::c_char, + nArg: ::std::os::raw::c_int, + eTextRep: ::std::os::raw::c_int, + pApp: *mut ::std::os::raw::c_void, + xFunc: ::std::option::Option< + unsafe extern "C" fn( + arg1: *mut sqlite3_context, + arg2: ::std::os::raw::c_int, + arg3: *mut *mut sqlite3_value, + ), + >, + xStep: ::std::option::Option< + unsafe extern "C" fn( + arg1: *mut sqlite3_context, + arg2: ::std::os::raw::c_int, + arg3: *mut *mut sqlite3_value, + ), + >, + xFinal: ::std::option::Option, + xDestroy: ::std::option::Option< + unsafe extern "C" fn(arg1: *mut ::std::os::raw::c_void), + >, + ) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn sqlite3_create_window_function( + db: *mut sqlite3, + zFunctionName: *const ::std::os::raw::c_char, + nArg: ::std::os::raw::c_int, + eTextRep: ::std::os::raw::c_int, + pApp: *mut ::std::os::raw::c_void, + xStep: ::std::option::Option< + unsafe extern "C" fn( + arg1: *mut sqlite3_context, + arg2: ::std::os::raw::c_int, + arg3: *mut *mut sqlite3_value, + ), + >, + xFinal: ::std::option::Option, + xValue: ::std::option::Option, + xInverse: ::std::option::Option< + unsafe extern "C" fn( + arg1: *mut sqlite3_context, + arg2: ::std::os::raw::c_int, + arg3: *mut *mut sqlite3_value, + ), + >, + xDestroy: ::std::option::Option< + unsafe extern "C" fn(arg1: *mut ::std::os::raw::c_void), + >, + ) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn sqlite3_aggregate_count(arg1: *mut sqlite3_context) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn sqlite3_expired(arg1: *mut sqlite3_stmt) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn sqlite3_transfer_bindings( + arg1: *mut sqlite3_stmt, + arg2: *mut sqlite3_stmt, + ) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn sqlite3_global_recover() -> ::std::os::raw::c_int; +} +extern "C" { + pub fn sqlite3_thread_cleanup(); +} +extern "C" { + pub fn sqlite3_memory_alarm( + arg1: ::std::option::Option< + unsafe extern "C" fn( + arg1: *mut ::std::os::raw::c_void, + arg2: sqlite3_int64, + arg3: ::std::os::raw::c_int, + ), + >, + arg2: *mut ::std::os::raw::c_void, + arg3: sqlite3_int64, + ) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn sqlite3_value_blob(arg1: *mut sqlite3_value) -> *const ::std::os::raw::c_void; +} +extern "C" { + pub fn sqlite3_value_double(arg1: *mut sqlite3_value) -> f64; +} +extern "C" { + pub fn sqlite3_value_int(arg1: *mut sqlite3_value) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn sqlite3_value_int64(arg1: *mut sqlite3_value) -> sqlite3_int64; +} +extern "C" { + pub fn sqlite3_value_pointer( + arg1: *mut sqlite3_value, + arg2: *const ::std::os::raw::c_char, + ) -> *mut ::std::os::raw::c_void; +} +extern "C" { + pub fn sqlite3_value_text( + arg1: *mut sqlite3_value, + ) -> *const ::std::os::raw::c_uchar; +} +extern "C" { + pub fn sqlite3_value_bytes(arg1: *mut sqlite3_value) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn sqlite3_value_type(arg1: *mut sqlite3_value) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn sqlite3_value_numeric_type(arg1: *mut sqlite3_value) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn sqlite3_value_nochange(arg1: *mut sqlite3_value) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn sqlite3_value_frombind(arg1: *mut sqlite3_value) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn sqlite3_value_encoding(arg1: *mut sqlite3_value) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn sqlite3_value_subtype(arg1: *mut sqlite3_value) -> ::std::os::raw::c_uint; +} +extern "C" { + pub fn sqlite3_value_dup(arg1: *const sqlite3_value) -> *mut sqlite3_value; +} +extern "C" { + pub fn sqlite3_value_free(arg1: *mut sqlite3_value); +} +extern "C" { + pub fn sqlite3_aggregate_context( + arg1: *mut sqlite3_context, + nBytes: ::std::os::raw::c_int, + ) -> *mut ::std::os::raw::c_void; +} +extern "C" { + pub fn sqlite3_user_data(arg1: *mut sqlite3_context) -> *mut ::std::os::raw::c_void; +} +extern "C" { + pub fn sqlite3_context_db_handle(arg1: *mut sqlite3_context) -> *mut sqlite3; +} +extern "C" { + pub fn sqlite3_get_auxdata( + arg1: *mut sqlite3_context, + N: ::std::os::raw::c_int, + ) -> *mut ::std::os::raw::c_void; +} +extern "C" { + pub fn sqlite3_set_auxdata( + arg1: *mut sqlite3_context, + N: ::std::os::raw::c_int, + arg2: *mut ::std::os::raw::c_void, + arg3: ::std::option::Option< + unsafe extern "C" fn(arg1: *mut ::std::os::raw::c_void), + >, + ); +} +extern "C" { + pub fn sqlite3_get_clientdata( + arg1: *mut sqlite3, + arg2: *const ::std::os::raw::c_char, + ) -> *mut ::std::os::raw::c_void; +} +extern "C" { + pub fn sqlite3_set_clientdata( + arg1: *mut sqlite3, + arg2: *const ::std::os::raw::c_char, + arg3: *mut ::std::os::raw::c_void, + arg4: ::std::option::Option< + unsafe extern "C" fn(arg1: *mut ::std::os::raw::c_void), + >, + ) -> ::std::os::raw::c_int; +} +pub type sqlite3_destructor_type = ::std::option::Option< + unsafe extern "C" fn(arg1: *mut ::std::os::raw::c_void), +>; +extern "C" { + pub fn sqlite3_result_blob( + arg1: *mut sqlite3_context, + arg2: *const ::std::os::raw::c_void, + arg3: ::std::os::raw::c_int, + arg4: ::std::option::Option< + unsafe extern "C" fn(arg1: *mut ::std::os::raw::c_void), + >, + ); +} +extern "C" { + pub fn sqlite3_result_blob64( + arg1: *mut sqlite3_context, + arg2: *const ::std::os::raw::c_void, + arg3: sqlite3_uint64, + arg4: ::std::option::Option< + unsafe extern "C" fn(arg1: *mut ::std::os::raw::c_void), + >, + ); +} +extern "C" { + pub fn sqlite3_result_double(arg1: *mut sqlite3_context, arg2: f64); +} +extern "C" { + pub fn sqlite3_result_error( + arg1: *mut sqlite3_context, + arg2: *const ::std::os::raw::c_char, + arg3: ::std::os::raw::c_int, + ); +} +extern "C" { + pub fn sqlite3_result_error_toobig(arg1: *mut sqlite3_context); +} +extern "C" { + pub fn sqlite3_result_error_nomem(arg1: *mut sqlite3_context); +} +extern "C" { + pub fn sqlite3_result_error_code( + arg1: *mut sqlite3_context, + arg2: ::std::os::raw::c_int, + ); +} +extern "C" { + pub fn sqlite3_result_int(arg1: *mut sqlite3_context, arg2: ::std::os::raw::c_int); +} +extern "C" { + pub fn sqlite3_result_int64(arg1: *mut sqlite3_context, arg2: sqlite3_int64); +} +extern "C" { + pub fn sqlite3_result_null(arg1: *mut sqlite3_context); +} +extern "C" { + pub fn sqlite3_result_text( + arg1: *mut sqlite3_context, + arg2: *const ::std::os::raw::c_char, + arg3: ::std::os::raw::c_int, + arg4: ::std::option::Option< + unsafe extern "C" fn(arg1: *mut ::std::os::raw::c_void), + >, + ); +} +extern "C" { + pub fn sqlite3_result_text64( + arg1: *mut sqlite3_context, + arg2: *const ::std::os::raw::c_char, + arg3: sqlite3_uint64, + arg4: ::std::option::Option< + unsafe extern "C" fn(arg1: *mut ::std::os::raw::c_void), + >, + encoding: ::std::os::raw::c_uchar, + ); +} +extern "C" { + pub fn sqlite3_result_value(arg1: *mut sqlite3_context, arg2: *mut sqlite3_value); +} +extern "C" { + pub fn sqlite3_result_pointer( + arg1: *mut sqlite3_context, + arg2: *mut ::std::os::raw::c_void, + arg3: *const ::std::os::raw::c_char, + arg4: ::std::option::Option< + unsafe extern "C" fn(arg1: *mut ::std::os::raw::c_void), + >, + ); +} +extern "C" { + pub fn sqlite3_result_zeroblob(arg1: *mut sqlite3_context, n: ::std::os::raw::c_int); +} +extern "C" { + pub fn sqlite3_result_zeroblob64( + arg1: *mut sqlite3_context, + n: sqlite3_uint64, + ) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn sqlite3_result_subtype( + arg1: *mut sqlite3_context, + arg2: ::std::os::raw::c_uint, + ); +} +extern "C" { + pub fn sqlite3_create_collation_v2( + arg1: *mut sqlite3, + zName: *const ::std::os::raw::c_char, + eTextRep: ::std::os::raw::c_int, + pArg: *mut ::std::os::raw::c_void, + xCompare: ::std::option::Option< + unsafe extern "C" fn( + arg1: *mut ::std::os::raw::c_void, + arg2: ::std::os::raw::c_int, + arg3: *const ::std::os::raw::c_void, + arg4: ::std::os::raw::c_int, + arg5: *const ::std::os::raw::c_void, + ) -> ::std::os::raw::c_int, + >, + xDestroy: ::std::option::Option< + unsafe extern "C" fn(arg1: *mut ::std::os::raw::c_void), + >, + ) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn sqlite3_collation_needed( + arg1: *mut sqlite3, + arg2: *mut ::std::os::raw::c_void, + arg3: ::std::option::Option< + unsafe extern "C" fn( + arg1: *mut ::std::os::raw::c_void, + arg2: *mut sqlite3, + eTextRep: ::std::os::raw::c_int, + arg3: *const ::std::os::raw::c_char, + ), + >, + ) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn sqlite3_sleep(arg1: ::std::os::raw::c_int) -> ::std::os::raw::c_int; +} +extern "C" { + pub static mut sqlite3_temp_directory: *mut ::std::os::raw::c_char; +} +extern "C" { + pub static mut sqlite3_data_directory: *mut ::std::os::raw::c_char; +} +extern "C" { + pub fn sqlite3_win32_set_directory( + type_: ::std::os::raw::c_ulong, + zValue: *mut ::std::os::raw::c_void, + ) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn sqlite3_win32_set_directory8( + type_: ::std::os::raw::c_ulong, + zValue: *const ::std::os::raw::c_char, + ) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn sqlite3_get_autocommit(arg1: *mut sqlite3) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn sqlite3_db_handle(arg1: *mut sqlite3_stmt) -> *mut sqlite3; +} +extern "C" { + pub fn sqlite3_db_name( + db: *mut sqlite3, + N: ::std::os::raw::c_int, + ) -> *const ::std::os::raw::c_char; +} +extern "C" { + pub fn sqlite3_db_filename( + db: *mut sqlite3, + zDbName: *const ::std::os::raw::c_char, + ) -> sqlite3_filename; +} +extern "C" { + pub fn sqlite3_db_readonly( + db: *mut sqlite3, + zDbName: *const ::std::os::raw::c_char, + ) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn sqlite3_txn_state( + arg1: *mut sqlite3, + zSchema: *const ::std::os::raw::c_char, + ) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn sqlite3_next_stmt( + pDb: *mut sqlite3, + pStmt: *mut sqlite3_stmt, + ) -> *mut sqlite3_stmt; +} +extern "C" { + pub fn sqlite3_commit_hook( + arg1: *mut sqlite3, + arg2: ::std::option::Option< + unsafe extern "C" fn( + arg1: *mut ::std::os::raw::c_void, + ) -> ::std::os::raw::c_int, + >, + arg3: *mut ::std::os::raw::c_void, + ) -> *mut ::std::os::raw::c_void; +} +extern "C" { + pub fn sqlite3_rollback_hook( + arg1: *mut sqlite3, + arg2: ::std::option::Option< + unsafe extern "C" fn(arg1: *mut ::std::os::raw::c_void), + >, + arg3: *mut ::std::os::raw::c_void, + ) -> *mut ::std::os::raw::c_void; +} +extern "C" { + pub fn sqlite3_autovacuum_pages( + db: *mut sqlite3, + arg1: ::std::option::Option< + unsafe extern "C" fn( + arg1: *mut ::std::os::raw::c_void, + arg2: *const ::std::os::raw::c_char, + arg3: ::std::os::raw::c_uint, + arg4: ::std::os::raw::c_uint, + arg5: ::std::os::raw::c_uint, + ) -> ::std::os::raw::c_uint, + >, + arg2: *mut ::std::os::raw::c_void, + arg3: ::std::option::Option< + unsafe extern "C" fn(arg1: *mut ::std::os::raw::c_void), + >, + ) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn sqlite3_update_hook( + arg1: *mut sqlite3, + arg2: ::std::option::Option< + unsafe extern "C" fn( + arg1: *mut ::std::os::raw::c_void, + arg2: ::std::os::raw::c_int, + arg3: *const ::std::os::raw::c_char, + arg4: *const ::std::os::raw::c_char, + arg5: sqlite3_int64, + ), + >, + arg3: *mut ::std::os::raw::c_void, + ) -> *mut ::std::os::raw::c_void; +} +extern "C" { + pub fn sqlite3_enable_shared_cache( + arg1: ::std::os::raw::c_int, + ) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn sqlite3_release_memory(arg1: ::std::os::raw::c_int) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn sqlite3_db_release_memory(arg1: *mut sqlite3) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn sqlite3_soft_heap_limit64(N: sqlite3_int64) -> sqlite3_int64; +} +extern "C" { + pub fn sqlite3_hard_heap_limit64(N: sqlite3_int64) -> sqlite3_int64; +} +extern "C" { + pub fn sqlite3_soft_heap_limit(N: ::std::os::raw::c_int); +} +extern "C" { + pub fn sqlite3_table_column_metadata( + db: *mut sqlite3, + zDbName: *const ::std::os::raw::c_char, + zTableName: *const ::std::os::raw::c_char, + zColumnName: *const ::std::os::raw::c_char, + pzDataType: *mut *const ::std::os::raw::c_char, + pzCollSeq: *mut *const ::std::os::raw::c_char, + pNotNull: *mut ::std::os::raw::c_int, + pPrimaryKey: *mut ::std::os::raw::c_int, + pAutoinc: *mut ::std::os::raw::c_int, + ) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn sqlite3_reset_auto_extension(); +} +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct sqlite3_module { + pub iVersion: ::std::os::raw::c_int, + pub xCreate: ::std::option::Option< + unsafe extern "C" fn( + arg1: *mut sqlite3, + pAux: *mut ::std::os::raw::c_void, + argc: ::std::os::raw::c_int, + argv: *const *const ::std::os::raw::c_char, + ppVTab: *mut *mut sqlite3_vtab, + arg2: *mut *mut ::std::os::raw::c_char, + ) -> ::std::os::raw::c_int, + >, + pub xConnect: ::std::option::Option< + unsafe extern "C" fn( + arg1: *mut sqlite3, + pAux: *mut ::std::os::raw::c_void, + argc: ::std::os::raw::c_int, + argv: *const *const ::std::os::raw::c_char, + ppVTab: *mut *mut sqlite3_vtab, + arg2: *mut *mut ::std::os::raw::c_char, + ) -> ::std::os::raw::c_int, + >, + pub xBestIndex: ::std::option::Option< + unsafe extern "C" fn( + pVTab: *mut sqlite3_vtab, + arg1: *mut sqlite3_index_info, + ) -> ::std::os::raw::c_int, + >, + pub xDisconnect: ::std::option::Option< + unsafe extern "C" fn(pVTab: *mut sqlite3_vtab) -> ::std::os::raw::c_int, + >, + pub xDestroy: ::std::option::Option< + unsafe extern "C" fn(pVTab: *mut sqlite3_vtab) -> ::std::os::raw::c_int, + >, + pub xOpen: ::std::option::Option< + unsafe extern "C" fn( + pVTab: *mut sqlite3_vtab, + ppCursor: *mut *mut sqlite3_vtab_cursor, + ) -> ::std::os::raw::c_int, + >, + pub xClose: ::std::option::Option< + unsafe extern "C" fn(arg1: *mut sqlite3_vtab_cursor) -> ::std::os::raw::c_int, + >, + pub xFilter: ::std::option::Option< + unsafe extern "C" fn( + arg1: *mut sqlite3_vtab_cursor, + idxNum: ::std::os::raw::c_int, + idxStr: *const ::std::os::raw::c_char, + argc: ::std::os::raw::c_int, + argv: *mut *mut sqlite3_value, + ) -> ::std::os::raw::c_int, + >, + pub xNext: ::std::option::Option< + unsafe extern "C" fn(arg1: *mut sqlite3_vtab_cursor) -> ::std::os::raw::c_int, + >, + pub xEof: ::std::option::Option< + unsafe extern "C" fn(arg1: *mut sqlite3_vtab_cursor) -> ::std::os::raw::c_int, + >, + pub xColumn: ::std::option::Option< + unsafe extern "C" fn( + arg1: *mut sqlite3_vtab_cursor, + arg2: *mut sqlite3_context, + arg3: ::std::os::raw::c_int, + ) -> ::std::os::raw::c_int, + >, + pub xRowid: ::std::option::Option< + unsafe extern "C" fn( + arg1: *mut sqlite3_vtab_cursor, + pRowid: *mut sqlite3_int64, + ) -> ::std::os::raw::c_int, + >, + pub xUpdate: ::std::option::Option< + unsafe extern "C" fn( + arg1: *mut sqlite3_vtab, + arg2: ::std::os::raw::c_int, + arg3: *mut *mut sqlite3_value, + arg4: *mut sqlite3_int64, + ) -> ::std::os::raw::c_int, + >, + pub xBegin: ::std::option::Option< + unsafe extern "C" fn(pVTab: *mut sqlite3_vtab) -> ::std::os::raw::c_int, + >, + pub xSync: ::std::option::Option< + unsafe extern "C" fn(pVTab: *mut sqlite3_vtab) -> ::std::os::raw::c_int, + >, + pub xCommit: ::std::option::Option< + unsafe extern "C" fn(pVTab: *mut sqlite3_vtab) -> ::std::os::raw::c_int, + >, + pub xRollback: ::std::option::Option< + unsafe extern "C" fn(pVTab: *mut sqlite3_vtab) -> ::std::os::raw::c_int, + >, + pub xFindFunction: ::std::option::Option< + unsafe extern "C" fn( + pVtab: *mut sqlite3_vtab, + nArg: ::std::os::raw::c_int, + zName: *const ::std::os::raw::c_char, + pxFunc: *mut ::std::option::Option< + unsafe extern "C" fn( + arg1: *mut sqlite3_context, + arg2: ::std::os::raw::c_int, + arg3: *mut *mut sqlite3_value, + ), + >, + ppArg: *mut *mut ::std::os::raw::c_void, + ) -> ::std::os::raw::c_int, + >, + pub xRename: ::std::option::Option< + unsafe extern "C" fn( + pVtab: *mut sqlite3_vtab, + zNew: *const ::std::os::raw::c_char, + ) -> ::std::os::raw::c_int, + >, + pub xSavepoint: ::std::option::Option< + unsafe extern "C" fn( + pVTab: *mut sqlite3_vtab, + arg1: ::std::os::raw::c_int, + ) -> ::std::os::raw::c_int, + >, + pub xRelease: ::std::option::Option< + unsafe extern "C" fn( + pVTab: *mut sqlite3_vtab, + arg1: ::std::os::raw::c_int, + ) -> ::std::os::raw::c_int, + >, + pub xRollbackTo: ::std::option::Option< + unsafe extern "C" fn( + pVTab: *mut sqlite3_vtab, + arg1: ::std::os::raw::c_int, + ) -> ::std::os::raw::c_int, + >, + pub xShadowName: ::std::option::Option< + unsafe extern "C" fn( + arg1: *const ::std::os::raw::c_char, + ) -> ::std::os::raw::c_int, + >, + pub xIntegrity: ::std::option::Option< + unsafe extern "C" fn( + pVTab: *mut sqlite3_vtab, + zSchema: *const ::std::os::raw::c_char, + zTabName: *const ::std::os::raw::c_char, + mFlags: ::std::os::raw::c_int, + pzErr: *mut *mut ::std::os::raw::c_char, + ) -> ::std::os::raw::c_int, + >, +} +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct sqlite3_index_info { + pub nConstraint: ::std::os::raw::c_int, + pub aConstraint: *mut sqlite3_index_constraint, + pub nOrderBy: ::std::os::raw::c_int, + pub aOrderBy: *mut sqlite3_index_orderby, + pub aConstraintUsage: *mut sqlite3_index_constraint_usage, + pub idxNum: ::std::os::raw::c_int, + pub idxStr: *mut ::std::os::raw::c_char, + pub needToFreeIdxStr: ::std::os::raw::c_int, + pub orderByConsumed: ::std::os::raw::c_int, + pub estimatedCost: f64, + pub estimatedRows: sqlite3_int64, + pub idxFlags: ::std::os::raw::c_int, + pub colUsed: sqlite3_uint64, +} +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct sqlite3_index_constraint { + pub iColumn: ::std::os::raw::c_int, + pub op: ::std::os::raw::c_uchar, + pub usable: ::std::os::raw::c_uchar, + pub iTermOffset: ::std::os::raw::c_int, +} +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct sqlite3_index_orderby { + pub iColumn: ::std::os::raw::c_int, + pub desc: ::std::os::raw::c_uchar, +} +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct sqlite3_index_constraint_usage { + pub argvIndex: ::std::os::raw::c_int, + pub omit: ::std::os::raw::c_uchar, +} +extern "C" { + pub fn sqlite3_create_module_v2( + db: *mut sqlite3, + zName: *const ::std::os::raw::c_char, + p: *const sqlite3_module, + pClientData: *mut ::std::os::raw::c_void, + xDestroy: ::std::option::Option< + unsafe extern "C" fn(arg1: *mut ::std::os::raw::c_void), + >, + ) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn sqlite3_drop_modules( + db: *mut sqlite3, + azKeep: *mut *const ::std::os::raw::c_char, + ) -> ::std::os::raw::c_int; +} +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct sqlite3_vtab { + pub pModule: *const sqlite3_module, + pub nRef: ::std::os::raw::c_int, + pub zErrMsg: *mut ::std::os::raw::c_char, +} +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct sqlite3_vtab_cursor { + pub pVtab: *mut sqlite3_vtab, +} +extern "C" { + pub fn sqlite3_declare_vtab( + arg1: *mut sqlite3, + zSQL: *const ::std::os::raw::c_char, + ) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn sqlite3_overload_function( + arg1: *mut sqlite3, + zFuncName: *const ::std::os::raw::c_char, + nArg: ::std::os::raw::c_int, + ) -> ::std::os::raw::c_int; +} +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct sqlite3_blob { + _unused: [u8; 0], +} +extern "C" { + pub fn sqlite3_blob_open( + arg1: *mut sqlite3, + zDb: *const ::std::os::raw::c_char, + zTable: *const ::std::os::raw::c_char, + zColumn: *const ::std::os::raw::c_char, + iRow: sqlite3_int64, + flags: ::std::os::raw::c_int, + ppBlob: *mut *mut sqlite3_blob, + ) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn sqlite3_blob_reopen( + arg1: *mut sqlite3_blob, + arg2: sqlite3_int64, + ) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn sqlite3_blob_close(arg1: *mut sqlite3_blob) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn sqlite3_blob_bytes(arg1: *mut sqlite3_blob) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn sqlite3_blob_read( + arg1: *mut sqlite3_blob, + Z: *mut ::std::os::raw::c_void, + N: ::std::os::raw::c_int, + iOffset: ::std::os::raw::c_int, + ) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn sqlite3_blob_write( + arg1: *mut sqlite3_blob, + z: *const ::std::os::raw::c_void, + n: ::std::os::raw::c_int, + iOffset: ::std::os::raw::c_int, + ) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn sqlite3_vfs_find(zVfsName: *const ::std::os::raw::c_char) -> *mut sqlite3_vfs; +} +extern "C" { + pub fn sqlite3_vfs_register( + arg1: *mut sqlite3_vfs, + makeDflt: ::std::os::raw::c_int, + ) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn sqlite3_vfs_unregister(arg1: *mut sqlite3_vfs) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn sqlite3_mutex_alloc(arg1: ::std::os::raw::c_int) -> *mut sqlite3_mutex; +} +extern "C" { + pub fn sqlite3_mutex_free(arg1: *mut sqlite3_mutex); +} +extern "C" { + pub fn sqlite3_mutex_enter(arg1: *mut sqlite3_mutex); +} +extern "C" { + pub fn sqlite3_mutex_try(arg1: *mut sqlite3_mutex) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn sqlite3_mutex_leave(arg1: *mut sqlite3_mutex); +} +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct sqlite3_mutex_methods { + pub xMutexInit: ::std::option::Option< + unsafe extern "C" fn() -> ::std::os::raw::c_int, + >, + pub xMutexEnd: ::std::option::Option< + unsafe extern "C" fn() -> ::std::os::raw::c_int, + >, + pub xMutexAlloc: ::std::option::Option< + unsafe extern "C" fn(arg1: ::std::os::raw::c_int) -> *mut sqlite3_mutex, + >, + pub xMutexFree: ::std::option::Option< + unsafe extern "C" fn(arg1: *mut sqlite3_mutex), + >, + pub xMutexEnter: ::std::option::Option< + unsafe extern "C" fn(arg1: *mut sqlite3_mutex), + >, + pub xMutexTry: ::std::option::Option< + unsafe extern "C" fn(arg1: *mut sqlite3_mutex) -> ::std::os::raw::c_int, + >, + pub xMutexLeave: ::std::option::Option< + unsafe extern "C" fn(arg1: *mut sqlite3_mutex), + >, + pub xMutexHeld: ::std::option::Option< + unsafe extern "C" fn(arg1: *mut sqlite3_mutex) -> ::std::os::raw::c_int, + >, + pub xMutexNotheld: ::std::option::Option< + unsafe extern "C" fn(arg1: *mut sqlite3_mutex) -> ::std::os::raw::c_int, + >, +} +extern "C" { + pub fn sqlite3_mutex_held(arg1: *mut sqlite3_mutex) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn sqlite3_mutex_notheld(arg1: *mut sqlite3_mutex) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn sqlite3_db_mutex(arg1: *mut sqlite3) -> *mut sqlite3_mutex; +} +extern "C" { + pub fn sqlite3_file_control( + arg1: *mut sqlite3, + zDbName: *const ::std::os::raw::c_char, + op: ::std::os::raw::c_int, + arg2: *mut ::std::os::raw::c_void, + ) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn sqlite3_test_control(op: ::std::os::raw::c_int, ...) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn sqlite3_keyword_count() -> ::std::os::raw::c_int; +} +extern "C" { + pub fn sqlite3_keyword_name( + arg1: ::std::os::raw::c_int, + arg2: *mut *const ::std::os::raw::c_char, + arg3: *mut ::std::os::raw::c_int, + ) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn sqlite3_keyword_check( + arg1: *const ::std::os::raw::c_char, + arg2: ::std::os::raw::c_int, + ) -> ::std::os::raw::c_int; +} +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct sqlite3_str { + _unused: [u8; 0], +} +extern "C" { + pub fn sqlite3_str_new(arg1: *mut sqlite3) -> *mut sqlite3_str; +} +extern "C" { + pub fn sqlite3_str_finish(arg1: *mut sqlite3_str) -> *mut ::std::os::raw::c_char; +} +extern "C" { + pub fn sqlite3_str_appendf( + arg1: *mut sqlite3_str, + zFormat: *const ::std::os::raw::c_char, + ... + ); +} +extern "C" { + pub fn sqlite3_str_append( + arg1: *mut sqlite3_str, + zIn: *const ::std::os::raw::c_char, + N: ::std::os::raw::c_int, + ); +} +extern "C" { + pub fn sqlite3_str_appendall( + arg1: *mut sqlite3_str, + zIn: *const ::std::os::raw::c_char, + ); +} +extern "C" { + pub fn sqlite3_str_appendchar( + arg1: *mut sqlite3_str, + N: ::std::os::raw::c_int, + C: ::std::os::raw::c_char, + ); +} +extern "C" { + pub fn sqlite3_str_reset(arg1: *mut sqlite3_str); +} +extern "C" { + pub fn sqlite3_str_errcode(arg1: *mut sqlite3_str) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn sqlite3_str_length(arg1: *mut sqlite3_str) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn sqlite3_str_value(arg1: *mut sqlite3_str) -> *mut ::std::os::raw::c_char; +} +extern "C" { + pub fn sqlite3_status( + op: ::std::os::raw::c_int, + pCurrent: *mut ::std::os::raw::c_int, + pHighwater: *mut ::std::os::raw::c_int, + resetFlag: ::std::os::raw::c_int, + ) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn sqlite3_status64( + op: ::std::os::raw::c_int, + pCurrent: *mut sqlite3_int64, + pHighwater: *mut sqlite3_int64, + resetFlag: ::std::os::raw::c_int, + ) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn sqlite3_db_status( + arg1: *mut sqlite3, + op: ::std::os::raw::c_int, + pCur: *mut ::std::os::raw::c_int, + pHiwtr: *mut ::std::os::raw::c_int, + resetFlg: ::std::os::raw::c_int, + ) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn sqlite3_stmt_status( + arg1: *mut sqlite3_stmt, + op: ::std::os::raw::c_int, + resetFlg: ::std::os::raw::c_int, + ) -> ::std::os::raw::c_int; +} +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct sqlite3_pcache { + _unused: [u8; 0], +} +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct sqlite3_pcache_page { + pub pBuf: *mut ::std::os::raw::c_void, + pub pExtra: *mut ::std::os::raw::c_void, +} +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct sqlite3_pcache_methods2 { + pub iVersion: ::std::os::raw::c_int, + pub pArg: *mut ::std::os::raw::c_void, + pub xInit: ::std::option::Option< + unsafe extern "C" fn(arg1: *mut ::std::os::raw::c_void) -> ::std::os::raw::c_int, + >, + pub xShutdown: ::std::option::Option< + unsafe extern "C" fn(arg1: *mut ::std::os::raw::c_void), + >, + pub xCreate: ::std::option::Option< + unsafe extern "C" fn( + szPage: ::std::os::raw::c_int, + szExtra: ::std::os::raw::c_int, + bPurgeable: ::std::os::raw::c_int, + ) -> *mut sqlite3_pcache, + >, + pub xCachesize: ::std::option::Option< + unsafe extern "C" fn( + arg1: *mut sqlite3_pcache, + nCachesize: ::std::os::raw::c_int, + ), + >, + pub xPagecount: ::std::option::Option< + unsafe extern "C" fn(arg1: *mut sqlite3_pcache) -> ::std::os::raw::c_int, + >, + pub xFetch: ::std::option::Option< + unsafe extern "C" fn( + arg1: *mut sqlite3_pcache, + key: ::std::os::raw::c_uint, + createFlag: ::std::os::raw::c_int, + ) -> *mut sqlite3_pcache_page, + >, + pub xUnpin: ::std::option::Option< + unsafe extern "C" fn( + arg1: *mut sqlite3_pcache, + arg2: *mut sqlite3_pcache_page, + discard: ::std::os::raw::c_int, + ), + >, + pub xRekey: ::std::option::Option< + unsafe extern "C" fn( + arg1: *mut sqlite3_pcache, + arg2: *mut sqlite3_pcache_page, + oldKey: ::std::os::raw::c_uint, + newKey: ::std::os::raw::c_uint, + ), + >, + pub xTruncate: ::std::option::Option< + unsafe extern "C" fn(arg1: *mut sqlite3_pcache, iLimit: ::std::os::raw::c_uint), + >, + pub xDestroy: ::std::option::Option, + pub xShrink: ::std::option::Option, +} +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct sqlite3_pcache_methods { + pub pArg: *mut ::std::os::raw::c_void, + pub xInit: ::std::option::Option< + unsafe extern "C" fn(arg1: *mut ::std::os::raw::c_void) -> ::std::os::raw::c_int, + >, + pub xShutdown: ::std::option::Option< + unsafe extern "C" fn(arg1: *mut ::std::os::raw::c_void), + >, + pub xCreate: ::std::option::Option< + unsafe extern "C" fn( + szPage: ::std::os::raw::c_int, + bPurgeable: ::std::os::raw::c_int, + ) -> *mut sqlite3_pcache, + >, + pub xCachesize: ::std::option::Option< + unsafe extern "C" fn( + arg1: *mut sqlite3_pcache, + nCachesize: ::std::os::raw::c_int, + ), + >, + pub xPagecount: ::std::option::Option< + unsafe extern "C" fn(arg1: *mut sqlite3_pcache) -> ::std::os::raw::c_int, + >, + pub xFetch: ::std::option::Option< + unsafe extern "C" fn( + arg1: *mut sqlite3_pcache, + key: ::std::os::raw::c_uint, + createFlag: ::std::os::raw::c_int, + ) -> *mut ::std::os::raw::c_void, + >, + pub xUnpin: ::std::option::Option< + unsafe extern "C" fn( + arg1: *mut sqlite3_pcache, + arg2: *mut ::std::os::raw::c_void, + discard: ::std::os::raw::c_int, + ), + >, + pub xRekey: ::std::option::Option< + unsafe extern "C" fn( + arg1: *mut sqlite3_pcache, + arg2: *mut ::std::os::raw::c_void, + oldKey: ::std::os::raw::c_uint, + newKey: ::std::os::raw::c_uint, + ), + >, + pub xTruncate: ::std::option::Option< + unsafe extern "C" fn(arg1: *mut sqlite3_pcache, iLimit: ::std::os::raw::c_uint), + >, + pub xDestroy: ::std::option::Option, +} +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct sqlite3_backup { + _unused: [u8; 0], +} +extern "C" { + pub fn sqlite3_backup_init( + pDest: *mut sqlite3, + zDestName: *const ::std::os::raw::c_char, + pSource: *mut sqlite3, + zSourceName: *const ::std::os::raw::c_char, + ) -> *mut sqlite3_backup; +} +extern "C" { + pub fn sqlite3_backup_step( + p: *mut sqlite3_backup, + nPage: ::std::os::raw::c_int, + ) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn sqlite3_backup_finish(p: *mut sqlite3_backup) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn sqlite3_backup_remaining(p: *mut sqlite3_backup) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn sqlite3_backup_pagecount(p: *mut sqlite3_backup) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn sqlite3_stricmp( + arg1: *const ::std::os::raw::c_char, + arg2: *const ::std::os::raw::c_char, + ) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn sqlite3_strnicmp( + arg1: *const ::std::os::raw::c_char, + arg2: *const ::std::os::raw::c_char, + arg3: ::std::os::raw::c_int, + ) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn sqlite3_strglob( + zGlob: *const ::std::os::raw::c_char, + zStr: *const ::std::os::raw::c_char, + ) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn sqlite3_strlike( + zGlob: *const ::std::os::raw::c_char, + zStr: *const ::std::os::raw::c_char, + cEsc: ::std::os::raw::c_uint, + ) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn sqlite3_log( + iErrCode: ::std::os::raw::c_int, + zFormat: *const ::std::os::raw::c_char, + ... + ); +} +extern "C" { + pub fn sqlite3_wal_hook( + arg1: *mut sqlite3, + arg2: ::std::option::Option< + unsafe extern "C" fn( + arg1: *mut ::std::os::raw::c_void, + arg2: *mut sqlite3, + arg3: *const ::std::os::raw::c_char, + arg4: ::std::os::raw::c_int, + ) -> ::std::os::raw::c_int, + >, + arg3: *mut ::std::os::raw::c_void, + ) -> *mut ::std::os::raw::c_void; +} +extern "C" { + pub fn sqlite3_wal_autocheckpoint( + db: *mut sqlite3, + N: ::std::os::raw::c_int, + ) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn sqlite3_wal_checkpoint( + db: *mut sqlite3, + zDb: *const ::std::os::raw::c_char, + ) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn sqlite3_wal_checkpoint_v2( + db: *mut sqlite3, + zDb: *const ::std::os::raw::c_char, + eMode: ::std::os::raw::c_int, + pnLog: *mut ::std::os::raw::c_int, + pnCkpt: *mut ::std::os::raw::c_int, + ) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn sqlite3_vtab_config( + arg1: *mut sqlite3, + op: ::std::os::raw::c_int, + ... + ) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn sqlite3_vtab_on_conflict(arg1: *mut sqlite3) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn sqlite3_vtab_nochange(arg1: *mut sqlite3_context) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn sqlite3_vtab_collation( + arg1: *mut sqlite3_index_info, + arg2: ::std::os::raw::c_int, + ) -> *const ::std::os::raw::c_char; +} +extern "C" { + pub fn sqlite3_vtab_distinct(arg1: *mut sqlite3_index_info) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn sqlite3_vtab_in( + arg1: *mut sqlite3_index_info, + iCons: ::std::os::raw::c_int, + bHandle: ::std::os::raw::c_int, + ) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn sqlite3_vtab_in_first( + pVal: *mut sqlite3_value, + ppOut: *mut *mut sqlite3_value, + ) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn sqlite3_vtab_in_next( + pVal: *mut sqlite3_value, + ppOut: *mut *mut sqlite3_value, + ) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn sqlite3_vtab_rhs_value( + arg1: *mut sqlite3_index_info, + arg2: ::std::os::raw::c_int, + ppVal: *mut *mut sqlite3_value, + ) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn sqlite3_stmt_scanstatus( + pStmt: *mut sqlite3_stmt, + idx: ::std::os::raw::c_int, + iScanStatusOp: ::std::os::raw::c_int, + pOut: *mut ::std::os::raw::c_void, + ) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn sqlite3_stmt_scanstatus_v2( + pStmt: *mut sqlite3_stmt, + idx: ::std::os::raw::c_int, + iScanStatusOp: ::std::os::raw::c_int, + flags: ::std::os::raw::c_int, + pOut: *mut ::std::os::raw::c_void, + ) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn sqlite3_stmt_scanstatus_reset(arg1: *mut sqlite3_stmt); +} +extern "C" { + pub fn sqlite3_db_cacheflush(arg1: *mut sqlite3) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn sqlite3_preupdate_hook( + db: *mut sqlite3, + xPreUpdate: ::std::option::Option< + unsafe extern "C" fn( + pCtx: *mut ::std::os::raw::c_void, + db: *mut sqlite3, + op: ::std::os::raw::c_int, + zDb: *const ::std::os::raw::c_char, + zName: *const ::std::os::raw::c_char, + iKey1: sqlite3_int64, + iKey2: sqlite3_int64, + ), + >, + arg1: *mut ::std::os::raw::c_void, + ) -> *mut ::std::os::raw::c_void; +} +extern "C" { + pub fn sqlite3_preupdate_old( + arg1: *mut sqlite3, + arg2: ::std::os::raw::c_int, + arg3: *mut *mut sqlite3_value, + ) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn sqlite3_preupdate_count(arg1: *mut sqlite3) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn sqlite3_preupdate_depth(arg1: *mut sqlite3) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn sqlite3_preupdate_new( + arg1: *mut sqlite3, + arg2: ::std::os::raw::c_int, + arg3: *mut *mut sqlite3_value, + ) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn sqlite3_preupdate_blobwrite(arg1: *mut sqlite3) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn sqlite3_system_errno(arg1: *mut sqlite3) -> ::std::os::raw::c_int; +} +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct sqlite3_snapshot { + pub hidden: [::std::os::raw::c_uchar; 48usize], +} +extern "C" { + pub fn sqlite3_snapshot_get( + db: *mut sqlite3, + zSchema: *const ::std::os::raw::c_char, + ppSnapshot: *mut *mut sqlite3_snapshot, + ) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn sqlite3_snapshot_open( + db: *mut sqlite3, + zSchema: *const ::std::os::raw::c_char, + pSnapshot: *mut sqlite3_snapshot, + ) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn sqlite3_snapshot_free(arg1: *mut sqlite3_snapshot); +} +extern "C" { + pub fn sqlite3_snapshot_cmp( + p1: *mut sqlite3_snapshot, + p2: *mut sqlite3_snapshot, + ) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn sqlite3_snapshot_recover( + db: *mut sqlite3, + zDb: *const ::std::os::raw::c_char, + ) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn sqlite3_serialize( + db: *mut sqlite3, + zSchema: *const ::std::os::raw::c_char, + piSize: *mut sqlite3_int64, + mFlags: ::std::os::raw::c_uint, + ) -> *mut ::std::os::raw::c_uchar; +} +extern "C" { + pub fn sqlite3_deserialize( + db: *mut sqlite3, + zSchema: *const ::std::os::raw::c_char, + pData: *mut ::std::os::raw::c_uchar, + szDb: sqlite3_int64, + szBuf: sqlite3_int64, + mFlags: ::std::os::raw::c_uint, + ) -> ::std::os::raw::c_int; +} +pub type sqlite3_rtree_dbl = f64; +extern "C" { + pub fn sqlite3_rtree_geometry_callback( + db: *mut sqlite3, + zGeom: *const ::std::os::raw::c_char, + xGeom: ::std::option::Option< + unsafe extern "C" fn( + arg1: *mut sqlite3_rtree_geometry, + arg2: ::std::os::raw::c_int, + arg3: *mut sqlite3_rtree_dbl, + arg4: *mut ::std::os::raw::c_int, + ) -> ::std::os::raw::c_int, + >, + pContext: *mut ::std::os::raw::c_void, + ) -> ::std::os::raw::c_int; +} +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct sqlite3_rtree_geometry { + pub pContext: *mut ::std::os::raw::c_void, + pub nParam: ::std::os::raw::c_int, + pub aParam: *mut sqlite3_rtree_dbl, + pub pUser: *mut ::std::os::raw::c_void, + pub xDelUser: ::std::option::Option< + unsafe extern "C" fn(arg1: *mut ::std::os::raw::c_void), + >, +} +extern "C" { + pub fn sqlite3_rtree_query_callback( + db: *mut sqlite3, + zQueryFunc: *const ::std::os::raw::c_char, + xQueryFunc: ::std::option::Option< + unsafe extern "C" fn( + arg1: *mut sqlite3_rtree_query_info, + ) -> ::std::os::raw::c_int, + >, + pContext: *mut ::std::os::raw::c_void, + xDestructor: ::std::option::Option< + unsafe extern "C" fn(arg1: *mut ::std::os::raw::c_void), + >, + ) -> ::std::os::raw::c_int; +} +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct sqlite3_rtree_query_info { + pub pContext: *mut ::std::os::raw::c_void, + pub nParam: ::std::os::raw::c_int, + pub aParam: *mut sqlite3_rtree_dbl, + pub pUser: *mut ::std::os::raw::c_void, + pub xDelUser: ::std::option::Option< + unsafe extern "C" fn(arg1: *mut ::std::os::raw::c_void), + >, + pub aCoord: *mut sqlite3_rtree_dbl, + pub anQueue: *mut ::std::os::raw::c_uint, + pub nCoord: ::std::os::raw::c_int, + pub iLevel: ::std::os::raw::c_int, + pub mxLevel: ::std::os::raw::c_int, + pub iRowid: sqlite3_int64, + pub rParentScore: sqlite3_rtree_dbl, + pub eParentWithin: ::std::os::raw::c_int, + pub eWithin: ::std::os::raw::c_int, + pub rScore: sqlite3_rtree_dbl, + pub apSqlParam: *mut *mut sqlite3_value, +} +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct sqlite3_session { + _unused: [u8; 0], +} +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct sqlite3_changeset_iter { + _unused: [u8; 0], +} +extern "C" { + pub fn sqlite3session_create( + db: *mut sqlite3, + zDb: *const ::std::os::raw::c_char, + ppSession: *mut *mut sqlite3_session, + ) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn sqlite3session_delete(pSession: *mut sqlite3_session); +} +extern "C" { + pub fn sqlite3session_object_config( + arg1: *mut sqlite3_session, + op: ::std::os::raw::c_int, + pArg: *mut ::std::os::raw::c_void, + ) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn sqlite3session_enable( + pSession: *mut sqlite3_session, + bEnable: ::std::os::raw::c_int, + ) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn sqlite3session_indirect( + pSession: *mut sqlite3_session, + bIndirect: ::std::os::raw::c_int, + ) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn sqlite3session_attach( + pSession: *mut sqlite3_session, + zTab: *const ::std::os::raw::c_char, + ) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn sqlite3session_table_filter( + pSession: *mut sqlite3_session, + xFilter: ::std::option::Option< + unsafe extern "C" fn( + pCtx: *mut ::std::os::raw::c_void, + zTab: *const ::std::os::raw::c_char, + ) -> ::std::os::raw::c_int, + >, + pCtx: *mut ::std::os::raw::c_void, + ); +} +extern "C" { + pub fn sqlite3session_changeset( + pSession: *mut sqlite3_session, + pnChangeset: *mut ::std::os::raw::c_int, + ppChangeset: *mut *mut ::std::os::raw::c_void, + ) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn sqlite3session_changeset_size( + pSession: *mut sqlite3_session, + ) -> sqlite3_int64; +} +extern "C" { + pub fn sqlite3session_diff( + pSession: *mut sqlite3_session, + zFromDb: *const ::std::os::raw::c_char, + zTbl: *const ::std::os::raw::c_char, + pzErrMsg: *mut *mut ::std::os::raw::c_char, + ) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn sqlite3session_patchset( + pSession: *mut sqlite3_session, + pnPatchset: *mut ::std::os::raw::c_int, + ppPatchset: *mut *mut ::std::os::raw::c_void, + ) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn sqlite3session_isempty( + pSession: *mut sqlite3_session, + ) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn sqlite3session_memory_used(pSession: *mut sqlite3_session) -> sqlite3_int64; +} +extern "C" { + pub fn sqlite3changeset_start( + pp: *mut *mut sqlite3_changeset_iter, + nChangeset: ::std::os::raw::c_int, + pChangeset: *mut ::std::os::raw::c_void, + ) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn sqlite3changeset_start_v2( + pp: *mut *mut sqlite3_changeset_iter, + nChangeset: ::std::os::raw::c_int, + pChangeset: *mut ::std::os::raw::c_void, + flags: ::std::os::raw::c_int, + ) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn sqlite3changeset_next( + pIter: *mut sqlite3_changeset_iter, + ) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn sqlite3changeset_op( + pIter: *mut sqlite3_changeset_iter, + pzTab: *mut *const ::std::os::raw::c_char, + pnCol: *mut ::std::os::raw::c_int, + pOp: *mut ::std::os::raw::c_int, + pbIndirect: *mut ::std::os::raw::c_int, + ) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn sqlite3changeset_pk( + pIter: *mut sqlite3_changeset_iter, + pabPK: *mut *mut ::std::os::raw::c_uchar, + pnCol: *mut ::std::os::raw::c_int, + ) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn sqlite3changeset_old( + pIter: *mut sqlite3_changeset_iter, + iVal: ::std::os::raw::c_int, + ppValue: *mut *mut sqlite3_value, + ) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn sqlite3changeset_new( + pIter: *mut sqlite3_changeset_iter, + iVal: ::std::os::raw::c_int, + ppValue: *mut *mut sqlite3_value, + ) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn sqlite3changeset_conflict( + pIter: *mut sqlite3_changeset_iter, + iVal: ::std::os::raw::c_int, + ppValue: *mut *mut sqlite3_value, + ) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn sqlite3changeset_fk_conflicts( + pIter: *mut sqlite3_changeset_iter, + pnOut: *mut ::std::os::raw::c_int, + ) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn sqlite3changeset_finalize( + pIter: *mut sqlite3_changeset_iter, + ) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn sqlite3changeset_invert( + nIn: ::std::os::raw::c_int, + pIn: *const ::std::os::raw::c_void, + pnOut: *mut ::std::os::raw::c_int, + ppOut: *mut *mut ::std::os::raw::c_void, + ) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn sqlite3changeset_concat( + nA: ::std::os::raw::c_int, + pA: *mut ::std::os::raw::c_void, + nB: ::std::os::raw::c_int, + pB: *mut ::std::os::raw::c_void, + pnOut: *mut ::std::os::raw::c_int, + ppOut: *mut *mut ::std::os::raw::c_void, + ) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn sqlite3changeset_upgrade( + db: *mut sqlite3, + zDb: *const ::std::os::raw::c_char, + nIn: ::std::os::raw::c_int, + pIn: *const ::std::os::raw::c_void, + pnOut: *mut ::std::os::raw::c_int, + ppOut: *mut *mut ::std::os::raw::c_void, + ) -> ::std::os::raw::c_int; +} +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct sqlite3_changegroup { + _unused: [u8; 0], +} +extern "C" { + pub fn sqlite3changegroup_new( + pp: *mut *mut sqlite3_changegroup, + ) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn sqlite3changegroup_schema( + arg1: *mut sqlite3_changegroup, + arg2: *mut sqlite3, + zDb: *const ::std::os::raw::c_char, + ) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn sqlite3changegroup_add( + arg1: *mut sqlite3_changegroup, + nData: ::std::os::raw::c_int, + pData: *mut ::std::os::raw::c_void, + ) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn sqlite3changegroup_add_change( + arg1: *mut sqlite3_changegroup, + arg2: *mut sqlite3_changeset_iter, + ) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn sqlite3changegroup_output( + arg1: *mut sqlite3_changegroup, + pnData: *mut ::std::os::raw::c_int, + ppData: *mut *mut ::std::os::raw::c_void, + ) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn sqlite3changegroup_delete(arg1: *mut sqlite3_changegroup); +} +extern "C" { + pub fn sqlite3changeset_apply( + db: *mut sqlite3, + nChangeset: ::std::os::raw::c_int, + pChangeset: *mut ::std::os::raw::c_void, + xFilter: ::std::option::Option< + unsafe extern "C" fn( + pCtx: *mut ::std::os::raw::c_void, + zTab: *const ::std::os::raw::c_char, + ) -> ::std::os::raw::c_int, + >, + xConflict: ::std::option::Option< + unsafe extern "C" fn( + pCtx: *mut ::std::os::raw::c_void, + eConflict: ::std::os::raw::c_int, + p: *mut sqlite3_changeset_iter, + ) -> ::std::os::raw::c_int, + >, + pCtx: *mut ::std::os::raw::c_void, + ) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn sqlite3changeset_apply_v2( + db: *mut sqlite3, + nChangeset: ::std::os::raw::c_int, + pChangeset: *mut ::std::os::raw::c_void, + xFilter: ::std::option::Option< + unsafe extern "C" fn( + pCtx: *mut ::std::os::raw::c_void, + zTab: *const ::std::os::raw::c_char, + ) -> ::std::os::raw::c_int, + >, + xConflict: ::std::option::Option< + unsafe extern "C" fn( + pCtx: *mut ::std::os::raw::c_void, + eConflict: ::std::os::raw::c_int, + p: *mut sqlite3_changeset_iter, + ) -> ::std::os::raw::c_int, + >, + pCtx: *mut ::std::os::raw::c_void, + ppRebase: *mut *mut ::std::os::raw::c_void, + pnRebase: *mut ::std::os::raw::c_int, + flags: ::std::os::raw::c_int, + ) -> ::std::os::raw::c_int; +} +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct sqlite3_rebaser { + _unused: [u8; 0], +} +extern "C" { + pub fn sqlite3rebaser_create( + ppNew: *mut *mut sqlite3_rebaser, + ) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn sqlite3rebaser_configure( + arg1: *mut sqlite3_rebaser, + nRebase: ::std::os::raw::c_int, + pRebase: *const ::std::os::raw::c_void, + ) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn sqlite3rebaser_rebase( + arg1: *mut sqlite3_rebaser, + nIn: ::std::os::raw::c_int, + pIn: *const ::std::os::raw::c_void, + pnOut: *mut ::std::os::raw::c_int, + ppOut: *mut *mut ::std::os::raw::c_void, + ) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn sqlite3rebaser_delete(p: *mut sqlite3_rebaser); +} +extern "C" { + pub fn sqlite3changeset_apply_strm( + db: *mut sqlite3, + xInput: ::std::option::Option< + unsafe extern "C" fn( + pIn: *mut ::std::os::raw::c_void, + pData: *mut ::std::os::raw::c_void, + pnData: *mut ::std::os::raw::c_int, + ) -> ::std::os::raw::c_int, + >, + pIn: *mut ::std::os::raw::c_void, + xFilter: ::std::option::Option< + unsafe extern "C" fn( + pCtx: *mut ::std::os::raw::c_void, + zTab: *const ::std::os::raw::c_char, + ) -> ::std::os::raw::c_int, + >, + xConflict: ::std::option::Option< + unsafe extern "C" fn( + pCtx: *mut ::std::os::raw::c_void, + eConflict: ::std::os::raw::c_int, + p: *mut sqlite3_changeset_iter, + ) -> ::std::os::raw::c_int, + >, + pCtx: *mut ::std::os::raw::c_void, + ) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn sqlite3changeset_apply_v2_strm( + db: *mut sqlite3, + xInput: ::std::option::Option< + unsafe extern "C" fn( + pIn: *mut ::std::os::raw::c_void, + pData: *mut ::std::os::raw::c_void, + pnData: *mut ::std::os::raw::c_int, + ) -> ::std::os::raw::c_int, + >, + pIn: *mut ::std::os::raw::c_void, + xFilter: ::std::option::Option< + unsafe extern "C" fn( + pCtx: *mut ::std::os::raw::c_void, + zTab: *const ::std::os::raw::c_char, + ) -> ::std::os::raw::c_int, + >, + xConflict: ::std::option::Option< + unsafe extern "C" fn( + pCtx: *mut ::std::os::raw::c_void, + eConflict: ::std::os::raw::c_int, + p: *mut sqlite3_changeset_iter, + ) -> ::std::os::raw::c_int, + >, + pCtx: *mut ::std::os::raw::c_void, + ppRebase: *mut *mut ::std::os::raw::c_void, + pnRebase: *mut ::std::os::raw::c_int, + flags: ::std::os::raw::c_int, + ) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn sqlite3changeset_concat_strm( + xInputA: ::std::option::Option< + unsafe extern "C" fn( + pIn: *mut ::std::os::raw::c_void, + pData: *mut ::std::os::raw::c_void, + pnData: *mut ::std::os::raw::c_int, + ) -> ::std::os::raw::c_int, + >, + pInA: *mut ::std::os::raw::c_void, + xInputB: ::std::option::Option< + unsafe extern "C" fn( + pIn: *mut ::std::os::raw::c_void, + pData: *mut ::std::os::raw::c_void, + pnData: *mut ::std::os::raw::c_int, + ) -> ::std::os::raw::c_int, + >, + pInB: *mut ::std::os::raw::c_void, + xOutput: ::std::option::Option< + unsafe extern "C" fn( + pOut: *mut ::std::os::raw::c_void, + pData: *const ::std::os::raw::c_void, + nData: ::std::os::raw::c_int, + ) -> ::std::os::raw::c_int, + >, + pOut: *mut ::std::os::raw::c_void, + ) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn sqlite3changeset_invert_strm( + xInput: ::std::option::Option< + unsafe extern "C" fn( + pIn: *mut ::std::os::raw::c_void, + pData: *mut ::std::os::raw::c_void, + pnData: *mut ::std::os::raw::c_int, + ) -> ::std::os::raw::c_int, + >, + pIn: *mut ::std::os::raw::c_void, + xOutput: ::std::option::Option< + unsafe extern "C" fn( + pOut: *mut ::std::os::raw::c_void, + pData: *const ::std::os::raw::c_void, + nData: ::std::os::raw::c_int, + ) -> ::std::os::raw::c_int, + >, + pOut: *mut ::std::os::raw::c_void, + ) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn sqlite3changeset_start_strm( + pp: *mut *mut sqlite3_changeset_iter, + xInput: ::std::option::Option< + unsafe extern "C" fn( + pIn: *mut ::std::os::raw::c_void, + pData: *mut ::std::os::raw::c_void, + pnData: *mut ::std::os::raw::c_int, + ) -> ::std::os::raw::c_int, + >, + pIn: *mut ::std::os::raw::c_void, + ) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn sqlite3changeset_start_v2_strm( + pp: *mut *mut sqlite3_changeset_iter, + xInput: ::std::option::Option< + unsafe extern "C" fn( + pIn: *mut ::std::os::raw::c_void, + pData: *mut ::std::os::raw::c_void, + pnData: *mut ::std::os::raw::c_int, + ) -> ::std::os::raw::c_int, + >, + pIn: *mut ::std::os::raw::c_void, + flags: ::std::os::raw::c_int, + ) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn sqlite3session_changeset_strm( + pSession: *mut sqlite3_session, + xOutput: ::std::option::Option< + unsafe extern "C" fn( + pOut: *mut ::std::os::raw::c_void, + pData: *const ::std::os::raw::c_void, + nData: ::std::os::raw::c_int, + ) -> ::std::os::raw::c_int, + >, + pOut: *mut ::std::os::raw::c_void, + ) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn sqlite3session_patchset_strm( + pSession: *mut sqlite3_session, + xOutput: ::std::option::Option< + unsafe extern "C" fn( + pOut: *mut ::std::os::raw::c_void, + pData: *const ::std::os::raw::c_void, + nData: ::std::os::raw::c_int, + ) -> ::std::os::raw::c_int, + >, + pOut: *mut ::std::os::raw::c_void, + ) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn sqlite3changegroup_add_strm( + arg1: *mut sqlite3_changegroup, + xInput: ::std::option::Option< + unsafe extern "C" fn( + pIn: *mut ::std::os::raw::c_void, + pData: *mut ::std::os::raw::c_void, + pnData: *mut ::std::os::raw::c_int, + ) -> ::std::os::raw::c_int, + >, + pIn: *mut ::std::os::raw::c_void, + ) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn sqlite3changegroup_output_strm( + arg1: *mut sqlite3_changegroup, + xOutput: ::std::option::Option< + unsafe extern "C" fn( + pOut: *mut ::std::os::raw::c_void, + pData: *const ::std::os::raw::c_void, + nData: ::std::os::raw::c_int, + ) -> ::std::os::raw::c_int, + >, + pOut: *mut ::std::os::raw::c_void, + ) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn sqlite3rebaser_rebase_strm( + pRebaser: *mut sqlite3_rebaser, + xInput: ::std::option::Option< + unsafe extern "C" fn( + pIn: *mut ::std::os::raw::c_void, + pData: *mut ::std::os::raw::c_void, + pnData: *mut ::std::os::raw::c_int, + ) -> ::std::os::raw::c_int, + >, + pIn: *mut ::std::os::raw::c_void, + xOutput: ::std::option::Option< + unsafe extern "C" fn( + pOut: *mut ::std::os::raw::c_void, + pData: *const ::std::os::raw::c_void, + nData: ::std::os::raw::c_int, + ) -> ::std::os::raw::c_int, + >, + pOut: *mut ::std::os::raw::c_void, + ) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn sqlite3session_config( + op: ::std::os::raw::c_int, + pArg: *mut ::std::os::raw::c_void, + ) -> ::std::os::raw::c_int; +} +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct Fts5Context { + _unused: [u8; 0], +} +pub type fts5_extension_function = ::std::option::Option< + unsafe extern "C" fn( + pApi: *const Fts5ExtensionApi, + pFts: *mut Fts5Context, + pCtx: *mut sqlite3_context, + nVal: ::std::os::raw::c_int, + apVal: *mut *mut sqlite3_value, + ), +>; +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct Fts5PhraseIter { + pub a: *const ::std::os::raw::c_uchar, + pub b: *const ::std::os::raw::c_uchar, +} +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct Fts5ExtensionApi { + pub iVersion: ::std::os::raw::c_int, + pub xUserData: ::std::option::Option< + unsafe extern "C" fn(arg1: *mut Fts5Context) -> *mut ::std::os::raw::c_void, + >, + pub xColumnCount: ::std::option::Option< + unsafe extern "C" fn(arg1: *mut Fts5Context) -> ::std::os::raw::c_int, + >, + pub xRowCount: ::std::option::Option< + unsafe extern "C" fn( + arg1: *mut Fts5Context, + pnRow: *mut sqlite3_int64, + ) -> ::std::os::raw::c_int, + >, + pub xColumnTotalSize: ::std::option::Option< + unsafe extern "C" fn( + arg1: *mut Fts5Context, + iCol: ::std::os::raw::c_int, + pnToken: *mut sqlite3_int64, + ) -> ::std::os::raw::c_int, + >, + pub xTokenize: ::std::option::Option< + unsafe extern "C" fn( + arg1: *mut Fts5Context, + pText: *const ::std::os::raw::c_char, + nText: ::std::os::raw::c_int, + pCtx: *mut ::std::os::raw::c_void, + xToken: ::std::option::Option< + unsafe extern "C" fn( + arg1: *mut ::std::os::raw::c_void, + arg2: ::std::os::raw::c_int, + arg3: *const ::std::os::raw::c_char, + arg4: ::std::os::raw::c_int, + arg5: ::std::os::raw::c_int, + arg6: ::std::os::raw::c_int, + ) -> ::std::os::raw::c_int, + >, + ) -> ::std::os::raw::c_int, + >, + pub xPhraseCount: ::std::option::Option< + unsafe extern "C" fn(arg1: *mut Fts5Context) -> ::std::os::raw::c_int, + >, + pub xPhraseSize: ::std::option::Option< + unsafe extern "C" fn( + arg1: *mut Fts5Context, + iPhrase: ::std::os::raw::c_int, + ) -> ::std::os::raw::c_int, + >, + pub xInstCount: ::std::option::Option< + unsafe extern "C" fn( + arg1: *mut Fts5Context, + pnInst: *mut ::std::os::raw::c_int, + ) -> ::std::os::raw::c_int, + >, + pub xInst: ::std::option::Option< + unsafe extern "C" fn( + arg1: *mut Fts5Context, + iIdx: ::std::os::raw::c_int, + piPhrase: *mut ::std::os::raw::c_int, + piCol: *mut ::std::os::raw::c_int, + piOff: *mut ::std::os::raw::c_int, + ) -> ::std::os::raw::c_int, + >, + pub xRowid: ::std::option::Option< + unsafe extern "C" fn(arg1: *mut Fts5Context) -> sqlite3_int64, + >, + pub xColumnText: ::std::option::Option< + unsafe extern "C" fn( + arg1: *mut Fts5Context, + iCol: ::std::os::raw::c_int, + pz: *mut *const ::std::os::raw::c_char, + pn: *mut ::std::os::raw::c_int, + ) -> ::std::os::raw::c_int, + >, + pub xColumnSize: ::std::option::Option< + unsafe extern "C" fn( + arg1: *mut Fts5Context, + iCol: ::std::os::raw::c_int, + pnToken: *mut ::std::os::raw::c_int, + ) -> ::std::os::raw::c_int, + >, + pub xQueryPhrase: ::std::option::Option< + unsafe extern "C" fn( + arg1: *mut Fts5Context, + iPhrase: ::std::os::raw::c_int, + pUserData: *mut ::std::os::raw::c_void, + arg2: ::std::option::Option< + unsafe extern "C" fn( + arg1: *const Fts5ExtensionApi, + arg2: *mut Fts5Context, + arg3: *mut ::std::os::raw::c_void, + ) -> ::std::os::raw::c_int, + >, + ) -> ::std::os::raw::c_int, + >, + pub xSetAuxdata: ::std::option::Option< + unsafe extern "C" fn( + arg1: *mut Fts5Context, + pAux: *mut ::std::os::raw::c_void, + xDelete: ::std::option::Option< + unsafe extern "C" fn(arg1: *mut ::std::os::raw::c_void), + >, + ) -> ::std::os::raw::c_int, + >, + pub xGetAuxdata: ::std::option::Option< + unsafe extern "C" fn( + arg1: *mut Fts5Context, + bClear: ::std::os::raw::c_int, + ) -> *mut ::std::os::raw::c_void, + >, + pub xPhraseFirst: ::std::option::Option< + unsafe extern "C" fn( + arg1: *mut Fts5Context, + iPhrase: ::std::os::raw::c_int, + arg2: *mut Fts5PhraseIter, + arg3: *mut ::std::os::raw::c_int, + arg4: *mut ::std::os::raw::c_int, + ) -> ::std::os::raw::c_int, + >, + pub xPhraseNext: ::std::option::Option< + unsafe extern "C" fn( + arg1: *mut Fts5Context, + arg2: *mut Fts5PhraseIter, + piCol: *mut ::std::os::raw::c_int, + piOff: *mut ::std::os::raw::c_int, + ), + >, + pub xPhraseFirstColumn: ::std::option::Option< + unsafe extern "C" fn( + arg1: *mut Fts5Context, + iPhrase: ::std::os::raw::c_int, + arg2: *mut Fts5PhraseIter, + arg3: *mut ::std::os::raw::c_int, + ) -> ::std::os::raw::c_int, + >, + pub xPhraseNextColumn: ::std::option::Option< + unsafe extern "C" fn( + arg1: *mut Fts5Context, + arg2: *mut Fts5PhraseIter, + piCol: *mut ::std::os::raw::c_int, + ), + >, + pub xQueryToken: ::std::option::Option< + unsafe extern "C" fn( + arg1: *mut Fts5Context, + iPhrase: ::std::os::raw::c_int, + iToken: ::std::os::raw::c_int, + ppToken: *mut *const ::std::os::raw::c_char, + pnToken: *mut ::std::os::raw::c_int, + ) -> ::std::os::raw::c_int, + >, + pub xInstToken: ::std::option::Option< + unsafe extern "C" fn( + arg1: *mut Fts5Context, + iIdx: ::std::os::raw::c_int, + iToken: ::std::os::raw::c_int, + arg2: *mut *const ::std::os::raw::c_char, + arg3: *mut ::std::os::raw::c_int, + ) -> ::std::os::raw::c_int, + >, + pub xColumnLocale: ::std::option::Option< + unsafe extern "C" fn( + arg1: *mut Fts5Context, + iCol: ::std::os::raw::c_int, + pz: *mut *const ::std::os::raw::c_char, + pn: *mut ::std::os::raw::c_int, + ) -> ::std::os::raw::c_int, + >, + pub xTokenize_v2: ::std::option::Option< + unsafe extern "C" fn( + arg1: *mut Fts5Context, + pText: *const ::std::os::raw::c_char, + nText: ::std::os::raw::c_int, + pLocale: *const ::std::os::raw::c_char, + nLocale: ::std::os::raw::c_int, + pCtx: *mut ::std::os::raw::c_void, + xToken: ::std::option::Option< + unsafe extern "C" fn( + arg1: *mut ::std::os::raw::c_void, + arg2: ::std::os::raw::c_int, + arg3: *const ::std::os::raw::c_char, + arg4: ::std::os::raw::c_int, + arg5: ::std::os::raw::c_int, + arg6: ::std::os::raw::c_int, + ) -> ::std::os::raw::c_int, + >, + ) -> ::std::os::raw::c_int, + >, +} +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct Fts5Tokenizer { + _unused: [u8; 0], +} +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct fts5_tokenizer_v2 { + pub iVersion: ::std::os::raw::c_int, + pub xCreate: ::std::option::Option< + unsafe extern "C" fn( + arg1: *mut ::std::os::raw::c_void, + azArg: *mut *const ::std::os::raw::c_char, + nArg: ::std::os::raw::c_int, + ppOut: *mut *mut Fts5Tokenizer, + ) -> ::std::os::raw::c_int, + >, + pub xDelete: ::std::option::Option, + pub xTokenize: ::std::option::Option< + unsafe extern "C" fn( + arg1: *mut Fts5Tokenizer, + pCtx: *mut ::std::os::raw::c_void, + flags: ::std::os::raw::c_int, + pText: *const ::std::os::raw::c_char, + nText: ::std::os::raw::c_int, + pLocale: *const ::std::os::raw::c_char, + nLocale: ::std::os::raw::c_int, + xToken: ::std::option::Option< + unsafe extern "C" fn( + pCtx: *mut ::std::os::raw::c_void, + tflags: ::std::os::raw::c_int, + pToken: *const ::std::os::raw::c_char, + nToken: ::std::os::raw::c_int, + iStart: ::std::os::raw::c_int, + iEnd: ::std::os::raw::c_int, + ) -> ::std::os::raw::c_int, + >, + ) -> ::std::os::raw::c_int, + >, +} +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct fts5_tokenizer { + pub xCreate: ::std::option::Option< + unsafe extern "C" fn( + arg1: *mut ::std::os::raw::c_void, + azArg: *mut *const ::std::os::raw::c_char, + nArg: ::std::os::raw::c_int, + ppOut: *mut *mut Fts5Tokenizer, + ) -> ::std::os::raw::c_int, + >, + pub xDelete: ::std::option::Option, + pub xTokenize: ::std::option::Option< + unsafe extern "C" fn( + arg1: *mut Fts5Tokenizer, + pCtx: *mut ::std::os::raw::c_void, + flags: ::std::os::raw::c_int, + pText: *const ::std::os::raw::c_char, + nText: ::std::os::raw::c_int, + xToken: ::std::option::Option< + unsafe extern "C" fn( + pCtx: *mut ::std::os::raw::c_void, + tflags: ::std::os::raw::c_int, + pToken: *const ::std::os::raw::c_char, + nToken: ::std::os::raw::c_int, + iStart: ::std::os::raw::c_int, + iEnd: ::std::os::raw::c_int, + ) -> ::std::os::raw::c_int, + >, + ) -> ::std::os::raw::c_int, + >, +} +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct fts5_api { + pub iVersion: ::std::os::raw::c_int, + pub xCreateTokenizer: ::std::option::Option< + unsafe extern "C" fn( + pApi: *mut fts5_api, + zName: *const ::std::os::raw::c_char, + pUserData: *mut ::std::os::raw::c_void, + pTokenizer: *mut fts5_tokenizer, + xDestroy: ::std::option::Option< + unsafe extern "C" fn(arg1: *mut ::std::os::raw::c_void), + >, + ) -> ::std::os::raw::c_int, + >, + pub xFindTokenizer: ::std::option::Option< + unsafe extern "C" fn( + pApi: *mut fts5_api, + zName: *const ::std::os::raw::c_char, + ppUserData: *mut *mut ::std::os::raw::c_void, + pTokenizer: *mut fts5_tokenizer, + ) -> ::std::os::raw::c_int, + >, + pub xCreateFunction: ::std::option::Option< + unsafe extern "C" fn( + pApi: *mut fts5_api, + zName: *const ::std::os::raw::c_char, + pUserData: *mut ::std::os::raw::c_void, + xFunction: fts5_extension_function, + xDestroy: ::std::option::Option< + unsafe extern "C" fn(arg1: *mut ::std::os::raw::c_void), + >, + ) -> ::std::os::raw::c_int, + >, + pub xCreateTokenizer_v2: ::std::option::Option< + unsafe extern "C" fn( + pApi: *mut fts5_api, + zName: *const ::std::os::raw::c_char, + pUserData: *mut ::std::os::raw::c_void, + pTokenizer: *mut fts5_tokenizer_v2, + xDestroy: ::std::option::Option< + unsafe extern "C" fn(arg1: *mut ::std::os::raw::c_void), + >, + ) -> ::std::os::raw::c_int, + >, + pub xFindTokenizer_v2: ::std::option::Option< + unsafe extern "C" fn( + pApi: *mut fts5_api, + zName: *const ::std::os::raw::c_char, + ppUserData: *mut *mut ::std::os::raw::c_void, + ppTokenizer: *mut *mut fts5_tokenizer_v2, + ) -> ::std::os::raw::c_int, + >, +} diff --git a/vendor/sqlite-wasm-rs/src/shim/libsqlite3/error.rs b/vendor/sqlite-wasm-rs/src/shim/libsqlite3/error.rs new file mode 100644 index 0000000..4cfedde --- /dev/null +++ b/vendor/sqlite-wasm-rs/src/shim/libsqlite3/error.rs @@ -0,0 +1,275 @@ +use std::error; +use std::fmt; +use std::os::raw::c_int; + +/// Error Codes +#[derive(Clone, Copy, Debug, PartialEq, Eq)] +#[non_exhaustive] +pub enum ErrorCode { + /// Internal logic error in `SQLite` + InternalMalfunction, + /// Access permission denied + PermissionDenied, + /// Callback routine requested an abort + OperationAborted, + /// The database file is locked + DatabaseBusy, + /// A table in the database is locked + DatabaseLocked, + /// A `malloc()` failed + OutOfMemory, + /// Attempt to write a readonly database + ReadOnly, + /// Operation terminated by `sqlite3_interrupt()` + OperationInterrupted, + /// Some kind of disk I/O error occurred + SystemIoFailure, + /// The database disk image is malformed + DatabaseCorrupt, + /// Unknown opcode in `sqlite3_file_control()` + NotFound, + /// Insertion failed because database is full + DiskFull, + /// Unable to open the database file + CannotOpen, + /// Database lock protocol error + FileLockingProtocolFailed, + /// The database schema changed + SchemaChanged, + /// String or BLOB exceeds size limit + TooBig, + /// Abort due to constraint violation + ConstraintViolation, + /// Data type mismatch + TypeMismatch, + /// Library used incorrectly + ApiMisuse, + /// Uses OS features not supported on host + NoLargeFileSupport, + /// Authorization denied + AuthorizationForStatementDenied, + /// 2nd parameter to `sqlite3_bind` out of range + ParameterOutOfRange, + /// File opened that is not a database file + NotADatabase, + /// SQL error or missing database + Unknown, +} + +#[derive(Clone, Copy, Debug, PartialEq, Eq)] +pub struct Error { + pub code: ErrorCode, + pub extended_code: c_int, +} + +impl Error { + #[must_use] + pub fn new(result_code: c_int) -> Self { + let code = match result_code & 0xff { + super::SQLITE_INTERNAL => ErrorCode::InternalMalfunction, + super::SQLITE_PERM => ErrorCode::PermissionDenied, + super::SQLITE_ABORT => ErrorCode::OperationAborted, + super::SQLITE_BUSY => ErrorCode::DatabaseBusy, + super::SQLITE_LOCKED => ErrorCode::DatabaseLocked, + super::SQLITE_NOMEM => ErrorCode::OutOfMemory, + super::SQLITE_READONLY => ErrorCode::ReadOnly, + super::SQLITE_INTERRUPT => ErrorCode::OperationInterrupted, + super::SQLITE_IOERR => ErrorCode::SystemIoFailure, + super::SQLITE_CORRUPT => ErrorCode::DatabaseCorrupt, + super::SQLITE_NOTFOUND => ErrorCode::NotFound, + super::SQLITE_FULL => ErrorCode::DiskFull, + super::SQLITE_CANTOPEN => ErrorCode::CannotOpen, + super::SQLITE_PROTOCOL => ErrorCode::FileLockingProtocolFailed, + super::SQLITE_SCHEMA => ErrorCode::SchemaChanged, + super::SQLITE_TOOBIG => ErrorCode::TooBig, + super::SQLITE_CONSTRAINT => ErrorCode::ConstraintViolation, + super::SQLITE_MISMATCH => ErrorCode::TypeMismatch, + super::SQLITE_MISUSE => ErrorCode::ApiMisuse, + super::SQLITE_NOLFS => ErrorCode::NoLargeFileSupport, + super::SQLITE_AUTH => ErrorCode::AuthorizationForStatementDenied, + super::SQLITE_RANGE => ErrorCode::ParameterOutOfRange, + super::SQLITE_NOTADB => ErrorCode::NotADatabase, + _ => ErrorCode::Unknown, + }; + + Self { + code, + extended_code: result_code, + } + } +} + +impl fmt::Display for Error { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + write!( + f, + "Error code {}: {}", + self.extended_code, + code_to_str(self.extended_code) + ) + } +} + +impl error::Error for Error { + fn description(&self) -> &str { + code_to_str(self.extended_code) + } +} + +// Result codes. +// Note: These are not public because our bindgen bindings export whichever +// constants are present in the current version of SQLite. We repeat them here, +// so we don't have to worry about which version of SQLite added which +// constants, and we only use them to implement code_to_str below. + +// Extended result codes. + +const SQLITE_ERROR_MISSING_COLLSEQ: c_int = super::SQLITE_ERROR | (1 << 8); +const SQLITE_ERROR_RETRY: c_int = super::SQLITE_ERROR | (2 << 8); +const SQLITE_ERROR_SNAPSHOT: c_int = super::SQLITE_ERROR | (3 << 8); + +const SQLITE_IOERR_BEGIN_ATOMIC: c_int = super::SQLITE_IOERR | (29 << 8); +const SQLITE_IOERR_COMMIT_ATOMIC: c_int = super::SQLITE_IOERR | (30 << 8); +const SQLITE_IOERR_ROLLBACK_ATOMIC: c_int = super::SQLITE_IOERR | (31 << 8); +const SQLITE_IOERR_DATA: c_int = super::SQLITE_IOERR | (32 << 8); +const SQLITE_IOERR_CORRUPTFS: c_int = super::SQLITE_IOERR | (33 << 8); +const SQLITE_IOERR_IN_PAGE: c_int = super::SQLITE_IOERR | (34 << 8); + +const SQLITE_LOCKED_VTAB: c_int = super::SQLITE_LOCKED | (2 << 8); + +const SQLITE_BUSY_TIMEOUT: c_int = super::SQLITE_BUSY | (3 << 8); + +const SQLITE_CANTOPEN_SYMLINK: c_int = super::SQLITE_CANTOPEN | (6 << 8); + +const SQLITE_CORRUPT_SEQUENCE: c_int = super::SQLITE_CORRUPT | (2 << 8); +const SQLITE_CORRUPT_INDEX: c_int = super::SQLITE_CORRUPT | (3 << 8); + +const SQLITE_READONLY_CANTINIT: c_int = super::SQLITE_READONLY | (5 << 8); +const SQLITE_READONLY_DIRECTORY: c_int = super::SQLITE_READONLY | (6 << 8); + +const SQLITE_CONSTRAINT_PINNED: c_int = super::SQLITE_CONSTRAINT | (11 << 8); +const SQLITE_CONSTRAINT_DATATYPE: c_int = super::SQLITE_CONSTRAINT | (12 << 8); + +#[must_use] +pub fn code_to_str(code: c_int) -> &'static str { + match code { + super::SQLITE_OK => "Successful result", + super::SQLITE_ERROR => "SQL error or missing database", + super::SQLITE_INTERNAL => "Internal logic error in SQLite", + super::SQLITE_PERM => "Access permission denied", + super::SQLITE_ABORT => "Callback routine requested an abort", + super::SQLITE_BUSY => "The database file is locked", + super::SQLITE_LOCKED => "A table in the database is locked", + super::SQLITE_NOMEM => "A malloc() failed", + super::SQLITE_READONLY => "Attempt to write a readonly database", + super::SQLITE_INTERRUPT => "Operation terminated by sqlite3_interrupt()", + super::SQLITE_IOERR => "Some kind of disk I/O error occurred", + super::SQLITE_CORRUPT => "The database disk image is malformed", + super::SQLITE_NOTFOUND => "Unknown opcode in sqlite3_file_control()", + super::SQLITE_FULL => "Insertion failed because database is full", + super::SQLITE_CANTOPEN => "Unable to open the database file", + super::SQLITE_PROTOCOL => "Database lock protocol error", + super::SQLITE_EMPTY => "Database is empty", + super::SQLITE_SCHEMA => "The database schema changed", + super::SQLITE_TOOBIG => "String or BLOB exceeds size limit", + super::SQLITE_CONSTRAINT=> "Abort due to constraint violation", + super::SQLITE_MISMATCH => "Data type mismatch", + super::SQLITE_MISUSE => "Library used incorrectly", + super::SQLITE_NOLFS => "Uses OS features not supported on host", + super::SQLITE_AUTH => "Authorization denied", + super::SQLITE_FORMAT => "Auxiliary database format error", + super::SQLITE_RANGE => "2nd parameter to sqlite3_bind out of range", + super::SQLITE_NOTADB => "File opened that is not a database file", + super::SQLITE_NOTICE => "Notifications from sqlite3_log()", + super::SQLITE_WARNING => "Warnings from sqlite3_log()", + super::SQLITE_ROW => "sqlite3_step() has another row ready", + super::SQLITE_DONE => "sqlite3_step() has finished executing", + + SQLITE_ERROR_MISSING_COLLSEQ => "SQLITE_ERROR_MISSING_COLLSEQ", + SQLITE_ERROR_RETRY => "SQLITE_ERROR_RETRY", + SQLITE_ERROR_SNAPSHOT => "SQLITE_ERROR_SNAPSHOT", + + super::SQLITE_IOERR_READ => "Error reading from disk", + super::SQLITE_IOERR_SHORT_READ => "Unable to obtain number of requested bytes (file truncated?)", + super::SQLITE_IOERR_WRITE => "Error writing to disk", + super::SQLITE_IOERR_FSYNC => "Error flushing data to persistent storage (fsync)", + super::SQLITE_IOERR_DIR_FSYNC => "Error calling fsync on a directory", + super::SQLITE_IOERR_TRUNCATE => "Error attempting to truncate file", + super::SQLITE_IOERR_FSTAT => "Error invoking fstat to get file metadata", + super::SQLITE_IOERR_UNLOCK => "I/O error within xUnlock of a VFS object", + super::SQLITE_IOERR_RDLOCK => "I/O error within xLock of a VFS object (trying to obtain a read lock)", + super::SQLITE_IOERR_DELETE => "I/O error within xDelete of a VFS object", + super::SQLITE_IOERR_BLOCKED => "SQLITE_IOERR_BLOCKED", // no longer used + super::SQLITE_IOERR_NOMEM => "Out of memory in I/O layer", + super::SQLITE_IOERR_ACCESS => "I/O error within xAccess of a VFS object", + super::SQLITE_IOERR_CHECKRESERVEDLOCK => "I/O error within then xCheckReservedLock method", + super::SQLITE_IOERR_LOCK => "I/O error in the advisory file locking layer", + super::SQLITE_IOERR_CLOSE => "I/O error within the xClose method", + super::SQLITE_IOERR_DIR_CLOSE => "SQLITE_IOERR_DIR_CLOSE", // no longer used + super::SQLITE_IOERR_SHMOPEN => "I/O error within the xShmMap method (trying to open a new shared-memory segment)", + super::SQLITE_IOERR_SHMSIZE => "I/O error within the xShmMap method (trying to resize an existing shared-memory segment)", + super::SQLITE_IOERR_SHMLOCK => "SQLITE_IOERR_SHMLOCK", // no longer used + super::SQLITE_IOERR_SHMMAP => "I/O error within the xShmMap method (trying to map a shared-memory segment into process address space)", + super::SQLITE_IOERR_SEEK => "I/O error within the xRead or xWrite (trying to seek within a file)", + super::SQLITE_IOERR_DELETE_NOENT => "File being deleted does not exist", + super::SQLITE_IOERR_MMAP => "I/O error while trying to map or unmap part of the database file into process address space", + super::SQLITE_IOERR_GETTEMPPATH => "VFS is unable to determine a suitable directory for temporary files", + super::SQLITE_IOERR_CONVPATH => "cygwin_conv_path() system call failed", + super::SQLITE_IOERR_VNODE => "SQLITE_IOERR_VNODE", // not documented? + super::SQLITE_IOERR_AUTH => "SQLITE_IOERR_AUTH", + SQLITE_IOERR_BEGIN_ATOMIC => "SQLITE_IOERR_BEGIN_ATOMIC", + SQLITE_IOERR_COMMIT_ATOMIC => "SQLITE_IOERR_COMMIT_ATOMIC", + SQLITE_IOERR_ROLLBACK_ATOMIC => "SQLITE_IOERR_ROLLBACK_ATOMIC", + SQLITE_IOERR_DATA => "SQLITE_IOERR_DATA", + SQLITE_IOERR_CORRUPTFS => "SQLITE_IOERR_CORRUPTFS", + SQLITE_IOERR_IN_PAGE => "SQLITE_IOERR_IN_PAGE", + + super::SQLITE_LOCKED_SHAREDCACHE => "Locking conflict due to another connection with a shared cache", + SQLITE_LOCKED_VTAB => "SQLITE_LOCKED_VTAB", + + super::SQLITE_BUSY_RECOVERY => "Another process is recovering a WAL mode database file", + super::SQLITE_BUSY_SNAPSHOT => "Cannot promote read transaction to write transaction because of writes by another connection", + SQLITE_BUSY_TIMEOUT => "SQLITE_BUSY_TIMEOUT", + + super::SQLITE_CANTOPEN_NOTEMPDIR => "SQLITE_CANTOPEN_NOTEMPDIR", // no longer used + super::SQLITE_CANTOPEN_ISDIR => "Attempted to open directory as file", + super::SQLITE_CANTOPEN_FULLPATH => "Unable to convert filename into full pathname", + super::SQLITE_CANTOPEN_CONVPATH => "cygwin_conv_path() system call failed", + SQLITE_CANTOPEN_SYMLINK => "SQLITE_CANTOPEN_SYMLINK", + + super::SQLITE_CORRUPT_VTAB => "Content in the virtual table is corrupt", + SQLITE_CORRUPT_SEQUENCE => "SQLITE_CORRUPT_SEQUENCE", + SQLITE_CORRUPT_INDEX => "SQLITE_CORRUPT_INDEX", + + super::SQLITE_READONLY_RECOVERY => "WAL mode database file needs recovery (requires write access)", + super::SQLITE_READONLY_CANTLOCK => "Shared-memory file associated with WAL mode database is read-only", + super::SQLITE_READONLY_ROLLBACK => "Database has hot journal that must be rolled back (requires write access)", + super::SQLITE_READONLY_DBMOVED => "Database cannot be modified because database file has moved", + SQLITE_READONLY_CANTINIT => "SQLITE_READONLY_CANTINIT", + SQLITE_READONLY_DIRECTORY => "SQLITE_READONLY_DIRECTORY", + + super::SQLITE_ABORT_ROLLBACK => "Transaction was rolled back", + + super::SQLITE_CONSTRAINT_CHECK => "A CHECK constraint failed", + super::SQLITE_CONSTRAINT_COMMITHOOK => "Commit hook caused rollback", + super::SQLITE_CONSTRAINT_FOREIGNKEY => "Foreign key constraint failed", + super::SQLITE_CONSTRAINT_FUNCTION => "Error returned from extension function", + super::SQLITE_CONSTRAINT_NOTNULL => "A NOT NULL constraint failed", + super::SQLITE_CONSTRAINT_PRIMARYKEY => "A PRIMARY KEY constraint failed", + super::SQLITE_CONSTRAINT_TRIGGER => "A RAISE function within a trigger fired", + super::SQLITE_CONSTRAINT_UNIQUE => "A UNIQUE constraint failed", + super::SQLITE_CONSTRAINT_VTAB => "An application-defined virtual table error occurred", + super::SQLITE_CONSTRAINT_ROWID => "A non-unique rowid occurred", + SQLITE_CONSTRAINT_PINNED => "SQLITE_CONSTRAINT_PINNED", + SQLITE_CONSTRAINT_DATATYPE => "SQLITE_CONSTRAINT_DATATYPE", + + super::SQLITE_NOTICE_RECOVER_WAL => "A WAL mode database file was recovered", + super::SQLITE_NOTICE_RECOVER_ROLLBACK => "Hot journal was rolled back", + + super::SQLITE_WARNING_AUTOINDEX => "Automatic indexing used - database might benefit from additional indexes", + + super::SQLITE_AUTH_USER => "SQLITE_AUTH_USER", // not documented? + + _ => "Unknown error code", + } +} diff --git a/vendor/sqlite-wasm-rs/src/shim/libsqlite3/mod.rs b/vendor/sqlite-wasm-rs/src/shim/libsqlite3/mod.rs new file mode 100644 index 0000000..b424f5f --- /dev/null +++ b/vendor/sqlite-wasm-rs/src/shim/libsqlite3/mod.rs @@ -0,0 +1,36 @@ +//! This module is codegen from build.rs + +#[cfg(feature = "buildtime-bindgen")] +mod bindings { + include!(concat!(env!("OUT_DIR"), "/bindings.rs")); +} +#[cfg(not(feature = "buildtime-bindgen"))] +mod bindings; +mod error; + +pub use bindings::*; +pub use error::*; + +use std::mem; + +#[must_use] +pub fn SQLITE_STATIC() -> sqlite3_destructor_type { + None +} + +#[must_use] +pub fn SQLITE_TRANSIENT() -> sqlite3_destructor_type { + Some(unsafe { mem::transmute::(-1_isize) }) +} + +impl Default for sqlite3_vtab { + fn default() -> Self { + unsafe { mem::zeroed() } + } +} + +impl Default for sqlite3_vtab_cursor { + fn default() -> Self { + unsafe { mem::zeroed() } + } +} diff --git a/vendor/sqlite-wasm-rs/src/shim/mod.rs b/vendor/sqlite-wasm-rs/src/shim/mod.rs new file mode 100644 index 0000000..8ae70dd --- /dev/null +++ b/vendor/sqlite-wasm-rs/src/shim/mod.rs @@ -0,0 +1,27 @@ +#[allow(non_upper_case_globals)] +#[allow(non_camel_case_types)] +#[allow(non_snake_case)] +#[allow(clippy::type_complexity)] +mod libsqlite3; + +#[allow(non_upper_case_globals)] +#[allow(non_camel_case_types)] +#[allow(non_snake_case)] +mod r#impl; + +#[allow(non_upper_case_globals)] +#[allow(non_camel_case_types)] +#[allow(non_snake_case)] +mod vfs; + +/// These exported APIs are stable and will not have breaking changes. +pub mod export { + // Some sqlite types copied from libsqlite3-sys + pub use super::libsqlite3::*; + pub use super::vfs::sahpool::{ + install_opfs_sahpool, OpfsSAHError, OpfsSAHPoolCfg, OpfsSAHPoolCfgBuilder, OpfsSAHPoolUtil, + }; + + #[cfg(feature = "custom-libc")] + pub use sqlite_wasm_libc; +} diff --git a/vendor/sqlite-wasm-rs/src/shim/vfs/memory.rs b/vendor/sqlite-wasm-rs/src/shim/vfs/memory.rs new file mode 100644 index 0000000..d55f21c --- /dev/null +++ b/vendor/sqlite-wasm-rs/src/shim/vfs/memory.rs @@ -0,0 +1,355 @@ +//! Memory VFS, used as the default VFS + +use std::{collections::HashMap, ffi::CStr, sync::Arc}; + +use js_sys::{Date, Math}; +use once_cell::sync::Lazy; + +use crate::export::*; +use crate::locker::{Mutex, MutexGuard, RwLock}; + +/// thread::sleep is available when atomics are enabled +#[cfg(target_feature = "atomics")] +unsafe extern "C" fn xSleep( + _pVfs: *mut sqlite3_vfs, + microseconds: ::std::os::raw::c_int, +) -> ::std::os::raw::c_int { + use std::{thread, time::Duration}; + + thread::sleep(Duration::from_micros(microseconds as u64)); + SQLITE_OK +} + +#[cfg(not(target_feature = "atomics"))] +unsafe extern "C" fn xSleep( + _pVfs: *mut sqlite3_vfs, + _microseconds: ::std::os::raw::c_int, +) -> ::std::os::raw::c_int { + SQLITE_OK +} + +/// https://github.com/sqlite/sqlite/blob/fb9e8e48fd70b463fb7ba6d99e00f2be54df749e/ext/wasm/api/sqlite3-vfs-opfs.c-pp.js#L951 +unsafe extern "C" fn xRandomness( + _pVfs: *mut sqlite3_vfs, + nByte: ::std::os::raw::c_int, + zOut: *mut ::std::os::raw::c_char, +) -> ::std::os::raw::c_int { + for i in 0..nByte { + *zOut.offset(i as isize) = (Math::random() * 255000.0) as _; + } + nByte +} + +/// https://github.com/sqlite/sqlite/blob/fb9e8e48fd70b463fb7ba6d99e00f2be54df749e/ext/wasm/api/sqlite3-vfs-opfs.c-pp.js#L870 +unsafe extern "C" fn xCurrentTime( + _pVfs: *mut sqlite3_vfs, + pTimeOut: *mut f64, +) -> ::std::os::raw::c_int { + *pTimeOut = 2440587.5 + (Date::new_0().get_time() / 86400000.0); + SQLITE_OK +} + +/// https://github.com/sqlite/sqlite/blob/fb9e8e48fd70b463fb7ba6d99e00f2be54df749e/ext/wasm/api/sqlite3-vfs-opfs.c-pp.js#L877 +unsafe extern "C" fn xCurrentTimeInt64( + _pVfs: *mut sqlite3_vfs, + pOut: *mut sqlite3_int64, +) -> ::std::os::raw::c_int { + *pOut = ((2440587.5 * 86400000.0) + Date::new_0().get_time()) as sqlite3_int64; + SQLITE_OK +} + +/// pFile -> mem_file +fn file2file() -> MutexGuard<'static, HashMap>>> { + static PFILE: Lazy>>>> = + Lazy::new(|| Mutex::new(HashMap::new())); + + PFILE.lock() +} + +/// filename -> mem_file +fn name2file() -> MutexGuard<'static, HashMap>>> { + static NAME: Lazy>>>> = + Lazy::new(|| Mutex::new(HashMap::new())); + + NAME.lock() +} + +/// An open file +struct MemFile { + // filename + name: String, + /// flags + flags: i32, + /// content of the file + data: Vec, +} + +unsafe impl Send for MemFile {} +unsafe impl Sync for MemFile {} + +unsafe extern "C" fn xOpen( + _pVfs: *mut sqlite3_vfs, + zName: sqlite3_filename, + pFile: *mut sqlite3_file, + flags: ::std::os::raw::c_int, + pOutFlags: *mut ::std::os::raw::c_int, +) -> ::std::os::raw::c_int { + let Ok(s) = CStr::from_ptr(zName).to_str() else { + return SQLITE_ERROR; + }; + + let mut name2file = name2file(); + let mem_file = if let Some(mem_file) = name2file.get(s) { + Arc::clone(mem_file) + } else { + if flags & SQLITE_OPEN_CREATE == 0 { + return SQLITE_CANTOPEN; + } + let file = Arc::new(RwLock::new(MemFile { + name: s.into(), + flags, + data: Vec::new(), + })); + name2file.insert(s.into(), Arc::clone(&file)); + file + }; + + file2file().insert(pFile as usize, mem_file); + + (*pFile).pMethods = &IO_METHODS; + + if !pOutFlags.is_null() { + *pOutFlags = flags; + } + + SQLITE_OK +} + +unsafe extern "C" fn xDelete( + _pVfs: *mut sqlite3_vfs, + zName: *const ::std::os::raw::c_char, + _syncDir: ::std::os::raw::c_int, +) -> ::std::os::raw::c_int { + let Ok(s) = CStr::from_ptr(zName).to_str() else { + return SQLITE_ERROR; + }; + name2file().remove(s); + SQLITE_OK +} + +unsafe extern "C" fn xAccess( + _pVfs: *mut sqlite3_vfs, + zName: *const ::std::os::raw::c_char, + _flags: ::std::os::raw::c_int, + pResOut: *mut ::std::os::raw::c_int, +) -> ::std::os::raw::c_int { + let Ok(s) = CStr::from_ptr(zName).to_str() else { + return SQLITE_ERROR; + }; + *pResOut = i32::from(name2file().contains_key(s)); + SQLITE_OK +} + +unsafe extern "C" fn xFullPathname( + _pVfs: *mut sqlite3_vfs, + zName: *const ::std::os::raw::c_char, + nOut: ::std::os::raw::c_int, + zOut: *mut ::std::os::raw::c_char, +) -> ::std::os::raw::c_int { + zName.copy_to(zOut, nOut as usize); + SQLITE_OK +} + +unsafe extern "C" fn xGetLastError( + _pVfs: *mut sqlite3_vfs, + _nOut: ::std::os::raw::c_int, + _zOut: *mut ::std::os::raw::c_char, +) -> ::std::os::raw::c_int { + SQLITE_OK +} + +unsafe extern "C" fn xClose(pFile: *mut sqlite3_file) -> ::std::os::raw::c_int { + if let Some(file) = file2file().remove(&(pFile as usize)) { + let file = file.write(); + if file.flags & SQLITE_OPEN_DELETEONCLOSE != 0 { + name2file().remove(&file.name); + } + } + SQLITE_OK +} + +unsafe extern "C" fn xRead( + pFile: *mut sqlite3_file, + zBuf: *mut ::std::os::raw::c_void, + iAmt: ::std::os::raw::c_int, + iOfst: sqlite3_int64, +) -> ::std::os::raw::c_int { + let Some(file) = file2file().get(&(pFile as usize)).cloned() else { + return SQLITE_ERROR; + }; + let file = file.read(); + let data = &file.data; + + let end = iOfst as usize + iAmt as usize; + let slice = std::slice::from_raw_parts_mut(zBuf.cast::(), iAmt as usize); + + if data.len() <= iOfst as usize { + slice.fill(0); + return SQLITE_IOERR_SHORT_READ; + } + + let read_size = end.min(data.len()) - iOfst as usize; + slice[..read_size].copy_from_slice(&data[iOfst as usize..end.min(data.len())]); + + if read_size < iAmt as usize { + slice[read_size..iAmt as usize].fill(0); + return SQLITE_IOERR_SHORT_READ; + } + + SQLITE_OK +} + +unsafe extern "C" fn xWrite( + pFile: *mut sqlite3_file, + zBuf: *const ::std::os::raw::c_void, + iAmt: ::std::os::raw::c_int, + iOfst: sqlite3_int64, +) -> ::std::os::raw::c_int { + let Some(file) = file2file().get(&(pFile as usize)).cloned() else { + return SQLITE_ERROR; + }; + let end = iOfst as usize + iAmt as usize; + let mut file = file.write(); + let data = &mut file.data; + + if end > data.len() { + data.resize(end, 0); + } + let slice = std::slice::from_raw_parts(zBuf.cast::(), iAmt as usize); + + data[iOfst as usize..end].copy_from_slice(slice); + + SQLITE_OK +} + +unsafe extern "C" fn xTruncate( + pFile: *mut sqlite3_file, + size: sqlite3_int64, +) -> ::std::os::raw::c_int { + let Some(file) = file2file().get(&(pFile as usize)).cloned() else { + return SQLITE_ERROR; + }; + let mut file = file.write(); + let now = file.data.len(); + file.data.truncate(now.min(size as usize)); + SQLITE_OK +} + +unsafe extern "C" fn xSync( + _pFile: *mut sqlite3_file, + _flags: ::std::os::raw::c_int, +) -> ::std::os::raw::c_int { + SQLITE_OK +} + +unsafe extern "C" fn xFileSize( + pFile: *mut sqlite3_file, + pSize: *mut sqlite3_int64, +) -> ::std::os::raw::c_int { + let Some(file) = file2file().get(&(pFile as usize)).cloned() else { + return SQLITE_ERROR; + }; + *pSize = file.read().data.len() as sqlite3_int64; + SQLITE_OK +} + +unsafe extern "C" fn xLock( + _pFile: *mut sqlite3_file, + _eLock: ::std::os::raw::c_int, +) -> ::std::os::raw::c_int { + SQLITE_OK +} + +unsafe extern "C" fn xUnlock( + _pFile: *mut sqlite3_file, + _eLock: ::std::os::raw::c_int, +) -> ::std::os::raw::c_int { + SQLITE_OK +} + +unsafe extern "C" fn xCheckReservedLock( + _pFile: *mut sqlite3_file, + pResOut: *mut ::std::os::raw::c_int, +) -> ::std::os::raw::c_int { + *pResOut = 0; + SQLITE_OK +} + +unsafe extern "C" fn xFileControl( + _pVfs: *mut sqlite3_file, + _op: ::std::os::raw::c_int, + _pArg: *mut ::std::os::raw::c_void, +) -> ::std::os::raw::c_int { + SQLITE_NOTFOUND +} + +unsafe extern "C" fn xSectorSize(_pFile: *mut sqlite3_file) -> ::std::os::raw::c_int { + 512 +} + +unsafe extern "C" fn xDeviceCharacteristics(_arg1: *mut sqlite3_file) -> ::std::os::raw::c_int { + 0 +} + +static IO_METHODS: sqlite3_io_methods = sqlite3_io_methods { + iVersion: 1, + xClose: Some(xClose), + xRead: Some(xRead), + xWrite: Some(xWrite), + xTruncate: Some(xTruncate), + xSync: Some(xSync), + xFileSize: Some(xFileSize), + xLock: Some(xLock), + xUnlock: Some(xUnlock), + xCheckReservedLock: Some(xCheckReservedLock), + xFileControl: Some(xFileControl), + xSectorSize: Some(xSectorSize), + xDeviceCharacteristics: Some(xDeviceCharacteristics), + xShmMap: None, + xShmLock: None, + xShmBarrier: None, + xShmUnmap: None, + xFetch: None, + xUnfetch: None, +}; + +fn vfs() -> sqlite3_vfs { + sqlite3_vfs { + iVersion: 1, + szOsFile: std::mem::size_of::() as i32, + mxPathname: 1024, + pNext: std::ptr::null_mut(), + zName: c"memvfs".as_ptr().cast(), + pAppData: std::ptr::null_mut(), + xOpen: Some(xOpen), + xDelete: Some(xDelete), + xAccess: Some(xAccess), + xFullPathname: Some(xFullPathname), + xDlOpen: None, + xDlError: None, + xDlSym: None, + xDlClose: None, + xRandomness: Some(xRandomness), + xSleep: Some(xSleep), + xCurrentTime: Some(xCurrentTime), + xGetLastError: Some(xGetLastError), + xCurrentTimeInt64: Some(xCurrentTimeInt64), + xSetSystemCall: None, + xGetSystemCall: None, + xNextSystemCall: None, + } +} + +pub(crate) fn install_memory_vfs() -> ::std::os::raw::c_int { + unsafe { sqlite3_vfs_register(Box::leak(Box::new(vfs())), 1) } +} diff --git a/vendor/sqlite-wasm-rs/src/shim/vfs/mod.rs b/vendor/sqlite-wasm-rs/src/shim/vfs/mod.rs new file mode 100644 index 0000000..017aa96 --- /dev/null +++ b/vendor/sqlite-wasm-rs/src/shim/vfs/mod.rs @@ -0,0 +1,4 @@ +#![doc = include_str!("../../../VFS.md")] + +pub mod memory; +pub mod sahpool; diff --git a/vendor/sqlite-wasm-rs/src/shim/vfs/sahpool.rs b/vendor/sqlite-wasm-rs/src/shim/vfs/sahpool.rs new file mode 100644 index 0000000..c20636a --- /dev/null +++ b/vendor/sqlite-wasm-rs/src/shim/vfs/sahpool.rs @@ -0,0 +1,1203 @@ +//! opfs-sahpool vfs implementation, ported from sqlite-wasm +//! +//! + +use crate::{export::*, locker::RwLock}; + +use crate::fragile::FragileComfirmed; +use crate::locker::Mutex; +use js_sys::{ + Array, DataView, IteratorNext, Map, Math, Number, Object, Reflect, Set, Uint32Array, Uint8Array, +}; +use once_cell::sync::Lazy; +use std::ffi::CString; +use std::sync::Arc; +use std::{collections::HashMap, ffi::CStr}; +use wasm_bindgen::{JsCast, JsValue}; +use wasm_bindgen_futures::JsFuture; +use web_sys::{ + FileSystemDirectoryHandle, FileSystemFileHandle, FileSystemGetDirectoryOptions, + FileSystemGetFileOptions, FileSystemReadWriteOptions, FileSystemSyncAccessHandle, Url, + WorkerGlobalScope, +}; + +const SECTOR_SIZE: usize = 4096; +const HEADER_MAX_PATH_SIZE: usize = 512; +const HEADER_FLAGS_SIZE: usize = 4; +const HEADER_DIGEST_SIZE: usize = 8; +const HEADER_CORPUS_SIZE: usize = HEADER_MAX_PATH_SIZE + HEADER_FLAGS_SIZE; +const HEADER_OFFSET_FLAGS: usize = HEADER_MAX_PATH_SIZE; +const HEADER_OFFSET_DIGEST: usize = HEADER_CORPUS_SIZE; +const HEADER_OFFSET_DATA: usize = SECTOR_SIZE; + +const PERSISTENT_FILE_TYPES: i32 = + SQLITE_OPEN_MAIN_DB | SQLITE_OPEN_MAIN_JOURNAL | SQLITE_OPEN_SUPER_JOURNAL | SQLITE_OPEN_WAL; + +static VFS2SAH: Lazy>>> = + Lazy::new(|| RwLock::new(HashMap::new())); + +fn pool(vfs: *mut sqlite3_vfs) -> Arc> { + VFS2SAH.read().get(&(vfs as usize)).unwrap().pool.clone() +} + +fn read_write_options(at: f64) -> FileSystemReadWriteOptions { + let options = FileSystemReadWriteOptions::new(); + options.set_at(at); + options +} + +unsafe fn file2vfs(file: *mut sqlite3_file) -> *mut sqlite3_vfs { + (*(file.cast::())).vfs +} + +// this function only return [0, 0] for now +// +// https://github.com/sqlite/sqlite-wasm/issues/97 +fn compute_digest(_byte_array: &Uint8Array) -> Uint32Array { + let u32_array = Uint32Array::new_with_length(2); + u32_array.set_index(0, 0); + u32_array.set_index(1, 0); + u32_array +} + +fn get_random_name() -> String { + let random = Number::from(Math::random()).to_string(36).unwrap(); + random.slice(2, random.length()).as_string().unwrap() +} + +#[repr(C)] +struct OpfsFile { + io_methods: sqlite3_file, + vfs: *mut sqlite3_vfs, +} + +struct FileObject { + path: String, + flags: i32, + sah: FileSystemSyncAccessHandle, +} + +impl FileObject { + fn new(obj: Object) -> Result { + let path = Reflect::get(&obj, &JsValue::from("path")) + .map_err(OpfsSAHError::Reflect)? + .as_string() + .ok_or_else(|| OpfsSAHError::Custom("path not string".into()))?; + + let flags = Reflect::get(&obj, &JsValue::from("flags")) + .map_err(OpfsSAHError::Reflect)? + .as_f64() + .ok_or_else(|| OpfsSAHError::Custom("flags not number".into()))? + as i32; + + let sah = Reflect::get(&obj, &JsValue::from("sah")) + .map_err(OpfsSAHError::Reflect)? + .into(); + + Ok(Self { path, flags, sah }) + } +} + +/// Class for managing OPFS-related state for the OPFS +/// SharedAccessHandle Pool sqlite3_vfs. +struct OpfsSAHPool { + /// Directory handle to the subdir of vfs root which holds + /// the randomly-named "opaque" files. This subdir exists in the + /// hope that we can eventually support client-created files in + dh_opaque: FileSystemDirectoryHandle, + /// Buffer used by [sg]etAssociatedPath() + ap_body: Uint8Array, + /// DataView for self.apBody + dv_body: DataView, + /// Maps client-side file names to SAHs + map_filename_to_sah: Map, + /// Set of currently-unused SAHs + available_sah: Set, + /// Maps SAHs to their opaque file names + map_sah_to_name: Map, + /// Maps (sqlite3_file*) to xOpen's file objects + map_s3_file_to_o_file: Map, + /// Store last_error + /// + /// Never poison, unwrap `lock()` is fine + last_error: Mutex>, +} + +impl OpfsSAHPool { + async fn new(options: &OpfsSAHPoolCfg) -> Result { + const OPAQUE_DIR_NAME: &str = ".opaque"; + + let vfs_dir = &options.directory; + let capacity = options.initial_capacity; + let clear_files = options.clear_on_init; + + let create_option = FileSystemGetDirectoryOptions::new(); + create_option.set_create(true); + + let mut handle: FileSystemDirectoryHandle = JsFuture::from( + js_sys::global() + .dyn_into::() + .map_err(|_| OpfsSAHError::NotSuported)? + .navigator() + .storage() + .get_directory(), + ) + .await + .map_err(OpfsSAHError::GetDirHandle)? + .into(); + + for dir in vfs_dir.split('/').filter(|x| !x.is_empty()) { + let next = + JsFuture::from(handle.get_directory_handle_with_options(dir, &create_option)) + .await + .map_err(OpfsSAHError::GetDirHandle)? + .into(); + handle = next; + } + + let dh_opaque = JsFuture::from( + handle.get_directory_handle_with_options(OPAQUE_DIR_NAME, &create_option), + ) + .await + .map_err(OpfsSAHError::GetDirHandle)? + .into(); + + let ap_body = Uint8Array::new_with_length(HEADER_CORPUS_SIZE as _); + let dv_body = DataView::new( + &ap_body.buffer(), + ap_body.byte_offset() as usize, + (ap_body.byte_length() - ap_body.byte_offset()) as usize, + ); + + let pool = Self { + dh_opaque, + ap_body, + dv_body, + map_filename_to_sah: Map::new(), + available_sah: Set::default(), + map_sah_to_name: Map::new(), + map_s3_file_to_o_file: Map::new(), + last_error: Mutex::new(None), + }; + pool.acquire_access_handles(clear_files).await?; + if pool.get_capacity() == 0 { + pool.add_capacity(capacity).await?; + } + + Ok(pool) + } + + /// Adds n files to the pool's capacity. This change is + /// persistent across settings. Returns a Promise which resolves + /// to the new capacity. + async fn add_capacity(&self, n: u32) -> Result { + for _ in 0..n { + let name = get_random_name(); + let handle: FileSystemFileHandle = + JsFuture::from(self.dh_opaque.get_file_handle_with_options(&name, &{ + let options = FileSystemGetFileOptions::new(); + options.set_create(true); + options + })) + .await + .map_err(OpfsSAHError::GetFileHandle)? + .into(); + let sah: FileSystemSyncAccessHandle = + JsFuture::from(handle.create_sync_access_handle()) + .await + .map_err(OpfsSAHError::CreateSyncAccessHandle)? + .into(); + self.map_sah_to_name.set(&sah, &JsValue::from(name)); + self.set_associated_path(&sah, "", 0)?; + } + Ok(self.get_capacity()) + } + + /// Reduce capacity by n, but can only reduce up to the limit + /// of currently-available SAHs. Returns a Promise which resolves + /// to the number of slots really removed. + async fn reduce_capacity(&self, n: u32) -> Result { + let mut result = 0; + for sah in Array::from(&self.available_sah) { + if result == n || self.get_capacity() == self.get_file_count() { + break; + } + let sah = FileSystemSyncAccessHandle::from(sah); + + let name = self.map_sah_to_name.get(&sah); + assert!(!name.is_undefined(), "name must exists"); + let name = name.as_string().unwrap(); + + sah.close(); + JsFuture::from(self.dh_opaque.remove_entry(&name)) + .await + .map_err(OpfsSAHError::RemoveEntity)?; + self.map_sah_to_name.delete(&sah); + self.available_sah.delete(&sah); + result += 1; + } + Ok(result) + } + + /// Current pool capacity. + fn get_capacity(&self) -> u32 { + self.map_sah_to_name.size() + } + + /// Current number of in-use files from pool. + fn get_file_count(&self) -> u32 { + self.map_filename_to_sah.size() + } + + /// Returns an array of the names of all + /// currently-opened client-specified filenames. + fn get_file_names(&self) -> Vec { + let mut result = vec![]; + for name in self.map_filename_to_sah.keys().into_iter().flatten() { + result.push(name.as_string().unwrap()); + } + result + } + + /// Given an SAH, returns the client-specified name of + /// that file by extracting it from the SAH's header. + /// On error, it disassociates SAH from the pool and + /// returns an empty string. + fn get_associated_path( + &self, + sah: &FileSystemSyncAccessHandle, + ) -> Result, OpfsSAHError> { + sah.read_with_buffer_source_and_options(&self.ap_body, &read_write_options(0.0)) + .map_err(OpfsSAHError::Read)?; + let flags = self.dv_body.get_uint32(HEADER_OFFSET_FLAGS); + if self.ap_body.get_index(0) != 0 + && ((flags & SQLITE_OPEN_DELETEONCLOSE as u32 != 0) + || (flags & PERSISTENT_FILE_TYPES as u32) == 0) + { + self.set_associated_path(sah, "", 0)?; + return Ok(None); + } + + // size is 2 + let file_digest = Uint32Array::new_with_length(HEADER_DIGEST_SIZE as u32 / 4); + sah.read_with_buffer_source_and_options( + &file_digest, + &read_write_options(HEADER_OFFSET_DIGEST as f64), + ) + .map_err(OpfsSAHError::Read)?; + + let comp_digest = compute_digest(&self.ap_body); + if Array::from(&file_digest) + .every(&mut |v, i, _| v.as_f64().unwrap() as u32 == comp_digest.get_index(i)) + { + let path_size = Array::from(&self.ap_body) + .find_index(&mut |x, _, _| x.as_f64().unwrap() as u8 == 0) + as u32; + if path_size == 0 { + sah.truncate_with_u32(HEADER_OFFSET_DATA as u32) + .map_err(OpfsSAHError::Truncate)?; + return Ok(None); + } + let path_bytes = self.ap_body.subarray(0, path_size); + let mut path = vec![0; path_size as usize]; + for idx in 0..path_size { + // why not `copy_to`? + // + // see + path[idx as usize] = path_bytes.get_index(idx); + } + // set_associated_path ensures that it is utf8 + let path = String::from_utf8(path).unwrap(); + Ok(Some(path)) + } else { + self.set_associated_path(sah, "", 0)?; + Ok(None) + } + } + + /// Stores the given client-defined path and SQLITE_OPEN_xyz flags + /// into the given SAH. If path is an empty string then the file is + /// disassociated from the pool but its previous name is preserved + /// in the metadata. + fn set_associated_path( + &self, + sah: &FileSystemSyncAccessHandle, + path: &str, + flags: i32, + ) -> Result<(), OpfsSAHError> { + if HEADER_MAX_PATH_SIZE < path.len() { + return Err(OpfsSAHError::Custom(format!("Path too long: {path}"))); + } + for (idx, byte) in path.bytes().enumerate() { + // why not `copy_from`? + // + // see + self.ap_body.set_index(idx as u32, byte); + } + + self.ap_body + .fill(0, path.len() as u32, HEADER_MAX_PATH_SIZE as u32); + self.dv_body.set_uint32(HEADER_OFFSET_FLAGS, flags as u32); + + let digest = compute_digest(&self.ap_body); + + sah.write_with_js_u8_array_and_options(&self.ap_body, &read_write_options(0.0)) + .map_err(OpfsSAHError::Write)?; + sah.write_with_buffer_source_and_options( + &digest, + &read_write_options(HEADER_OFFSET_DIGEST as f64), + ) + .map_err(OpfsSAHError::Write)?; + sah.flush().map_err(OpfsSAHError::Flush)?; + + if path.is_empty() { + sah.truncate_with_u32(HEADER_OFFSET_DATA as u32) + .map_err(OpfsSAHError::Truncate)?; + self.available_sah.add(sah); + } else { + self.map_filename_to_sah.set(&JsValue::from(path), sah); + self.available_sah.delete(sah); + } + + Ok(()) + } + + /// Opens all files under self.dh_opaque and acquires + /// a SAH for each. returns a Promise which resolves to no value + /// but completes once all SAHs are acquired. If acquiring an SAH + /// throws, SAHPool.$error will contain the corresponding + /// exception. + /// + /// If clearFiles is true, the client-stored state of each file is + /// cleared when its handle is acquired, including its name, flags, + /// and any data stored after the metadata block. + async fn acquire_access_handles(&self, clear_files: bool) -> Result<(), OpfsSAHError> { + let mut files = vec![]; + let iter = self.dh_opaque.entries(); + while let Ok(future) = iter.next() { + let next: IteratorNext = JsFuture::from(future) + .await + .map_err(OpfsSAHError::IterHandle)? + .into(); + if next.done() { + break; + } + let array: Array = next.value().into(); + let key = array.get(0); + let value = array.get(1); + let kind = Reflect::get(&value, &JsValue::from("kind")) + .map_err(OpfsSAHError::Reflect)? + .as_string(); + if kind.as_deref() == Some("file") { + files.push((key, FileSystemFileHandle::from(value))); + } + } + + let fut = async { + for (file, handle) in files { + let sah = JsFuture::from(handle.create_sync_access_handle()) + .await + .map_err(OpfsSAHError::CreateSyncAccessHandle)?; + self.map_sah_to_name.set(&sah, &file); + let sah = FileSystemSyncAccessHandle::from(sah); + if clear_files { + sah.truncate_with_u32(HEADER_OFFSET_DATA as u32) + .map_err(OpfsSAHError::Truncate)?; + self.set_associated_path(&sah, "", 0)?; + } else if let Some(path) = self.get_associated_path(&sah)? { + self.map_filename_to_sah.set(&JsValue::from(path), &sah); + } else { + self.available_sah.add(&sah); + } + } + Ok::<_, OpfsSAHError>(()) + }; + + if let Err(e) = fut.await { + self.store_err(&e, None); + self.release_access_handles(); + return Err(e); + } + + Ok(()) + } + + /// Releases all currently-opened SAHs. The only legal + /// operation after this is acquireAccessHandles(). + fn release_access_handles(&self) { + for sah in self.map_sah_to_name.keys().into_iter().flatten() { + let sah = FileSystemSyncAccessHandle::from(sah); + sah.close(); + } + self.map_sah_to_name.clear(); + self.map_filename_to_sah.clear(); + self.available_sah.clear(); + } + + /// Pops this object's Error object and returns + /// it (a falsy value if no error is set). + fn pop_err(&self) -> Option<(i32, String)> { + self.last_error.lock().take() + } + + /// Sets e (an Error object) as this object's current error. Pass a + /// falsy (or no) value to clear it. If code is truthy it is + /// assumed to be an SQLITE_xxx result code, defaulting to + /// SQLITE_IOERR if code is falsy. + fn store_err(&self, err: &OpfsSAHError, code: Option) -> i32 { + let code = code.unwrap_or(SQLITE_IOERR); + self.last_error.lock().replace((code, format!("{:?}", err))); + code + } + + /// Given an (sqlite3_file*), returns the mapped + /// xOpen file object. + fn get_o_file_for_s3_file( + &self, + p_file: *mut sqlite3_file, + ) -> Result { + let file = self.map_s3_file_to_o_file.get(&JsValue::from(p_file)); + if file.is_undefined() { + return Err(OpfsSAHError::Custom("open file not exists".into())); + } + FileObject::new(file.into()) + } + + /// Maps or unmaps (if file is falsy) the given (sqlite3_file*) + /// to an xOpen file object and to this pool object. + fn map_s3_file_to_o_file(&self, p_file: *mut sqlite3_file, file: Option) { + if let Some(file) = file { + self.map_s3_file_to_o_file + .set(&JsValue::from(p_file), &JsValue::from(file)); + } else { + self.map_s3_file_to_o_file.delete(&JsValue::from(p_file)); + } + } + + /// Removes the association of the given client-specified file + /// name (JS string) from the pool. Returns true if a mapping + /// is found, else false. + fn delete_path(&self, path: &str) -> Result { + let sah = self.map_filename_to_sah.get(&JsValue::from(path)); + let found = !sah.is_undefined(); + if found { + let sah: FileSystemSyncAccessHandle = sah.into(); + self.map_filename_to_sah.delete(&JsValue::from(path)); + self.set_associated_path(&sah, "", 0)?; + } + Ok(found) + } + + /// All "../" parts and duplicate slashes are resolve/removed from + /// the returned result. + fn get_path(&self, name: *const ::std::os::raw::c_char) -> Result { + if name.is_null() { + return Err(OpfsSAHError::Custom("name is null ptr".into())); + } + let name = unsafe { + CStr::from_ptr(name) + .to_str() + .map_err(|e| OpfsSAHError::Custom(format!("{e:?}")))? + }; + Url::new_with_base(name, "file://localhost/") + .map(|x| x.pathname()) + .map_err(OpfsSAHError::GetPath) + } + + /// Returns true if the given client-defined file name is in this + /// object's name-to-SAH map. + fn has_filename(&self, name: &str) -> bool { + self.map_filename_to_sah.has(&JsValue::from(name)) + } + + /// Returns the SAH associated with the given + /// client-defined file name. + fn get_sah_for_path(&self, path: &str) -> Option { + self.has_filename(path) + .then(|| self.map_filename_to_sah.get(&JsValue::from(path)).into()) + } + + /// Returns the next available SAH without removing + /// it from the set. + fn next_available_sah(&self) -> Option { + self.available_sah + .keys() + .next() + .ok() + .filter(|x| !x.done()) + .map(|x| x.value().into()) + } + + fn export_file(&self, name: &str) -> Result, OpfsSAHError> { + let sah = self.map_filename_to_sah.get(&JsValue::from(name)); + if sah.is_undefined() { + return Err(OpfsSAHError::Custom("File not found:".into())); + } + let sah = FileSystemSyncAccessHandle::from(sah); + let n = sah.get_size().map_err(OpfsSAHError::GetSize)? - HEADER_OFFSET_DATA as f64; + let n = n.max(0.0) as usize; + let mut data = vec![0; n]; + if n > 0 { + let read = sah + .read_with_u8_array_and_options( + &mut data, + &read_write_options(HEADER_OFFSET_DATA as f64), + ) + .map_err(OpfsSAHError::Read)?; + if read != n as f64 { + return Err(OpfsSAHError::Custom(format!( + "Expected to read {} bytes but read {}.", + n, read + ))); + } + } + Ok(data) + } + + fn import_db(&self, path: &str, bytes: &[u8]) -> Result<(), OpfsSAHError> { + const HEADER: &str = "SQLite format 3"; + + let sah = self.map_filename_to_sah.get(&JsValue::from(path)); + let sah = if sah.is_undefined() { + self.next_available_sah() + .ok_or_else(|| OpfsSAHError::Custom("No available handles to import to.".into()))? + } else { + FileSystemSyncAccessHandle::from(sah) + }; + let length = bytes.len(); + if length < 512 && length % 512 != 0 { + return Err(OpfsSAHError::Custom( + "Byte array size is invalid for an SQLite db.".into(), + )); + } + if HEADER.as_bytes().iter().zip(bytes).any(|(x, y)| x != y) { + return Err(OpfsSAHError::Custom( + "Input does not contain an SQLite database header.".into(), + )); + } + let write = sah + .write_with_u8_array_and_options(bytes, &read_write_options(HEADER_OFFSET_DATA as f64)) + .map_err(OpfsSAHError::Write)?; + if write != length as f64 { + self.set_associated_path(&sah, "", 0)?; + return Err(OpfsSAHError::Custom(format!( + "Expected to write {} bytes but wrote {}.", + length, write + ))); + } + + let bytes = [1, 1]; + sah.write_with_u8_array_and_options( + &bytes, + &read_write_options((HEADER_OFFSET_DATA + 18) as f64), + ) + .map_err(OpfsSAHError::Write)?; + self.set_associated_path(&sah, path, SQLITE_OPEN_MAIN_DB)?; + + Ok(()) + } +} + +unsafe extern "C" fn xCheckReservedLock( + pFile: *mut sqlite3_file, + pResOut: *mut ::std::os::raw::c_int, +) -> ::std::os::raw::c_int { + let vfs = file2vfs(pFile); + let pool = pool(vfs); + pool.pop_err(); + + *pResOut = 1; + SQLITE_OK +} + +unsafe extern "C" fn xClose(pFile: *mut sqlite3_file) -> ::std::os::raw::c_int { + let vfs = file2vfs(pFile); + let pool = pool(vfs); + pool.pop_err(); + + let f = || { + if let Ok(file) = pool.get_o_file_for_s3_file(pFile) { + pool.map_s3_file_to_o_file(pFile, None); + file.sah.flush().map_err(OpfsSAHError::Flush)?; + if (file.flags & SQLITE_OPEN_DELETEONCLOSE) != 0 { + pool.delete_path(&file.path)?; + } + } + Ok::<_, OpfsSAHError>(()) + }; + + if let Err(e) = f() { + return pool.store_err(&e, Some(SQLITE_IOERR)); + } + SQLITE_OK +} + +unsafe extern "C" fn xDeviceCharacteristics(_pFile: *mut sqlite3_file) -> ::std::os::raw::c_int { + SQLITE_IOCAP_UNDELETABLE_WHEN_OPEN +} + +unsafe extern "C" fn xFileControl( + _pFile: *mut sqlite3_file, + _op: ::std::os::raw::c_int, + _pArg: *mut ::std::os::raw::c_void, +) -> ::std::os::raw::c_int { + SQLITE_NOTFOUND +} + +unsafe extern "C" fn xFileSize( + pFile: *mut sqlite3_file, + pSize: *mut sqlite3_int64, +) -> ::std::os::raw::c_int { + let vfs = file2vfs(pFile); + let pool = pool(vfs); + + if let Ok(file) = pool.get_o_file_for_s3_file(pFile) { + let size = file.sah.get_size().unwrap() as i64 - HEADER_OFFSET_DATA as i64; + *pSize = size; + } + SQLITE_OK +} + +unsafe extern "C" fn xLock( + _pFile: *mut sqlite3_file, + _eLock: ::std::os::raw::c_int, +) -> ::std::os::raw::c_int { + SQLITE_OK +} + +unsafe extern "C" fn xRead( + pFile: *mut sqlite3_file, + zBuf: *mut ::std::os::raw::c_void, + iAmt: ::std::os::raw::c_int, + iOfst: sqlite3_int64, +) -> ::std::os::raw::c_int { + let vfs = file2vfs(pFile); + let pool = pool(vfs); + pool.pop_err(); + + let f = || { + let file = pool.get_o_file_for_s3_file(pFile)?; + let slice = std::slice::from_raw_parts_mut(zBuf.cast::(), iAmt as usize); + + let n_read = file + .sah + .read_with_u8_array_and_options( + slice, + &read_write_options((HEADER_OFFSET_DATA as i64 + iOfst) as f64), + ) + .map_err(OpfsSAHError::Read)?; + + if (n_read as i32) < iAmt { + slice[n_read as usize..iAmt as usize].fill(0); + return Ok(SQLITE_IOERR_SHORT_READ); + } + + Ok::(SQLITE_OK) + }; + + match f() { + Ok(ret) => ret, + Err(e) => pool.store_err(&e, Some(SQLITE_IOERR)), + } +} + +unsafe extern "C" fn xSectorSize(_pFile: *mut sqlite3_file) -> ::std::os::raw::c_int { + SECTOR_SIZE as i32 +} + +unsafe extern "C" fn xSync( + pFile: *mut sqlite3_file, + _flags: ::std::os::raw::c_int, +) -> ::std::os::raw::c_int { + let vfs = file2vfs(pFile); + let pool = pool(vfs); + pool.pop_err(); + + if let Err(e) = pool + .get_o_file_for_s3_file(pFile) + .and_then(|file| file.sah.flush().map_err(OpfsSAHError::Flush)) + { + return pool.store_err(&e, Some(SQLITE_IOERR)); + } + + SQLITE_OK +} + +unsafe extern "C" fn xTruncate( + pFile: *mut sqlite3_file, + size: sqlite3_int64, +) -> ::std::os::raw::c_int { + let vfs = file2vfs(pFile); + let pool = pool(vfs); + pool.pop_err(); + + if let Err(e) = pool.get_o_file_for_s3_file(pFile).and_then(|file| { + file.sah + .truncate_with_f64((HEADER_OFFSET_DATA as i64 + size) as f64) + .map_err(OpfsSAHError::Truncate) + }) { + return pool.store_err(&e, Some(SQLITE_IOERR)); + } + + SQLITE_OK +} + +unsafe extern "C" fn xUnlock( + _pFile: *mut sqlite3_file, + _eLock: ::std::os::raw::c_int, +) -> ::std::os::raw::c_int { + SQLITE_OK +} + +unsafe extern "C" fn xWrite( + pFile: *mut sqlite3_file, + zBuf: *const ::std::os::raw::c_void, + iAmt: ::std::os::raw::c_int, + iOfst: sqlite3_int64, +) -> ::std::os::raw::c_int { + let vfs = file2vfs(pFile); + let pool = pool(vfs); + pool.pop_err(); + + let f = || { + let file = pool.get_o_file_for_s3_file(pFile)?; + let slice = std::slice::from_raw_parts(zBuf.cast::(), iAmt as usize); + + let n_write = file + .sah + .write_with_u8_array_and_options( + slice, + &read_write_options((HEADER_OFFSET_DATA as i64 + iOfst) as f64), + ) + .map_err(OpfsSAHError::Read)?; + + let ret = if iAmt == n_write as i32 { + SQLITE_OK + } else { + SQLITE_ERROR + }; + + Ok::(ret) + }; + + match f() { + Ok(ret) => ret, + Err(e) => pool.store_err(&e, Some(SQLITE_IOERR)), + } +} + +unsafe extern "C" fn xAccess( + pVfs: *mut sqlite3_vfs, + zName: *const ::std::os::raw::c_char, + _flags: ::std::os::raw::c_int, + pResOut: *mut ::std::os::raw::c_int, +) -> ::std::os::raw::c_int { + let pool = pool(pVfs); + pool.pop_err(); + + *pResOut = match pool.get_path(zName) { + Ok(s) => i32::from(pool.has_filename(&s)), + Err(_) => 0, + }; + + SQLITE_OK +} + +unsafe extern "C" fn xDelete( + pVfs: *mut sqlite3_vfs, + zName: *const ::std::os::raw::c_char, + _syncDir: ::std::os::raw::c_int, +) -> ::std::os::raw::c_int { + let pool = pool(pVfs); + pool.pop_err(); + + if let Err(e) = pool.get_path(zName).map(|name| pool.delete_path(&name)) { + return pool.store_err(&e, Some(SQLITE_IOERR_DELETE)); + } + + SQLITE_OK +} + +unsafe extern "C" fn xFullPathname( + _pVfs: *mut sqlite3_vfs, + zName: *const ::std::os::raw::c_char, + nOut: ::std::os::raw::c_int, + zOut: *mut ::std::os::raw::c_char, +) -> ::std::os::raw::c_int { + zName.copy_to(zOut, nOut as usize); + SQLITE_OK +} + +unsafe extern "C" fn xGetLastError( + pVfs: *mut sqlite3_vfs, + nOut: ::std::os::raw::c_int, + zOut: *mut ::std::os::raw::c_char, +) -> ::std::os::raw::c_int { + let pool = pool(pVfs); + let Some((code, msg)) = pool.pop_err() else { + return SQLITE_OK; + }; + if !zOut.is_null() { + let count = msg.len().min(nOut as usize); + msg.as_ptr().copy_to(zOut.cast(), count); + let zero = match count.cmp(&msg.len()) { + std::cmp::Ordering::Less | std::cmp::Ordering::Equal => nOut as usize, + std::cmp::Ordering::Greater => msg.len() + 1, + }; + if zero > 0 { + std::ptr::write(zOut.add(zero - 1), 0); + } + } + code +} + +unsafe extern "C" fn xOpen( + pVfs: *mut sqlite3_vfs, + zName: sqlite3_filename, + pFile: *mut sqlite3_file, + flags: ::std::os::raw::c_int, + pOutFlags: *mut ::std::os::raw::c_int, +) -> ::std::os::raw::c_int { + let pool = pool(pVfs); + + let f = || { + let name = pool.get_path(zName)?; + let sah = match pool.get_sah_for_path(&name) { + Some(sah) => sah, + None => { + if flags & SQLITE_OPEN_CREATE == 0 { + return Err(OpfsSAHError::Custom(format!("file not found: {name}"))); + } + if let Some(sah) = pool.next_available_sah() { + pool.set_associated_path(&sah, &name, flags)?; + sah + } else { + return Err(OpfsSAHError::Custom( + "SAH pool is full. Cannot create file".into(), + )); + } + } + }; + let file = Object::new(); + Reflect::set(&file, &JsValue::from("path"), &JsValue::from(name)).unwrap(); + Reflect::set(&file, &JsValue::from("flags"), &JsValue::from(flags)).unwrap(); + Reflect::set(&file, &JsValue::from("sah"), &JsValue::from(sah)).unwrap(); + pool.map_s3_file_to_o_file(pFile, Some(file)); + + (*(pFile.cast::())).vfs = pVfs; + (*pFile).pMethods = &IO_METHODS; + + if !pOutFlags.is_null() { + *pOutFlags = flags; + } + + Ok::(SQLITE_OK) + }; + match f() { + Ok(ret) => ret, + Err(e) => pool.store_err(&e, Some(SQLITE_CANTOPEN)), + } +} + +static IO_METHODS: sqlite3_io_methods = sqlite3_io_methods { + iVersion: 1, + xClose: Some(xClose), + xRead: Some(xRead), + xWrite: Some(xWrite), + xTruncate: Some(xTruncate), + xSync: Some(xSync), + xFileSize: Some(xFileSize), + xLock: Some(xLock), + xUnlock: Some(xUnlock), + xCheckReservedLock: Some(xCheckReservedLock), + xFileControl: Some(xFileControl), + xSectorSize: Some(xSectorSize), + xDeviceCharacteristics: Some(xDeviceCharacteristics), + xShmMap: None, + xShmLock: None, + xShmBarrier: None, + xShmUnmap: None, + xFetch: None, + xUnfetch: None, +}; + +fn vfs(name: *const ::std::os::raw::c_char) -> sqlite3_vfs { + let default_vfs = unsafe { sqlite3_vfs_find(std::ptr::null()) }; + let xRandomness = unsafe { (*default_vfs).xRandomness }; + let xSleep = unsafe { (*default_vfs).xSleep }; + let xCurrentTime = unsafe { (*default_vfs).xCurrentTime }; + let xCurrentTimeInt64 = unsafe { (*default_vfs).xCurrentTimeInt64 }; + + sqlite3_vfs { + iVersion: 2, + szOsFile: std::mem::size_of::() as i32, + mxPathname: HEADER_MAX_PATH_SIZE as i32, + pNext: std::ptr::null_mut(), + zName: name, + pAppData: std::ptr::null_mut(), + xOpen: Some(xOpen), + xDelete: Some(xDelete), + xAccess: Some(xAccess), + xFullPathname: Some(xFullPathname), + xDlOpen: None, + xDlError: None, + xDlSym: None, + xDlClose: None, + xRandomness, + xSleep, + xCurrentTime, + xGetLastError: Some(xGetLastError), + xCurrentTimeInt64, + xSetSystemCall: None, + xGetSystemCall: None, + xNextSystemCall: None, + } +} + +struct OpfsSAH { + pool: Arc>, +} + +impl OpfsSAH { + fn new(pool: OpfsSAHPool) -> Self { + Self { + pool: Arc::new(FragileComfirmed::new(pool)), + } + } +} + +/// Build `OpfsSAHPoolCfg` +pub struct OpfsSAHPoolCfgBuilder(OpfsSAHPoolCfg); + +impl OpfsSAHPoolCfgBuilder { + pub fn new() -> Self { + Self(OpfsSAHPoolCfg::default()) + } + + /// The SQLite VFS name under which this pool's VFS is registered. + pub fn vfs_name(mut self, name: &str) -> Self { + self.0.vfs_name = name.into(); + self + } + + /// Specifies the OPFS directory name in which to store metadata for the `vfs_name` + pub fn directory(mut self, directory: &str) -> Self { + self.0.directory = directory.into(); + self + } + + /// If truthy, contents and filename mapping are removed from each SAH + /// as it is acquired during initalization of the VFS, leaving the VFS's + /// storage in a pristine state. Use this only for databases which need not + /// survive a page reload. + pub fn clear_on_init(mut self, set: bool) -> Self { + self.0.clear_on_init = set; + self + } + + /// Specifies the default capacity of the VFS, i.e. the number of files + /// it may contain. + pub fn initial_capacity(mut self, cap: u32) -> Self { + self.0.initial_capacity = cap; + self + } + + /// Build OpfsSAHPoolCfg + pub fn build(self) -> OpfsSAHPoolCfg { + self.0 + } +} + +impl Default for OpfsSAHPoolCfgBuilder { + fn default() -> Self { + Self::new() + } +} + +/// `OpfsSAHPool` options +pub struct OpfsSAHPoolCfg { + /// The SQLite VFS name under which this pool's VFS is registered. + pub vfs_name: String, + /// Specifies the OPFS directory name in which to store metadata for the `vfs_name` + pub directory: String, + /// If truthy, contents and filename mapping are removed from each SAH + /// as it is acquired during initalization of the VFS, leaving the VFS's + /// storage in a pristine state. Use this only for databases which need not + /// survive a page reload. + pub clear_on_init: bool, + /// Specifies the default capacity of the VFS, i.e. the number of files + /// it may contain. + pub initial_capacity: u32, +} + +impl Default for OpfsSAHPoolCfg { + fn default() -> Self { + Self { + vfs_name: "opfs-sahpool".into(), + directory: ".opfs-sahpool".into(), + clear_on_init: false, + initial_capacity: 6, + } + } +} + +#[derive(thiserror::Error, Debug)] +pub enum OpfsSAHError { + #[error("this vfs is only available in workers")] + NotSuported, + #[error("get directory handle error")] + GetDirHandle(JsValue), + #[error("get file handle error")] + GetFileHandle(JsValue), + #[error("create sync access handle error")] + CreateSyncAccessHandle(JsValue), + #[error("iterate handle error")] + IterHandle(JsValue), + #[error("get path error")] + GetPath(JsValue), + #[error("remove entity error")] + RemoveEntity(JsValue), + #[error("get size error")] + GetSize(JsValue), + #[error("sah read error")] + Read(JsValue), + #[error("sah write error")] + Write(JsValue), + #[error("sah flush error")] + Flush(JsValue), + #[error("sah truncate error")] + Truncate(JsValue), + #[error("reflect error")] + Reflect(JsValue), + #[error("custom error")] + Custom(String), +} + +/// A OpfsSAHPoolUtil instance is exposed to clients in order to +/// manipulate an OpfsSAHPool object without directly exposing that +/// object and allowing for some semantic changes compared to that +/// class. +pub struct OpfsSAHPoolUtil { + pool: Arc>, +} + +impl OpfsSAHPoolUtil { + /// Adds n entries to the current pool. + pub async fn add_capacity(&self, n: u32) -> Result { + self.pool.add_capacity(n).await + } + + /// Removes up to n entries from the pool, with the caveat that + /// it can only remove currently-unused entries. + pub async fn reduce_capacity(&self, n: u32) -> Result { + self.pool.reduce_capacity(n).await + } + + /// Returns the number of files currently contained in the SAH pool. + pub fn get_capacity(&self) -> u32 { + self.pool.get_capacity() + } + + /// Returns the number of files from the pool currently allocated to VFS slots. + pub fn get_file_count(&self) -> u32 { + self.pool.get_file_count() + } + + /// Returns an array of the names of the files currently allocated to VFS slots. + pub fn get_file_names(&self) -> Vec { + self.pool.get_file_names() + } + + /// Removes up to n entries from the pool, with the caveat that it can only + /// remove currently-unused entries. + pub async fn reserve_minimum_capacity(&self, min: u32) -> Result<(), OpfsSAHError> { + let now = self.pool.get_capacity(); + if min > now { + self.pool.add_capacity(min - now).await?; + } + Ok(()) + } + + /// If a virtual file exists with the given name, disassociates it + /// from the pool and returns true, else returns false without side effects. + pub fn unlink(&self, name: &str) -> Result { + self.pool.delete_path(name) + } + + /// Synchronously reads the contents of the given file into a Uint8Array and returns it. + pub fn export_file(&self, name: &str) -> Result, OpfsSAHError> { + self.pool.export_file(name) + } + + /// Imports the contents of an SQLite database, provided as a byte array or ArrayBuffer, + /// under the given name, overwriting any existing content. + /// + /// path must start with '/' + pub fn import_db(&self, path: &str, bytes: &[u8]) -> Result<(), OpfsSAHError> { + if !path.starts_with('/') { + return Err(OpfsSAHError::Custom("path must start with '/'".into())); + } + self.pool.import_db(path, bytes) + } + + /// Clears all client-defined state of all SAHs and makes all of them available + /// for re-use by the pool. + pub async fn wipe_files(&self) -> Result<(), OpfsSAHError> { + self.pool.release_access_handles(); + self.pool.acquire_access_handles(true).await?; + Ok(()) + } +} + +/// Register `opfs-sahpool` vfs and return a utility object which can be used +/// to perform basic administration of the file pool +pub async fn install_opfs_sahpool( + options: Option<&OpfsSAHPoolCfg>, + default_vfs: bool, +) -> Result { + let default_options = OpfsSAHPoolCfg::default(); + let options = options.unwrap_or(&default_options); + let vfs_name = &options.vfs_name; + + let create_pool = async { + let pool = OpfsSAHPool::new(options).await?; + Ok(OpfsSAH::new(pool)) + }; + + let register_vfs = || { + let name = + CString::new(vfs_name.clone()).map_err(|e| OpfsSAHError::Custom(format!("{e:?}")))?; + let vfs = Box::leak(Box::new(vfs(name.into_raw()))); + + let ret = unsafe { sqlite3_vfs_register(vfs, i32::from(default_vfs)) }; + if ret != SQLITE_OK { + unsafe { + drop(Box::from_raw(vfs)); + } + return Err(OpfsSAHError::Custom(format!( + "register {vfs_name} vfs failed", + ))); + } + + Ok(vfs as *mut sqlite3_vfs) + }; + + static NAME2VFS: Lazy>>> = + Lazy::new(|| tokio::sync::Mutex::new(HashMap::new())); + + let mut name2vfs = NAME2VFS.lock().await; + + let pool = if let Some(sah) = name2vfs.get(vfs_name) { + Arc::clone(&sah.pool) + } else { + let opfs_sah = Arc::new(create_pool.await?); + let vfs = register_vfs()?; + name2vfs.insert(vfs_name.clone(), Arc::clone(&opfs_sah)); + VFS2SAH.write().insert(vfs as usize, Arc::clone(&opfs_sah)); + Arc::clone(&opfs_sah.pool) + }; + + let util = OpfsSAHPoolUtil { pool }; + + Ok(util) +}