diff --git a/.github/.codecov.yml b/.github/.codecov.yml index ab126bc2..e8c58cf3 100644 --- a/.github/.codecov.yml +++ b/.github/.codecov.yml @@ -1,6 +1,6 @@ ignore: - - "libduckdb-sys/duckdb" - - "libduckdb-sys/src/bindgen_bundled_version.rs" + - "crates/libduckdb-sys/duckdb" + - "crates/libduckdb-sys/src/bindgen_bundled_version.rs" coverage: status: project: diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index 065f1737..91f4c6ae 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -20,13 +20,13 @@ jobs: components: 'rustfmt, clippy' # cargo publish - - uses: wangfenjin/publish-crates@main - name: cargo publish + - name: publish crates + uses: katyo/publish-crates@v2 with: path: './' args: --no-verify --allow-dirty --all-features registry-token: ${{ secrets.CARGO_REGISTRY_TOKEN }} - ignore-published: true + ignore-unpublished-changes: true # create release - name: "Build Changelog" diff --git a/.github/workflows/rust.yaml b/.github/workflows/rust.yaml index 0ddf6416..c243e202 100644 --- a/.github/workflows/rust.yaml +++ b/.github/workflows/rust.yaml @@ -38,7 +38,7 @@ jobs: name: Download duckdb with: repository: "duckdb/duckdb" - tag: "v0.10.1" + tag: "v1.0.0" fileName: ${{ matrix.duckdb }} out-file-path: . @@ -107,10 +107,6 @@ jobs: runs-on: windows-latest steps: - uses: actions/checkout@v2 - # - run: echo "VCPKG_ROOT=$env:VCPKG_INSTALLATION_ROOT" | Out-File -FilePath $env:GITHUB_ENV -Append - # - run: vcpkg install openssl:x64-windows-static-md - - run: choco install openssl --execution-timeout 5400 - - run: echo 'OPENSSL_DIR=C:\Program Files\OpenSSL' | Out-File -FilePath $env:GITHUB_ENV -Append - uses: actions/cache@v3 with: path: ~/.cargo/registry/index @@ -145,10 +141,10 @@ jobs: # as the other tests have them. RUST_BACKTRACE: "0" run: cargo -Z build-std test --features "modern-full extensions-full" --target x86_64-unknown-linux-gnu - - uses: wangfenjin/publish-crates@main - name: cargo publish --dry-run + - name: publish crates --dry-run + uses: katyo/publish-crates@v2 with: path: './' args: --allow-dirty --all-features dry-run: true - ignore-published: true + ignore-unpublished-changes: true diff --git a/.gitignore b/.gitignore index 0b6b9228..02483800 100644 --- a/.gitignore +++ b/.gitignore @@ -27,6 +27,6 @@ Cargo.lock *.db -libduckdb-sys/duckdb-sources/ -libduckdb-sys/duckdb/ -libduckdb-sys/._duckdb +crates/libduckdb-sys/duckdb-sources/ +crates/libduckdb-sys/duckdb/ +crates/libduckdb-sys/._duckdb diff --git a/.gitmodules b/.gitmodules index 4754e802..c35364a0 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,4 +1,4 @@ -[submodule "libduckdb-sys/duckdb-sources"] - path = libduckdb-sys/duckdb-sources +[submodule "crates/libduckdb-sys/duckdb-sources"] + path = crates/libduckdb-sys/duckdb-sources url = https://github.com/duckdb/duckdb update = none diff --git a/.rustfmt.toml b/.rustfmt.toml index 0b7ea326..5baafd61 100644 --- a/.rustfmt.toml +++ b/.rustfmt.toml @@ -1,2 +1,7 @@ max_width = 120 -imports_granularity = "Crate" \ No newline at end of file +imports_granularity = "Crate" +reorder_imports = true +fn_call_width = 72 +# indent_style = "Block" +# tab_spaces = 2 +# group_imports="StdExternalCrate" diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index bac02655..16bc8bed 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -43,24 +43,24 @@ export DUCKDB_INCLUDE_DIR=~/duckdb-lib Use the exported library and header: ```shell -cd ~/github/duckdb-rs/libduckdb-sys +cd ~/github/duckdb-rs/crates/libduckdb-sys cargo test --features buildtime_bindgen ``` Use the bundled header file: ```shell -cd ~/github/duckdb-rs/libduckdb-sys +cd ~/github/duckdb-rs/crates/libduckdb-sys cargo test --features bundled ``` -Currently in [github actions](https://github.com/wangfenjin/duckdb-rs/actions), we always use the bundled file for testing. So if you change the header in duckdb-cpp repo, you need to make the PR merged and updated the [bundled-file](https://github.com/wangfenjin/duckdb-rs/tree/main/libduckdb-sys/duckdb). +Currently in [github actions](https://github.com/wangfenjin/duckdb-rs/actions), we always use the bundled file for testing. So if you change the header in duckdb-cpp repo, you need to make the PR merged and updated the [bundled-file](https://github.com/wangfenjin/duckdb-rs/tree/main/crates/libduckdb-sys/duckdb). You can generated the amalgamated file by: ```shell cd ~/github/duckdb mkdir -p build/amaldebug python scripts/amalgamation.py -cp src/amalgamation/duckdb.cpp src/include/duckdb.h src/amalgamation/duckdb.hpp ../duckdb-rs/libduckdb-sys/duckdb/ +cp src/amalgamation/duckdb.cpp src/include/duckdb.h src/amalgamation/duckdb.hpp ../duckdb-rs/crates/libduckdb-sys/duckdb/ ``` ### duckdb-rs diff --git a/Cargo.toml b/Cargo.toml index 99c4f03a..65dbf60d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,101 +1,64 @@ -[package] -name = "duckdb" -version = "0.10.2" +[workspace] +resolver = "2" +members = [ + "crates/duckdb", + "crates/libduckdb-sys", + "crates/duckdb-loadable-macros" +] + +[workspace.package] +version = "1.0.0" authors = ["wangfenjin "] edition = "2021" -description = "Ergonomic wrapper for DuckDB" -repository = "https://github.com/wangfenjin/duckdb-rs" -homepage = "https://github.com/wangfenjin/duckdb-rs" +repository = "https://github.com/duckdb/duckdb-rs" +homepage = "https://github.com/duckdb/duckdb-rs" documentation = "http://docs.rs/duckdb/" readme = "README.md" keywords = ["duckdb", "database", "ffi"] license = "MIT" categories = ["database"] -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[lib] -name = "duckdb" - -[workspace] -members = ["libduckdb-sys", "duckdb-loadable-macros"] - -[features] -default = [] -bundled = ["libduckdb-sys/bundled"] -httpfs = ["libduckdb-sys/httpfs", "bundled"] -json = ["libduckdb-sys/json", "bundled"] -parquet = ["libduckdb-sys/parquet", "bundled"] -vtab = [] -vtab-loadable = ["vtab", "duckdb-loadable-macros"] -vtab-excel = ["vtab", "calamine"] -vtab-arrow = ["vtab", "num"] -appender-arrow = ["vtab-arrow"] -vtab-full = ["vtab-excel", "vtab-arrow", "appender-arrow"] -extensions-full = ["httpfs", "json", "parquet", "vtab-full"] -buildtime_bindgen = ["libduckdb-sys/buildtime_bindgen"] -modern-full = ["chrono", "serde_json", "url", "r2d2", "uuid", "polars"] -polars = ["dep:polars"] -chrono = ["dep:chrono", "num-integer"] - -[dependencies] -# time = { version = "0.3.2", features = ["formatting", "parsing"], optional = true } -hashlink = "0.8" -chrono = { version = "0.4.22", optional = true } -serde_json = { version = "1.0", optional = true } -csv = { version = "1.1", optional = true } -url = { version = "2.1", optional = true } -lazy_static = { version = "1.4", optional = true } -byteorder = { version = "1.3", features = ["i128"], optional = true } +[workspace.dependencies] +duckdb = { version = "1.0.0", path = "crates/duckdb" } +libduckdb-sys = { version = "1.0.0", path = "crates/libduckdb-sys" } +duckdb-loadable-macros = { version = "0.1.2", path = "crates/duckdb-loadable-macros" } +autocfg = "1.0" +bindgen = { version = "0.69", default-features = false } +byteorder = "1.3" +calamine = "0.22.0" +cast = "0.3" +cc = "1.0" +chrono = "0.4.22" +csv = "1.1" +doc-comment = "0.3" fallible-iterator = "0.3" fallible-streaming-iterator = "0.1" +flate2 = "1.0" +hashlink = "0.9" +lazy_static = "1.4" memchr = "2.3" -uuid = { version = "1.0", optional = true } -smallvec = "1.6.1" -cast = { version = "0.3", features = ["std"] } -arrow = { version = "51", default-features = false, features = ["prettyprint", "ffi"] } +num = { version = "0.4", default-features = false } +num-integer = "0.1.46" +pkg-config = "0.3.24" +polars = "0.35.4" +polars-core = "0.35.4" +pretty_assertions = "1.4.0" +proc-macro2 = "1.0.56" +quote = "1.0.21" +r2d2 = "0.8.9" +rand = "0.8.3" +regex = "1.6" rust_decimal = "1.14" -strum = { version = "0.25", features = ["derive"] } -r2d2 = { version = "0.8.9", optional = true } -calamine = { version = "0.22.0", optional = true } -num = { version = "0.4", optional = true, default-features = false, features = ["std"] } -duckdb-loadable-macros = { version = "0.1.1", path="./duckdb-loadable-macros", optional = true } -polars = { version = "0.35.4", features = ["dtype-full"], optional = true} -num-integer = {version = "0.1.46", optional = true} - -[dev-dependencies] -doc-comment = "0.3" +serde = "1.0" +serde_json = "1.0" +smallvec = "1.6.1" +strum = "0.25" +syn = "2.0.15" +tar = "0.4.38" +tempdir = "0.3.7" tempfile = "3.1.0" -lazy_static = "1.4" -regex = "1.6" -uuid = { version = "1.0", features = ["v4"] } unicase = "2.6.0" -rand = "0.8.3" -tempdir = "0.3.7" -polars-core = "0.35.4" -pretty_assertions = "1.4.0" -# criterion = "0.3" - -# [[bench]] -# name = "data_types" -# harness = false - -[dependencies.libduckdb-sys] -path = "libduckdb-sys" -version = "0.10.2" - - -[package.metadata.docs.rs] -features = ['vtab', 'chrono'] -all-features = false -no-default-features = true -default-target = "x86_64-unknown-linux-gnu" - -[package.metadata.playground] -features = [] -all-features = false - -[[example]] -name = "hello-ext" -crate-type = ["cdylib"] -required-features = ["vtab-loadable"] +url = "2.1" +uuid = "1.0" +vcpkg = "0.2" +arrow = { version = "52", default-features = false } diff --git a/README.md b/README.md index 243a6324..6f594ed2 100644 --- a/README.md +++ b/README.md @@ -91,6 +91,13 @@ You can adjust this behavior in a number of ways: as we are still in development, we will update it regularly. After we are more stable, we will use the stable released version from [duckdb](https://github.com/duckdb/duckdb/releases). This is probably the simplest solution to any build problems. You can enable this by adding the following in your `Cargo.toml` file: + + ```bash + cargo add duckdb --features bundled + ``` + + `Cargo.toml` will be updated. + ```toml [dependencies] # Assume that version DuckDB version 0.9.2 is used. diff --git a/crates/duckdb-loadable-macros/Cargo.toml b/crates/duckdb-loadable-macros/Cargo.toml new file mode 100644 index 00000000..0a6af2fc --- /dev/null +++ b/crates/duckdb-loadable-macros/Cargo.toml @@ -0,0 +1,22 @@ +[package] +name = "duckdb-loadable-macros" +version = "0.1.2" +authors.workspace = true +edition.workspace = true +license.workspace = true +repository.workspace = true +homepage.workspace = true +keywords.workspace = true +readme.workspace = true +categories = ["external-ffi-bindings", "database"] +description = "Native bindings to the libduckdb library, C API; build loadable extensions" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +proc-macro2 = { workspace = true } +quote = { workspace = true } +syn = { workspace = true, features = ["extra-traits", "full", "fold", "parsing"] } + +[lib] +proc-macro = true diff --git a/crates/duckdb-loadable-macros/LICENSE b/crates/duckdb-loadable-macros/LICENSE new file mode 120000 index 00000000..30cff740 --- /dev/null +++ b/crates/duckdb-loadable-macros/LICENSE @@ -0,0 +1 @@ +../../LICENSE \ No newline at end of file diff --git a/crates/duckdb-loadable-macros/README.md b/crates/duckdb-loadable-macros/README.md new file mode 120000 index 00000000..fe840054 --- /dev/null +++ b/crates/duckdb-loadable-macros/README.md @@ -0,0 +1 @@ +../../README.md \ No newline at end of file diff --git a/duckdb-loadable-macros/src/lib.rs b/crates/duckdb-loadable-macros/src/lib.rs similarity index 100% rename from duckdb-loadable-macros/src/lib.rs rename to crates/duckdb-loadable-macros/src/lib.rs diff --git a/crates/duckdb/Cargo.toml b/crates/duckdb/Cargo.toml new file mode 100644 index 00000000..e04260e4 --- /dev/null +++ b/crates/duckdb/Cargo.toml @@ -0,0 +1,95 @@ +[package] +name = "duckdb" +version = "1.0.0" +authors.workspace = true +edition.workspace = true +repository.workspace = true +homepage.workspace = true +documentation.workspace = true +readme.workspace = true +keywords.workspace = true +license.workspace = true +categories.workspace = true +description = "Ergonomic wrapper for DuckDB" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[lib] +name = "duckdb" + +[features] +default = [] +bundled = ["libduckdb-sys/bundled"] +json = ["libduckdb-sys/json", "bundled"] +parquet = ["libduckdb-sys/parquet", "bundled"] +vtab = [] +vtab-loadable = ["vtab", "duckdb-loadable-macros"] +vtab-excel = ["vtab", "calamine"] +vtab-arrow = ["vtab", "num"] +appender-arrow = ["vtab-arrow"] +vtab-full = ["vtab-excel", "vtab-arrow", "appender-arrow"] +extensions-full = ["json", "parquet", "vtab-full"] +buildtime_bindgen = ["libduckdb-sys/buildtime_bindgen"] +modern-full = ["chrono", "serde_json", "url", "r2d2", "uuid", "polars"] +polars = ["dep:polars"] +# FIXME: These were added to make clippy happy: these features appear unused and should perhaps be removed +column_decltype = [] +extra_check = [] + +[dependencies] +libduckdb-sys = { workspace = true } +hashlink = { workspace = true } +chrono = { workspace = true, optional = true } +serde_json = { workspace = true, optional = true } +csv = { workspace = true, optional = true } +url = { workspace = true, optional = true } +lazy_static = { workspace = true, optional = true } +byteorder = { workspace = true, features = ["i128"], optional = true } +fallible-iterator = { workspace = true } +fallible-streaming-iterator = { workspace = true } +memchr = { workspace = true } +uuid = { workspace = true, optional = true } +smallvec = { workspace = true } +cast = { workspace = true, features = ["std"] } +arrow = { workspace = true, features = ["prettyprint", "ffi"] } +rust_decimal = { workspace = true } +strum = { workspace = true, features = ["derive"] } +r2d2 = { workspace = true, optional = true } +calamine = { workspace = true, optional = true } +num = { workspace = true, features = ["std"], optional = true } +duckdb-loadable-macros = { workspace = true, optional = true } +polars = { workspace = true, features = ["dtype-full"], optional = true } +num-integer = { workspace = true } + +[dev-dependencies] +doc-comment = { workspace = true } +tempfile = { workspace = true } +lazy_static = { workspace = true } +regex = { workspace = true } +uuid = { workspace = true, features = ["v4"] } +unicase = { workspace = true } +rand = { workspace = true } +tempdir = { workspace = true } +polars-core = { workspace = true } +pretty_assertions = { workspace = true } +# criterion = "0.3" + +# [[bench]] +# name = "data_types" +# harness = false + + +[package.metadata.docs.rs] +features = [] +all-features = false +no-default-features = true +default-target = "x86_64-unknown-linux-gnu" + +[package.metadata.playground] +features = [] +all-features = false + +[[example]] +name = "hello-ext" +crate-type = ["cdylib"] +required-features = ["vtab-loadable"] diff --git a/examples/Movies_Social_metadata.xlsx b/crates/duckdb/examples/Movies_Social_metadata.xlsx similarity index 100% rename from examples/Movies_Social_metadata.xlsx rename to crates/duckdb/examples/Movies_Social_metadata.xlsx diff --git a/examples/appender.rs b/crates/duckdb/examples/appender.rs similarity index 100% rename from examples/appender.rs rename to crates/duckdb/examples/appender.rs diff --git a/examples/basic.rs b/crates/duckdb/examples/basic.rs similarity index 100% rename from examples/basic.rs rename to crates/duckdb/examples/basic.rs diff --git a/examples/date.xlsx b/crates/duckdb/examples/date.xlsx similarity index 100% rename from examples/date.xlsx rename to crates/duckdb/examples/date.xlsx diff --git a/examples/hello-ext/main.rs b/crates/duckdb/examples/hello-ext/main.rs similarity index 82% rename from examples/hello-ext/main.rs rename to crates/duckdb/examples/hello-ext/main.rs index 5409dff1..6f159e9a 100644 --- a/examples/hello-ext/main.rs +++ b/crates/duckdb/examples/hello-ext/main.rs @@ -3,7 +3,8 @@ extern crate duckdb_loadable_macros; extern crate libduckdb_sys; use duckdb::{ - vtab::{BindInfo, DataChunk, Free, FunctionInfo, InitInfo, Inserter, LogicalType, LogicalTypeId, VTab}, + core::{DataChunkHandle, Inserter, LogicalTypeHandle, LogicalTypeId}, + vtab::{BindInfo, Free, FunctionInfo, InitInfo, VTab}, Connection, Result, }; use duckdb_loadable_macros::duckdb_entrypoint; @@ -43,7 +44,7 @@ impl VTab for HelloVTab { type BindData = HelloBindData; unsafe fn bind(bind: &BindInfo, data: *mut HelloBindData) -> Result<(), Box> { - bind.add_result_column("column0", LogicalType::new(LogicalTypeId::Varchar)); + bind.add_result_column("column0", LogicalTypeHandle::from(LogicalTypeId::Varchar)); let param = bind.get_parameter(0).to_string(); unsafe { (*data).name = CString::new(param).unwrap().into_raw(); @@ -58,7 +59,7 @@ impl VTab for HelloVTab { Ok(()) } - unsafe fn func(func: &FunctionInfo, output: &mut DataChunk) -> Result<(), Box> { + unsafe fn func(func: &FunctionInfo, output: &mut DataChunkHandle) -> Result<(), Box> { let init_info = func.get_init_data::(); let bind_info = func.get_bind_data::(); @@ -79,8 +80,8 @@ impl VTab for HelloVTab { Ok(()) } - fn parameters() -> Option> { - Some(vec![LogicalType::new(LogicalTypeId::Varchar)]) + fn parameters() -> Option> { + Some(vec![LogicalTypeHandle::from(LogicalTypeId::Varchar)]) } } diff --git a/examples/int32_decimal.parquet b/crates/duckdb/examples/int32_decimal.parquet similarity index 100% rename from examples/int32_decimal.parquet rename to crates/duckdb/examples/int32_decimal.parquet diff --git a/examples/parquet.rs b/crates/duckdb/examples/parquet.rs similarity index 100% rename from examples/parquet.rs rename to crates/duckdb/examples/parquet.rs diff --git a/src/appender/arrow.rs b/crates/duckdb/src/appender/arrow.rs similarity index 94% rename from src/appender/arrow.rs rename to crates/duckdb/src/appender/arrow.rs index 19d79bb4..942242cc 100644 --- a/src/appender/arrow.rs +++ b/crates/duckdb/src/appender/arrow.rs @@ -1,7 +1,8 @@ use super::{ffi, Appender, Result}; use crate::{ + core::{DataChunkHandle, LogicalTypeHandle}, error::result_from_duckdb_appender, - vtab::{record_batch_to_duckdb_data_chunk, to_duckdb_logical_type, DataChunk, LogicalType}, + vtab::{record_batch_to_duckdb_data_chunk, to_duckdb_logical_type}, Error, }; use arrow::record_batch::RecordBatch; @@ -28,14 +29,14 @@ impl Appender<'_> { #[inline] pub fn append_record_batch(&mut self, record_batch: RecordBatch) -> Result<()> { let schema = record_batch.schema(); - let mut logical_type: Vec = vec![]; + let mut logical_type: Vec = vec![]; for field in schema.fields() { let logical_t = to_duckdb_logical_type(field.data_type()) .map_err(|_op| Error::ArrowTypeToDuckdbType(field.to_string(), field.data_type().clone()))?; logical_type.push(logical_t); } - let mut data_chunk = DataChunk::new(&logical_type); + let mut data_chunk = DataChunkHandle::new(&logical_type); record_batch_to_duckdb_data_chunk(&record_batch, &mut data_chunk).map_err(|_op| Error::AppendError)?; let rc = unsafe { duckdb_append_data_chunk(self.app, data_chunk.get_ptr()) }; diff --git a/src/appender/mod.rs b/crates/duckdb/src/appender/mod.rs similarity index 85% rename from src/appender/mod.rs rename to crates/duckdb/src/appender/mod.rs index 65b6db0f..488db82f 100644 --- a/src/appender/mod.rs +++ b/crates/duckdb/src/appender/mod.rs @@ -3,7 +3,7 @@ use std::{ffi::c_void, fmt, os::raw::c_char}; use crate::{ error::result_from_duckdb_appender, - types::{TimeUnit, ToSql, ToSqlOutput}, + types::{ToSql, ToSqlOutput}, Error, }; @@ -118,15 +118,23 @@ impl Appender<'_> { ffi::duckdb_append_varchar_length(ptr, s.as_ptr() as *const c_char, s.len() as u64) }, ValueRef::Timestamp(u, i) => unsafe { - let micros = match u { - TimeUnit::Second => i * 1_000_000, - TimeUnit::Millisecond => i * 1_000, - TimeUnit::Microsecond => i, - TimeUnit::Nanosecond => i / 1_000, - }; - ffi::duckdb_append_timestamp(ptr, ffi::duckdb_timestamp { micros }) + ffi::duckdb_append_timestamp(ptr, ffi::duckdb_timestamp { micros: u.to_micros(i) }) }, ValueRef::Blob(b) => unsafe { ffi::duckdb_append_blob(ptr, b.as_ptr() as *const c_void, b.len() as u64) }, + ValueRef::Date32(d) => unsafe { ffi::duckdb_append_date(ptr, ffi::duckdb_date { days: d }) }, + ValueRef::Time64(u, v) => unsafe { + ffi::duckdb_append_time(ptr, ffi::duckdb_time { micros: u.to_micros(v) }) + }, + ValueRef::Interval { months, days, nanos } => unsafe { + ffi::duckdb_append_interval( + ptr, + ffi::duckdb_interval { + months, + days, + micros: nanos / 1000, + }, + ) + }, _ => unreachable!("not supported"), }; if rc != 0 { @@ -255,6 +263,29 @@ mod test { Ok(()) } + #[test] + #[cfg(feature = "chrono")] + fn test_append_datetime() -> Result<()> { + use crate::params; + use chrono::{NaiveDate, NaiveDateTime}; + + let db = Connection::open_in_memory()?; + db.execute_batch("CREATE TABLE foo(x DATE, y TIMESTAMP)")?; + + let date = NaiveDate::from_ymd_opt(2024, 6, 5).unwrap(); + let timestamp = date.and_hms_opt(18, 26, 53).unwrap(); + { + let mut app = db.appender("foo")?; + app.append_row(params![date, timestamp])?; + } + let (date2, timestamp2) = db.query_row("SELECT x, y FROM foo", [], |row| { + Ok((row.get::<_, NaiveDate>(0)?, row.get::<_, NaiveDateTime>(1)?)) + })?; + assert_eq!(date, date2); + assert_eq!(timestamp, timestamp2); + Ok(()) + } + #[test] fn test_appender_error() -> Result<(), crate::Error> { let conn = Connection::open_in_memory()?; diff --git a/src/appender_params.rs b/crates/duckdb/src/appender_params.rs similarity index 100% rename from src/appender_params.rs rename to crates/duckdb/src/appender_params.rs diff --git a/src/arrow_batch.rs b/crates/duckdb/src/arrow_batch.rs similarity index 100% rename from src/arrow_batch.rs rename to crates/duckdb/src/arrow_batch.rs diff --git a/src/cache.rs b/crates/duckdb/src/cache.rs similarity index 100% rename from src/cache.rs rename to crates/duckdb/src/cache.rs diff --git a/src/column.rs b/crates/duckdb/src/column.rs similarity index 90% rename from src/column.rs rename to crates/duckdb/src/column.rs index b7ab88ae..8d4c8935 100644 --- a/src/column.rs +++ b/crates/duckdb/src/column.rs @@ -1,5 +1,7 @@ use std::str; +use arrow::datatypes::DataType; + use crate::{Error, Result, Statement}; /// Information about a column of a DuckDB query. @@ -29,6 +31,9 @@ impl Statement<'_> { /// If associated DB schema can be altered concurrently, you should make /// sure that current statement has already been stepped once before /// calling this method. + /// + /// # Caveats + /// Panics if the query has not been [`execute`](Statement::execute)d yet. pub fn column_names(&self) -> Vec { self.stmt .schema() @@ -87,7 +92,9 @@ impl Statement<'_> { /// Returns an `Error::InvalidColumnIndex` if `idx` is outside the valid /// column range for this row. /// - /// Panics when column name is not valid UTF-8. + /// # Caveats + /// Panics if the query has not been [`execute`](Statement::execute)d yet + /// or when column name is not valid UTF-8. #[inline] pub fn column_name(&self, col: usize) -> Result<&String> { self.stmt.column_name(col).ok_or(Error::InvalidColumnIndex(col)) @@ -106,6 +113,9 @@ impl Statement<'_> { /// /// Will return an `Error::InvalidColumnName` when there is no column with /// the specified `name`. + /// + /// # Caveats + /// Panics if the query has not been [`execute`](Statement::execute)d yet. #[inline] pub fn column_index(&self, name: &str) -> Result { let n = self.column_count(); @@ -119,6 +129,15 @@ impl Statement<'_> { Err(Error::InvalidColumnName(String::from(name))) } + /// Returns the declared data type of the column. + /// + /// # Caveats + /// Panics if the query has not been [`execute`](Statement::execute)d yet. + #[inline] + pub fn column_type(&self, idx: usize) -> DataType { + self.stmt.column_type(idx) + } + /// Returns a slice describing the columns of the result of the query. /// /// If associated DB schema can be altered concurrently, you should make @@ -127,7 +146,7 @@ impl Statement<'_> { #[cfg(feature = "column_decltype")] pub fn columns(&self) -> Vec { let n = self.column_count(); - let mut cols = Vec::with_capacity(n as usize); + let mut cols = Vec::with_capacity(n); for i in 0..n { let name = self.column_name_unwrap(i); let slice = self.stmt.column_decltype(i); diff --git a/src/config.rs b/crates/duckdb/src/config.rs similarity index 94% rename from src/config.rs rename to crates/duckdb/src/config.rs index 66e37c4b..62df2c57 100644 --- a/src/config.rs +++ b/crates/duckdb/src/config.rs @@ -65,6 +65,12 @@ impl Config { Ok(self) } + /// Metadata from DuckDB callers + pub fn custom_user_agent(mut self, custom_user_agent: &str) -> Result { + self.set("custom_user_agent", custom_user_agent)?; + Ok(self) + } + /// The order type used when none is specified ([ASC] or DESC) pub fn default_order(mut self, order: DefaultOrder) -> Result { self.set("default_order", &order.to_string())?; @@ -190,6 +196,7 @@ mod test { .enable_object_cache(false)? .enable_autoload_extension(true)? .allow_unsigned_extensions()? + .custom_user_agent("test_user_agent")? .max_memory("2GB")? .threads(4)? .with("preserve_insertion_order", "true")?; @@ -215,6 +222,10 @@ mod test { assert!(iter.next().unwrap().is_none()); assert_eq!(iter.next(), None); + let user_agent: Result = db.query_row("PRAGMA USER_AGENT", [], |row| row.get(0)); + let user_agent = user_agent.unwrap(); + assert!(&user_agent.ends_with("rust test_user_agent")); + Ok(()) } diff --git a/src/vtab/data_chunk.rs b/crates/duckdb/src/core/data_chunk.rs similarity index 68% rename from src/vtab/data_chunk.rs rename to crates/duckdb/src/core/data_chunk.rs index 6e472773..7b6d2e2c 100644 --- a/src/vtab/data_chunk.rs +++ b/crates/duckdb/src/core/data_chunk.rs @@ -1,28 +1,41 @@ use super::{ - logical_type::LogicalType, - vector::{FlatVector, ListVector, StructVector}, + logical_type::LogicalTypeHandle, + vector::{ArrayVector, FlatVector, ListVector, StructVector}, }; use crate::ffi::{ duckdb_create_data_chunk, duckdb_data_chunk, duckdb_data_chunk_get_column_count, duckdb_data_chunk_get_size, duckdb_data_chunk_get_vector, duckdb_data_chunk_set_size, duckdb_destroy_data_chunk, }; -/// DataChunk in DuckDB. -pub struct DataChunk { +/// Handle to the DataChunk in DuckDB. +pub struct DataChunkHandle { /// Pointer to the DataChunk in duckdb C API. ptr: duckdb_data_chunk, - /// Whether this [DataChunk] own the [DataChunk::ptr]. + /// Whether this [DataChunkHandle] own the [DataChunk::ptr]. owned: bool, } -impl DataChunk { - /// Create a new [DataChunk] with the given [LogicalType]s. - pub fn new(logical_types: &[LogicalType]) -> Self { +impl Drop for DataChunkHandle { + fn drop(&mut self) { + if self.owned && !self.ptr.is_null() { + unsafe { duckdb_destroy_data_chunk(&mut self.ptr) } + self.ptr = std::ptr::null_mut(); + } + } +} + +impl DataChunkHandle { + pub(crate) unsafe fn new_unowned(ptr: duckdb_data_chunk) -> Self { + Self { ptr, owned: false } + } + + /// Create a new [DataChunkHandle] with the given [LogicalTypeHandle]s. + pub fn new(logical_types: &[LogicalTypeHandle]) -> Self { let num_columns = logical_types.len(); let mut c_types = logical_types.iter().map(|t| t.ptr).collect::>(); let ptr = unsafe { duckdb_create_data_chunk(c_types.as_mut_ptr(), num_columns as u64) }; - DataChunk { ptr, owned: true } + DataChunkHandle { ptr, owned: true } } /// Get the vector at the specific column index: `idx`. @@ -35,6 +48,11 @@ impl DataChunk { ListVector::from(unsafe { duckdb_data_chunk_get_vector(self.ptr, idx as u64) }) } + /// Get a array vector from the column index. + pub fn array_vector(&self, idx: usize) -> ArrayVector { + ArrayVector::from(unsafe { duckdb_data_chunk_get_vector(self.ptr, idx as u64) }) + } + /// Get struct vector at the column index: `idx`. pub fn struct_vector(&self, idx: usize) -> StructVector { StructVector::from(unsafe { duckdb_data_chunk_get_vector(self.ptr, idx as u64) }) @@ -45,49 +63,34 @@ impl DataChunk { unsafe { duckdb_data_chunk_set_size(self.ptr, new_len as u64) }; } - /// Get the length / the number of rows in this [DataChunk]. + /// Get the length / the number of rows in this [DataChunkHandle]. pub fn len(&self) -> usize { unsafe { duckdb_data_chunk_get_size(self.ptr) as usize } } - /// Check whether this [DataChunk] is empty. + /// Check whether this [DataChunkHandle] is empty. pub fn is_empty(&self) -> bool { self.len() == 0 } - /// Get the number of columns in this [DataChunk]. + /// Get the number of columns in this [DataChunkHandle]. pub fn num_columns(&self) -> usize { unsafe { duckdb_data_chunk_get_column_count(self.ptr) as usize } } - /// Get the ptr of duckdb_data_chunk in this [DataChunk]. + /// Get the ptr of duckdb_data_chunk in this [DataChunkHandle]. pub fn get_ptr(&self) -> duckdb_data_chunk { self.ptr } } -impl From for DataChunk { - fn from(ptr: duckdb_data_chunk) -> Self { - Self { ptr, owned: false } - } -} - -impl Drop for DataChunk { - fn drop(&mut self) { - if self.owned && !self.ptr.is_null() { - unsafe { duckdb_destroy_data_chunk(&mut self.ptr) } - self.ptr = std::ptr::null_mut(); - } - } -} - #[cfg(test)] mod test { use super::{super::logical_type::LogicalTypeId, *}; #[test] fn test_data_chunk_construction() { - let dc = DataChunk::new(&[LogicalType::new(LogicalTypeId::Integer)]); + let dc = DataChunkHandle::new(&[LogicalTypeHandle::from(LogicalTypeId::Integer)]); assert_eq!(dc.num_columns(), 1); @@ -96,7 +99,7 @@ mod test { #[test] fn test_vector() { - let datachunk = DataChunk::new(&[LogicalType::new(LogicalTypeId::Bigint)]); + let datachunk = DataChunkHandle::new(&[LogicalTypeHandle::from(LogicalTypeId::Bigint)]); let mut vector = datachunk.flat_vector(0); let data = vector.as_mut_slice::(); @@ -105,11 +108,11 @@ mod test { #[test] fn test_logi() { - let key = LogicalType::new(LogicalTypeId::Varchar); + let key = LogicalTypeHandle::from(LogicalTypeId::Varchar); - let value = LogicalType::new(LogicalTypeId::UTinyint); + let value = LogicalTypeHandle::from(LogicalTypeId::UTinyint); - let map = LogicalType::map(&key, &value); + let map = LogicalTypeHandle::map(&key, &value); assert_eq!(map.id(), LogicalTypeId::Map); diff --git a/src/vtab/logical_type.rs b/crates/duckdb/src/core/logical_type.rs similarity index 85% rename from src/vtab/logical_type.rs rename to crates/duckdb/src/core/logical_type.rs index 76a17182..ede3ba52 100644 --- a/src/vtab/logical_type.rs +++ b/crates/duckdb/src/core/logical_type.rs @@ -110,11 +110,11 @@ impl From for LogicalTypeId { /// DuckDB Logical Type. /// -pub struct LogicalType { +pub struct LogicalTypeHandle { pub(crate) ptr: duckdb_logical_type, } -impl Debug for LogicalType { +impl Debug for LogicalTypeHandle { /// Debug implementation for LogicalType fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> Result<(), std::fmt::Error> { let id = self.id(); @@ -134,7 +134,7 @@ impl Debug for LogicalType { } } -impl Drop for LogicalType { +impl Drop for LogicalTypeHandle { /// Drop implementation for LogicalType fn drop(&mut self) { if !self.ptr.is_null() { @@ -147,25 +147,25 @@ impl Drop for LogicalType { } } -impl From for LogicalType { - /// Wrap a DuckDB logical type from C API - fn from(ptr: duckdb_logical_type) -> Self { - Self { ptr } - } -} - -impl LogicalType { - /// Create a new [LogicalType] from [LogicalTypeId] - pub fn new(id: LogicalTypeId) -> Self { +impl From for LogicalTypeHandle { + /// Create a new [LogicalTypeHandle] from [LogicalTypeId] + fn from(id: LogicalTypeId) -> Self { unsafe { Self { ptr: duckdb_create_logical_type(id as u32), } } } +} + +impl LogicalTypeHandle { + /// Create a DuckDB logical type from C API + pub(crate) unsafe fn new(ptr: duckdb_logical_type) -> Self { + Self { ptr } + } /// Creates a map type from its child type. - pub fn map(key: &LogicalType, value: &LogicalType) -> Self { + pub fn map(key: &LogicalTypeHandle, value: &LogicalTypeHandle) -> Self { unsafe { Self { ptr: duckdb_create_map_type(key.ptr, value.ptr), @@ -174,7 +174,7 @@ impl LogicalType { } /// Creates a list type from its child type. - pub fn list(child_type: &LogicalType) -> Self { + pub fn list(child_type: &LogicalTypeHandle) -> Self { unsafe { Self { ptr: duckdb_create_list_type(child_type.ptr), @@ -182,6 +182,15 @@ impl LogicalType { } } + /// Creates an array type from its child type. + pub fn array(child_type: &LogicalTypeHandle, array_size: u64) -> Self { + unsafe { + Self { + ptr: duckdb_create_array_type(child_type.ptr, array_size), + } + } + } + /// Creates a decimal type from its `width` and `scale`. pub fn decimal(width: u8, scale: u8) -> Self { unsafe { @@ -204,7 +213,7 @@ impl LogicalType { } /// Make a `LogicalType` for `struct` - pub fn struct_type(fields: &[(&str, LogicalType)]) -> Self { + pub fn struct_type(fields: &[(&str, LogicalTypeHandle)]) -> Self { let keys: Vec = fields.iter().map(|f| CString::new(f.0).unwrap()).collect(); let values: Vec = fields.iter().map(|it| it.1.ptr).collect(); let name_ptrs = keys.iter().map(|it| it.as_ptr()).collect::>(); @@ -221,7 +230,7 @@ impl LogicalType { } /// Make a `LogicalType` for `union` - pub fn union_type(fields: &[(&str, LogicalType)]) -> Self { + pub fn union_type(fields: &[(&str, LogicalTypeHandle)]) -> Self { let keys: Vec = fields.iter().map(|f| CString::new(f.0).unwrap()).collect(); let values: Vec = fields.iter().map(|it| it.1.ptr).collect(); let name_ptrs = keys.iter().map(|it| it.as_ptr()).collect::>(); @@ -278,36 +287,36 @@ impl LogicalType { _ => panic!("not a struct or union"), } }; - Self::from(c_logical_type) + unsafe { Self::new(c_logical_type) } } } #[cfg(test)] mod test { - use super::{LogicalType, LogicalTypeId}; + use crate::core::{LogicalTypeHandle, LogicalTypeId}; #[test] fn test_struct() { - let fields = &[("hello", LogicalType::new(crate::vtab::LogicalTypeId::Boolean))]; - let typ = LogicalType::struct_type(fields); + let fields = &[("hello", LogicalTypeHandle::from(crate::core::LogicalTypeId::Boolean))]; + let typ = LogicalTypeHandle::struct_type(fields); assert_eq!(typ.num_children(), 1); assert_eq!(typ.child_name(0), "hello"); - assert_eq!(typ.child(0).id(), crate::vtab::LogicalTypeId::Boolean); + assert_eq!(typ.child(0).id(), crate::core::LogicalTypeId::Boolean); } #[test] fn test_decimal() { - let typ = LogicalType::decimal(10, 2); + let typ = LogicalTypeHandle::decimal(10, 2); - assert_eq!(typ.id(), crate::vtab::LogicalTypeId::Decimal); + assert_eq!(typ.id(), crate::core::LogicalTypeId::Decimal); assert_eq!(typ.decimal_width(), 10); assert_eq!(typ.decimal_scale(), 2); } #[test] fn test_decimal_methods() { - let typ = LogicalType::new(crate::vtab::LogicalTypeId::Varchar); + let typ = LogicalTypeHandle::from(crate::core::LogicalTypeId::Varchar); assert_eq!(typ.decimal_width(), 0); assert_eq!(typ.decimal_scale(), 0); @@ -316,10 +325,10 @@ mod test { #[test] fn test_union_type() { let fields = &[ - ("hello", LogicalType::new(LogicalTypeId::Boolean)), - ("world", LogicalType::new(LogicalTypeId::Integer)), + ("hello", LogicalTypeHandle::from(LogicalTypeId::Boolean)), + ("world", LogicalTypeHandle::from(LogicalTypeId::Integer)), ]; - let typ = LogicalType::union_type(fields); + let typ = LogicalTypeHandle::union_type(fields); assert_eq!(typ.num_children(), 2); diff --git a/crates/duckdb/src/core/mod.rs b/crates/duckdb/src/core/mod.rs new file mode 100644 index 00000000..21e630fd --- /dev/null +++ b/crates/duckdb/src/core/mod.rs @@ -0,0 +1,7 @@ +mod data_chunk; +mod logical_type; +mod vector; + +pub use data_chunk::DataChunkHandle; +pub use logical_type::{LogicalTypeHandle, LogicalTypeId}; +pub use vector::*; diff --git a/src/vtab/vector.rs b/crates/duckdb/src/core/vector.rs similarity index 70% rename from src/vtab/vector.rs rename to crates/duckdb/src/core/vector.rs index bf61cff4..befda697 100644 --- a/src/vtab/vector.rs +++ b/crates/duckdb/src/core/vector.rs @@ -1,12 +1,15 @@ use std::{any::Any, ffi::CString, slice}; -use super::LogicalType; +use libduckdb_sys::{duckdb_array_type_array_size, duckdb_array_vector_get_child, DuckDbString}; + +use super::LogicalTypeHandle; use crate::ffi::{ duckdb_list_entry, duckdb_list_vector_get_child, duckdb_list_vector_get_size, duckdb_list_vector_reserve, duckdb_list_vector_set_size, duckdb_struct_type_child_count, duckdb_struct_type_child_name, duckdb_struct_vector_get_child, duckdb_validity_set_row_invalid, duckdb_vector, - duckdb_vector_assign_string_element, duckdb_vector_ensure_validity_writable, duckdb_vector_get_column_type, - duckdb_vector_get_data, duckdb_vector_get_validity, duckdb_vector_size, + duckdb_vector_assign_string_element, duckdb_vector_assign_string_element_len, + duckdb_vector_ensure_validity_writable, duckdb_vector_get_column_type, duckdb_vector_get_data, + duckdb_vector_get_validity, duckdb_vector_size, }; /// Vector trait. @@ -68,8 +71,8 @@ impl FlatVector { } /// Returns the logical type of the vector - pub fn logical_type(&self) -> LogicalType { - LogicalType::from(unsafe { duckdb_vector_get_column_type(self.ptr) }) + pub fn logical_type(&self) -> LogicalTypeHandle { + unsafe { LogicalTypeHandle::new(duckdb_vector_get_column_type(self.ptr)) } } /// Set row as null @@ -111,6 +114,21 @@ impl Inserter<&str> for FlatVector { } } +impl Inserter<&[u8]> for FlatVector { + fn insert(&self, index: usize, value: &[u8]) { + let value_size = value.len(); + unsafe { + // This function also works for binary data. https://duckdb.org/docs/api/c/api#duckdb_vector_assign_string_element_len + duckdb_vector_assign_string_element_len( + self.ptr, + index as u64, + value.as_ptr() as *const ::std::os::raw::c_char, + value_size as u64, + ); + } + } +} + /// A list vector. pub struct ListVector { /// ListVector does not own the vector pointer. @@ -170,6 +188,43 @@ impl ListVector { } } +/// A array vector. (fixed-size list) +pub struct ArrayVector { + /// ArrayVector does not own the vector pointer. + ptr: duckdb_vector, +} + +impl From for ArrayVector { + fn from(ptr: duckdb_vector) -> Self { + Self { ptr } + } +} + +impl ArrayVector { + /// Get the logical type of this ArrayVector. + pub fn logical_type(&self) -> LogicalTypeHandle { + unsafe { LogicalTypeHandle::new(duckdb_vector_get_column_type(self.ptr)) } + } + + /// Returns the size of the array type. + pub fn get_array_size(&self) -> u64 { + let ty = self.logical_type(); + unsafe { duckdb_array_type_array_size(ty.ptr) as u64 } + } + + /// Returns the child vector. + /// capacity should be a multiple of the array size. + // TODO: not ideal interface. Where should we keep count. + pub fn child(&self, capacity: usize) -> FlatVector { + FlatVector::with_capacity(unsafe { duckdb_array_vector_get_child(self.ptr) }, capacity) + } + + /// Set primitive data to the child node. + pub fn set_child(&self, data: &[T]) { + self.child(data.len()).copy(data); + } +} + /// A struct vector. pub struct StructVector { /// ListVector does not own the vector pointer. @@ -198,20 +253,22 @@ impl StructVector { ListVector::from(unsafe { duckdb_struct_vector_get_child(self.ptr, idx as u64) }) } + /// Take the child as [ArrayVector]. + pub fn array_vector_child(&self, idx: usize) -> ArrayVector { + ArrayVector::from(unsafe { duckdb_struct_vector_get_child(self.ptr, idx as u64) }) + } + /// Get the logical type of this struct vector. - pub fn logical_type(&self) -> LogicalType { - LogicalType::from(unsafe { duckdb_vector_get_column_type(self.ptr) }) + pub fn logical_type(&self) -> LogicalTypeHandle { + unsafe { LogicalTypeHandle::new(duckdb_vector_get_column_type(self.ptr)) } } /// Get the name of the child by idx. - pub fn child_name(&self, idx: usize) -> String { + pub fn child_name(&self, idx: usize) -> DuckDbString { let logical_type = self.logical_type(); unsafe { let child_name_ptr = duckdb_struct_type_child_name(logical_type.ptr, idx as u64); - let c_str = CString::from_raw(child_name_ptr); - let name = c_str.to_str().unwrap(); - // duckdb_free(child_name_ptr.cast()); - name.to_string() + DuckDbString::from_ptr(child_name_ptr) } } diff --git a/src/error.rs b/crates/duckdb/src/error.rs similarity index 99% rename from src/error.rs rename to crates/duckdb/src/error.rs index 8d07a133..b56e2c35 100644 --- a/src/error.rs +++ b/crates/duckdb/src/error.rs @@ -122,7 +122,7 @@ impl From<::std::ffi::NulError> for Error { } } -const UNKNOWN_COLUMN: usize = std::usize::MAX; +const UNKNOWN_COLUMN: usize = usize::MAX; /// The conversion isn't precise, but it's convenient to have it /// to allow use of `get_raw(…).as_…()?` in callbacks that take `Error`. diff --git a/src/extension.rs b/crates/duckdb/src/extension.rs similarity index 68% rename from src/extension.rs rename to crates/duckdb/src/extension.rs index 1fa54c03..47e3f3fa 100644 --- a/src/extension.rs +++ b/crates/duckdb/src/extension.rs @@ -31,15 +31,4 @@ mod test { ); Ok(()) } - - // https://duckdb.org/docs/extensions/httpfs - #[test] - fn test_extension_httpfs() -> Result<()> { - let db = Connection::open_in_memory()?; - assert_eq!( - 300f32, - db.query_row::(r#"SELECT SUM(value) FROM read_parquet('https://github.com/wangfenjin/duckdb-rs/raw/main/examples/int32_decimal.parquet');"#, [], |r| r.get(0))? - ); - Ok(()) - } } diff --git a/src/inner_connection.rs b/crates/duckdb/src/inner_connection.rs similarity index 100% rename from src/inner_connection.rs rename to crates/duckdb/src/inner_connection.rs diff --git a/src/lib.rs b/crates/duckdb/src/lib.rs similarity index 99% rename from src/lib.rs rename to crates/duckdb/src/lib.rs index 81e2a5d9..6bc59316 100644 --- a/src/lib.rs +++ b/crates/duckdb/src/lib.rs @@ -93,6 +93,9 @@ pub use arrow; #[cfg(feature = "polars")] pub use polars::{self, export::arrow as arrow2}; +/// The core module contains the main functionality of the DuckDB crate. +pub mod core; + #[macro_use] mod error; mod appender; @@ -295,6 +298,7 @@ impl Connection { } let c_path = path_to_cstring(path.as_ref())?; + let config = config.with("duckdb_api", "rust").unwrap(); InnerConnection::open_with_flags(&c_path, config).map(|db| Connection { db: RefCell::new(db), cache: StatementCache::with_capacity(STATEMENT_CACHE_DEFAULT_CAPACITY), @@ -566,7 +570,7 @@ impl fmt::Debug for Connection { } #[cfg(doctest)] -doc_comment::doctest!("../README.md"); +doc_comment::doctest!("../../../README.md"); #[cfg(test)] mod test { @@ -1003,7 +1007,6 @@ mod test { } mod query_and_then_tests { - use super::*; #[derive(Debug)] diff --git a/src/params.rs b/crates/duckdb/src/params.rs similarity index 100% rename from src/params.rs rename to crates/duckdb/src/params.rs diff --git a/src/polars_dataframe.rs b/crates/duckdb/src/polars_dataframe.rs similarity index 100% rename from src/polars_dataframe.rs rename to crates/duckdb/src/polars_dataframe.rs diff --git a/src/pragma.rs b/crates/duckdb/src/pragma.rs similarity index 100% rename from src/pragma.rs rename to crates/duckdb/src/pragma.rs diff --git a/src/r2d2.rs b/crates/duckdb/src/r2d2.rs similarity index 100% rename from src/r2d2.rs rename to crates/duckdb/src/r2d2.rs diff --git a/src/raw_statement.rs b/crates/duckdb/src/raw_statement.rs similarity index 100% rename from src/raw_statement.rs rename to crates/duckdb/src/raw_statement.rs diff --git a/src/row.rs b/crates/duckdb/src/row.rs similarity index 96% rename from src/row.rs rename to crates/duckdb/src/row.rs index d1ac7905..f3def7cf 100644 --- a/src/row.rs +++ b/crates/duckdb/src/row.rs @@ -3,9 +3,8 @@ use std::{convert, sync::Arc}; use super::{Error, Result, Statement}; use crate::types::{self, EnumType, FromSql, FromSqlError, ListType, ValueRef}; -use arrow::array::DictionaryArray; use arrow::{ - array::{self, Array, ArrayRef, ListArray, StructArray}, + array::{self, Array, ArrayRef, DictionaryArray, FixedSizeListArray, ListArray, MapArray, StructArray}, datatypes::*, }; use fallible_iterator::FallibleIterator; @@ -560,12 +559,11 @@ impl<'stmt> Row<'stmt> { let value = array.value(row); - // TODO: remove this manual conversion once arrow-rs bug is fixed - let months = (value) as i32; - let days = (value >> 32) as i32; - let nanos = (value >> 64) as i64; - - ValueRef::Interval { months, days, nanos } + ValueRef::Interval { + months: value.months, + days: value.days, + nanos: value.nanoseconds, + } } _ => unimplemented!("{:?}", unit), }, @@ -609,7 +607,20 @@ impl<'stmt> Row<'stmt> { row, ) } - _ => unreachable!("invalid value: {} {}", col, column.data_type()), + DataType::Struct(_) => { + let res = column.as_any().downcast_ref::().unwrap(); + ValueRef::Struct(res, row) + } + DataType::Map(..) => { + let arr = column.as_any().downcast_ref::().unwrap(); + ValueRef::Map(arr, row) + } + DataType::FixedSizeList(..) => { + let arr = column.as_any().downcast_ref::().unwrap(); + ValueRef::Array(arr, row) + } + DataType::Union(..) => ValueRef::Union(column, row), + _ => unreachable!("invalid value: {}, {}", col, column.data_type()), } } diff --git a/src/statement.rs b/crates/duckdb/src/statement.rs similarity index 95% rename from src/statement.rs rename to crates/duckdb/src/statement.rs index 1a05c2f4..1b0ceca8 100644 --- a/src/statement.rs +++ b/crates/duckdb/src/statement.rs @@ -1,6 +1,6 @@ use std::{convert, ffi::c_void, fmt, mem, os::raw::c_char, ptr, str}; -use arrow::{array::StructArray, datatypes::DataType}; +use arrow::{array::StructArray, datatypes::SchemaRef}; use super::{ffi, AndThenRows, Connection, Error, MappedRows, Params, RawStatement, Result, Row, Rows, ValueRef}; #[cfg(feature = "polars")] @@ -448,10 +448,19 @@ impl Statement<'_> { /// Note that if the SQL does not return results, [`Statement::raw_execute`] /// should be used instead. #[inline] - pub fn raw_query(&mut self) -> Rows<'_> { + pub fn raw_query(&self) -> Rows<'_> { Rows::new(self) } + /// Returns the underlying schema of the prepared statement. + /// + /// # Caveats + /// Panics if the query has not been [`execute`](Statement::execute)d yet. + #[inline] + pub fn schema(&self) -> SchemaRef { + self.stmt.schema() + } + // generic because many of these branches can constant fold away. fn bind_parameter(&self, param: &P, col: usize) -> Result<()> { let value = param.to_sql()?; @@ -542,12 +551,6 @@ impl Statement<'_> { pub(super) fn new(conn: &Connection, stmt: RawStatement) -> Statement<'_> { Statement { conn, stmt } } - - /// column_type - #[inline] - pub fn column_type(&self, idx: usize) -> DataType { - self.stmt.column_type(idx) - } } #[cfg(test)] @@ -806,6 +809,41 @@ mod test { Ok(()) } + #[test] + fn test_get_schema_of_executed_result() -> Result<()> { + use arrow::datatypes::{DataType, Field, Schema}; + let db = Connection::open_in_memory()?; + let sql = "BEGIN; + CREATE TABLE foo(x STRING, y INTEGER); + INSERT INTO foo VALUES('hello', 3); + END;"; + db.execute_batch(sql)?; + let mut stmt = db.prepare("SELECT x, y FROM foo")?; + let _ = stmt.execute([]); + let schema = stmt.schema(); + assert_eq!( + *schema, + Schema::new(vec![ + Field::new("x", DataType::Utf8, true), + Field::new("y", DataType::Int32, true) + ]) + ); + Ok(()) + } + + #[test] + #[should_panic(expected = "called `Option::unwrap()` on a `None` value")] + fn test_unexecuted_schema_panics() { + let db = Connection::open_in_memory().unwrap(); + let sql = "BEGIN; + CREATE TABLE foo(x STRING, y INTEGER); + INSERT INTO foo VALUES('hello', 3); + END;"; + db.execute_batch(sql).unwrap(); + let stmt = db.prepare("SELECT x, y FROM foo").unwrap(); + let _ = stmt.schema(); + } + #[test] fn test_query_by_column_name_ignore_case() -> Result<()> { let db = Connection::open_in_memory()?; diff --git a/src/test_all_types.rs b/crates/duckdb/src/test_all_types.rs similarity index 53% rename from src/test_all_types.rs rename to crates/duckdb/src/test_all_types.rs index 1c324751..4088be1b 100644 --- a/src/test_all_types.rs +++ b/crates/duckdb/src/test_all_types.rs @@ -2,7 +2,7 @@ use pretty_assertions::assert_eq; use rust_decimal::Decimal; use crate::{ - types::{TimeUnit, Type, Value, ValueRef}, + types::{OrderedMap, TimeUnit, Type, Value, ValueRef}, Connection, }; @@ -20,27 +20,9 @@ fn test_large_arrow_types() -> crate::Result<()> { } fn test_with_database(database: &Connection) -> crate::Result<()> { - let excluded = vec![ - // uhugeint, time_tz, and dec38_10 aren't supported in the duckdb arrow layer - "uhugeint", - "time_tz", - "dec38_10", - // union is currently blocked by https://github.com/duckdb/duckdb/pull/11326 - "union", - // these remaining types are not yet supported by duckdb-rs - "struct", - "struct_of_arrays", - "array_of_structs", - "map", - "fixed_int_array", - "fixed_varchar_array", - "fixed_nested_int_array", - "fixed_nested_varchar_array", - "fixed_struct_array", - "struct_of_fixed_array", - "fixed_array_of_int_list", - "list_of_fixed_int_array", - ]; + // uhugeint, time_tz, and dec38_10 aren't supported in the duckdb arrow layer + // union is currently blocked by https://github.com/duckdb/duckdb/pull/11326 + let excluded = ["uhugeint", "time_tz", "dec38_10", "union"]; let mut binding = database.prepare(&format!( "SELECT * EXCLUDE ({}) FROM test_all_types()", @@ -58,7 +40,7 @@ fn test_with_database(database: &Connection) -> crate::Result<()> { for column in row.stmt.column_names() { let value = row.get_ref_unwrap(row.stmt.column_index(&column)?); if idx != 2 { - assert_ne!(value.data_type(), Type::Null); + assert_ne!(value.data_type(), Type::Null, "column {column} is null: {value:?}"); } test_single(&mut idx, column, value); } @@ -249,6 +231,14 @@ fn test_single(idx: &mut i32, column: String, value: ValueRef) { } _ => assert_eq!(value, ValueRef::Null), }, + "float_array" => match idx { + 0 => assert_eq!(value.to_owned(), Value::List(vec![])), + 1 => assert_eq!( + value.to_owned(), + Value::List(vec![Value::Float(1.0), Value::Float(2.0)]) + ), + _ => assert_eq!(value, ValueRef::Null), + }, "date_array" => match idx { 0 => assert_eq!(value.to_owned(), Value::List(vec![])), 1 => assert_eq!( @@ -332,6 +322,304 @@ fn test_single(idx: &mut i32, column: String, value: ValueRef) { } _ => assert_eq!(value, ValueRef::Null), }, + "struct" => match idx { + 0 => assert_eq!( + value.to_owned(), + Value::Struct(OrderedMap::from(vec![ + ("a".to_string(), Value::Null), + ("b".to_string(), Value::Null), + ])) + ), + 1 => assert_eq!( + value.to_owned(), + Value::Struct(OrderedMap::from(vec![ + ("a".to_string(), Value::Int(42)), + ("b".to_string(), Value::Text("🦆🦆🦆🦆🦆🦆".to_string())), + ])) + ), + _ => assert_eq!(value, ValueRef::Null), + }, + "struct_of_arrays" => match idx { + 0 => assert_eq!( + value.to_owned(), + Value::Struct(OrderedMap::from(vec![ + ("a".to_string(), Value::Null), + ("b".to_string(), Value::Null), + ])) + ), + 1 => assert_eq!( + value.to_owned(), + Value::Struct(OrderedMap::from(vec![ + ( + "a".to_string(), + Value::List(vec![ + Value::Int(42), + Value::Int(999), + Value::Null, + Value::Null, + Value::Int(-42) + ]) + ), + ( + "b".to_string(), + Value::List(vec![ + Value::Text("🦆🦆🦆🦆🦆🦆".to_string()), + Value::Text("goose".to_string()), + Value::Null, + Value::Text("".to_string()), + ]), + ) + ])) + ), + _ => assert_eq!(value, ValueRef::Null), + }, + "array_of_structs" => match idx { + 0 => assert_eq!(value.to_owned(), Value::List(vec![])), + 1 => assert_eq!( + value.to_owned(), + Value::List(vec![ + Value::Struct(OrderedMap::from(vec![ + ("a".to_string(), Value::Null), + ("b".to_string(), Value::Null) + ])), + Value::Struct(OrderedMap::from(vec![ + ("a".to_string(), Value::Int(42)), + ("b".to_string(), Value::Text("🦆🦆🦆🦆🦆🦆".to_string())) + ])), + Value::Null + ]) + ), + _ => assert_eq!(value, ValueRef::Null), + }, + "map" => match idx { + 0 => assert_eq!(value.to_owned(), Value::Map(OrderedMap::from(vec![]))), + 1 => assert_eq!( + value.to_owned(), + Value::Map(OrderedMap::from(vec![ + (Value::Text("key1".to_string()), Value::Text("🦆🦆🦆🦆🦆🦆".to_string())), + (Value::Text("key2".to_string()), Value::Text("goose".to_string())), + ])) + ), + _ => assert_eq!(value, ValueRef::Null), + }, + "fixed_int_array" => match idx { + 0 => assert_eq!( + value.to_owned(), + Value::Array(vec![Value::Null, Value::Int(2), Value::Int(3)]) + ), + 1 => assert_eq!( + value.to_owned(), + Value::Array(vec![Value::Int(4), Value::Int(5), Value::Int(6)]) + ), + _ => assert_eq!(value, ValueRef::Null), + }, + "fixed_varchar_array" => match idx { + 0 => assert_eq!( + value.to_owned(), + Value::Array(vec![ + Value::Text("a".to_string()), + Value::Null, + Value::Text("c".to_string()) + ]) + ), + 1 => assert_eq!( + value.to_owned(), + Value::Array(vec![ + Value::Text("d".to_string()), + Value::Text("e".to_string()), + Value::Text("f".to_string()) + ]) + ), + _ => assert_eq!(value, ValueRef::Null), + }, + "fixed_nested_int_array" => match idx { + 0 => assert_eq!( + value.to_owned(), + Value::Array(vec![ + Value::Array(vec![Value::Null, Value::Int(2), Value::Int(3)]), + Value::Null, + Value::Array(vec![Value::Null, Value::Int(2), Value::Int(3)]) + ]) + ), + 1 => assert_eq!( + value.to_owned(), + Value::Array(vec![ + Value::Array(vec![Value::Int(4), Value::Int(5), Value::Int(6)]), + Value::Array(vec![Value::Null, Value::Int(2), Value::Int(3)]), + Value::Array(vec![Value::Int(4), Value::Int(5), Value::Int(6)]), + ]) + ), + _ => assert_eq!(value, ValueRef::Null), + }, + "fixed_nested_varchar_array" => match idx { + 0 => assert_eq!( + value.to_owned(), + Value::Array(vec![ + Value::Array(vec![ + Value::Text("a".to_string()), + Value::Null, + Value::Text("c".to_string()) + ]), + Value::Null, + Value::Array(vec![ + Value::Text("a".to_string()), + Value::Null, + Value::Text("c".to_string()) + ]) + ]) + ), + 1 => assert_eq!( + value.to_owned(), + Value::Array(vec![ + Value::Array(vec![ + Value::Text("d".to_string()), + Value::Text("e".to_string()), + Value::Text("f".to_string()) + ]), + Value::Array(vec![ + Value::Text("a".to_string()), + Value::Null, + Value::Text("c".to_string()) + ]), + Value::Array(vec![ + Value::Text("d".to_string()), + Value::Text("e".to_string()), + Value::Text("f".to_string()) + ]), + ]) + ), + _ => assert_eq!(value, ValueRef::Null), + }, + "fixed_struct_array" => match idx { + 0 => assert_eq!( + value.to_owned(), + Value::Array(vec![ + Value::Struct(OrderedMap::from(vec![ + ("a".to_string(), Value::Null), + ("b".to_string(), Value::Null) + ])), + Value::Struct(OrderedMap::from(vec![ + ("a".to_string(), Value::Int(42)), + ("b".to_string(), Value::Text("🦆🦆🦆🦆🦆🦆".to_string())) + ])), + Value::Struct(OrderedMap::from(vec![ + ("a".to_string(), Value::Null), + ("b".to_string(), Value::Null) + ])), + ]) + ), + 1 => assert_eq!( + value.to_owned(), + Value::Array(vec![ + Value::Struct(OrderedMap::from(vec![ + ("a".to_string(), Value::Int(42)), + ("b".to_string(), Value::Text("🦆🦆🦆🦆🦆🦆".to_string())) + ])), + Value::Struct(OrderedMap::from(vec![ + ("a".to_string(), Value::Null), + ("b".to_string(), Value::Null) + ])), + Value::Struct(OrderedMap::from(vec![ + ("a".to_string(), Value::Int(42)), + ("b".to_string(), Value::Text("🦆🦆🦆🦆🦆🦆".to_string())) + ])), + ]) + ), + _ => assert_eq!(value, ValueRef::Null), + }, + "struct_of_fixed_array" => match idx { + 0 => assert_eq!( + value.to_owned(), + Value::Struct(OrderedMap::from(vec![ + ( + "a".to_string(), + Value::Array(vec![Value::Null, Value::Int(2), Value::Int(3)]) + ), + ( + "b".to_string(), + Value::Array(vec![ + Value::Text("a".to_string()), + Value::Null, + Value::Text("c".to_string()) + ]) + ), + ])) + ), + 1 => assert_eq!( + value.to_owned(), + Value::Struct(OrderedMap::from(vec![ + ( + "a".to_string(), + Value::Array(vec![Value::Int(4), Value::Int(5), Value::Int(6)]), + ), + ( + "b".to_string(), + Value::Array(vec![ + Value::Text("d".to_string()), + Value::Text("e".to_string()), + Value::Text("f".to_string()) + ]), + ) + ])) + ), + _ => assert_eq!(value, ValueRef::Null), + }, + "fixed_array_of_int_list" => match idx { + 0 => assert_eq!( + value.to_owned(), + Value::Array(vec![ + Value::List(vec![]), + Value::List(vec![ + Value::Int(42), + Value::Int(999), + Value::Null, + Value::Null, + Value::Int(-42), + ]), + Value::List(vec![]), + ]) + ), + 1 => assert_eq!( + value.to_owned(), + Value::Array(vec![ + Value::List(vec![ + Value::Int(42), + Value::Int(999), + Value::Null, + Value::Null, + Value::Int(-42), + ]), + Value::List(vec![]), + Value::List(vec![ + Value::Int(42), + Value::Int(999), + Value::Null, + Value::Null, + Value::Int(-42), + ]), + ]) + ), + _ => assert_eq!(value, ValueRef::Null), + }, + "list_of_fixed_int_array" => match idx { + 0 => assert_eq!( + value.to_owned(), + Value::List(vec![ + Value::Array(vec![Value::Null, Value::Int(2), Value::Int(3)]), + Value::Array(vec![Value::Int(4), Value::Int(5), Value::Int(6)]), + Value::Array(vec![Value::Null, Value::Int(2), Value::Int(3)]), + ]) + ), + 1 => assert_eq!( + value.to_owned(), + Value::List(vec![ + Value::Array(vec![Value::Int(4), Value::Int(5), Value::Int(6)]), + Value::Array(vec![Value::Null, Value::Int(2), Value::Int(3)]), + Value::Array(vec![Value::Int(4), Value::Int(5), Value::Int(6)]), + ]) + ), + _ => assert_eq!(value, ValueRef::Null), + }, "bit" => match idx { 0 => assert_eq!(value, ValueRef::Blob(&[1, 145, 46, 42, 215]),), 1 => assert_eq!(value, ValueRef::Blob(&[3, 245])), @@ -371,6 +659,14 @@ fn test_single(idx: &mut i32, column: String, value: ValueRef) { 1 => assert_eq!(value.to_owned(), Value::Enum("enum_69999".to_string())), _ => assert_eq!(value, ValueRef::Null), }, + "union" => match idx { + 0 => assert_eq!( + value.to_owned(), + Value::Union(Box::new(Value::Text("Frank".to_owned()))) + ), + 1 => assert_eq!(value.to_owned(), Value::Union(Box::new(Value::SmallInt(5)))), + _ => assert_eq!(value.to_owned(), Value::Union(Box::new(Value::Null))), + }, _ => todo!("{column:?}"), } } diff --git a/src/transaction.rs b/crates/duckdb/src/transaction.rs similarity index 100% rename from src/transaction.rs rename to crates/duckdb/src/transaction.rs diff --git a/src/types/chrono.rs b/crates/duckdb/src/types/chrono.rs similarity index 100% rename from src/types/chrono.rs rename to crates/duckdb/src/types/chrono.rs diff --git a/src/types/from_sql.rs b/crates/duckdb/src/types/from_sql.rs similarity index 100% rename from src/types/from_sql.rs rename to crates/duckdb/src/types/from_sql.rs diff --git a/src/types/mod.rs b/crates/duckdb/src/types/mod.rs similarity index 83% rename from src/types/mod.rs rename to crates/duckdb/src/types/mod.rs index 93222b09..f8ae5c58 100644 --- a/src/types/mod.rs +++ b/crates/duckdb/src/types/mod.rs @@ -1,74 +1,10 @@ -//! Traits dealing with DuckDB data types. -//! -//! DuckDB uses a [dynamic type system](https://www.sqlite.org/datatype3.html). Implementations of -//! the [`ToSql`] and [`FromSql`] traits are provided for the basic types that -//! DuckDB provides methods for: -//! -//! * Strings (`String` and `&str`) -//! * Blobs (`Vec` and `&[u8]`) -//! * Numbers -//! -//! The number situation is a little complicated due to the fact that all -//! numbers in DuckDB are stored as `INTEGER` (`i64`) or `REAL` (`f64`). -//! -//! [`ToSql`] and [`FromSql`] are implemented for all primitive number types. -//! [`FromSql`] has different behaviour depending on the SQL and Rust types, and -//! the value. -//! -//! * `INTEGER` to integer: returns an -//! [`Error::IntegralValueOutOfRange`](crate::Error::IntegralValueOutOfRange) -//! error if the value does not fit in the Rust type. -//! * `REAL` to integer: always returns an -//! [`Error::InvalidColumnType`](crate::Error::InvalidColumnType) error. -//! * `INTEGER` to float: casts using `as` operator. Never fails. -//! * `REAL` to float: casts using `as` operator. Never fails. -//! -//! [`ToSql`] always succeeds except when storing a `u64` or `usize` value that -//! cannot fit in an `INTEGER` (`i64`). Also note that DuckDB ignores column -//! types, so if you store an `i64` in a column with type `REAL` it will be -//! stored as an `INTEGER`, not a `REAL`. -//! -//! If the `time` feature is enabled, implementations are -//! provided for `time::OffsetDateTime` that use the RFC 3339 date/time format, -//! `"%Y-%m-%dT%H:%M:%S.%fZ"`, to store time values as strings. These values -//! can be parsed by SQLite's builtin -//! [datetime](https://www.sqlite.org/lang_datefunc.html) functions. If you -//! want different storage for datetimes, you can use a newtype. -#![cfg_attr( - feature = "time", - doc = r##" -For example, to store datetimes as `i64`s counting the number of seconds since -the Unix epoch: - -``` -use duckdb::types::{FromSql, FromSqlResult, ToSql, ToSqlOutput, ValueRef}; -use duckdb::Result; - -pub struct DateTimeSql(pub time::OffsetDateTime); - -impl FromSql for DateTimeSql { - fn column_result(value: ValueRef) -> FromSqlResult { - i64::column_result(value).map(|as_i64| { - DateTimeSql(time::OffsetDateTime::from_unix_timestamp(as_i64)) - }) - } -} - -impl ToSql for DateTimeSql { - fn to_sql(&self) -> Result { - Ok(self.0.timestamp().into()) - } -} -``` - -"## -)] //! [`ToSql`] and [`FromSql`] are also implemented for `Option` where `T` //! implements [`ToSql`] or [`FromSql`] for the cases where you want to know if //! a value was NULL (which gets translated to `None`). pub use self::{ from_sql::{FromSql, FromSqlError, FromSqlResult}, + ordered_map::OrderedMap, to_sql::{ToSql, ToSqlOutput}, value::Value, value_ref::{EnumType, ListType, TimeUnit, ValueRef}, @@ -88,6 +24,8 @@ mod url; mod value; mod value_ref; +mod ordered_map; + /// Empty struct that can be used to fill in a query parameter as `NULL`. /// /// ## Example @@ -151,6 +89,14 @@ pub enum Type { List(Box), /// ENUM Enum, + /// STRUCT + Struct(Vec<(String, Type)>), + /// MAP + Map(Box, Box), + /// ARRAY + Array(Box, u32), + /// UNION + Union, /// Any Any, } @@ -183,13 +129,30 @@ impl From<&DataType> for Type { // DataType::LargeBinary => Self::LargeBinary, DataType::LargeUtf8 | DataType::Utf8 => Self::Text, DataType::List(inner) => Self::List(Box::new(Type::from(inner.data_type()))), - // DataType::FixedSizeList(field, size) => Self::Array, + DataType::FixedSizeList(field, size) => { + Self::Array(Box::new(Type::from(field.data_type())), (*size).try_into().unwrap()) + } + // DataType::LargeList(_) => Self::LargeList, + DataType::Struct(inner) => Self::Struct( + inner + .iter() + .map(|f| (f.name().to_owned(), Type::from(f.data_type()))) + .collect(), + ), DataType::LargeList(inner) => Self::List(Box::new(Type::from(inner.data_type()))), - // DataType::Struct(inner) => Self::Struct, // DataType::Union(_, _) => Self::Union, DataType::Decimal128(..) => Self::Decimal, DataType::Decimal256(..) => Self::Decimal, - // DataType::Map(field, ..) => Self::Map, + DataType::Map(field, ..) => { + let data_type = field.data_type(); + match data_type { + DataType::Struct(fields) => Self::Map( + Box::new(Type::from(fields[0].data_type())), + Box::new(Type::from(fields[1].data_type())), + ), + _ => unreachable!(), + } + } res => unimplemented!("{}", res), } } @@ -218,8 +181,12 @@ impl fmt::Display for Type { Type::Date32 => f.pad("Date32"), Type::Time64 => f.pad("Time64"), Type::Interval => f.pad("Interval"), + Type::Struct(..) => f.pad("Struct"), Type::List(..) => f.pad("List"), Type::Enum => f.pad("Enum"), + Type::Map(..) => f.pad("Map"), + Type::Array(..) => f.pad("Array"), + Type::Union => f.pad("Union"), Type::Any => f.pad("Any"), } } @@ -229,10 +196,7 @@ impl fmt::Display for Type { mod test { use super::Value; use crate::{params, Connection, Error, Result, Statement}; - use std::{ - f64::EPSILON, - os::raw::{c_double, c_int}, - }; + use std::os::raw::{c_double, c_int}; fn checked_memory_handle() -> Result { let db = Connection::open_in_memory()?; @@ -353,7 +317,7 @@ mod test { assert_eq!(vec![1, 2], row.get::<_, Vec>(0)?); assert_eq!("text", row.get::<_, String>(1)?); assert_eq!(1, row.get::<_, c_int>(2)?); - assert!((1.5 - row.get::<_, c_double>(3)?).abs() < EPSILON); + assert!((1.5 - row.get::<_, c_double>(3)?).abs() < f64::EPSILON); assert_eq!(row.get::<_, Option>(4)?, None); assert_eq!(row.get::<_, Option>(4)?, None); assert_eq!(row.get::<_, Option>(4)?, None); @@ -366,10 +330,6 @@ mod test { assert!(is_invalid_column_type(row.get::<_, i64>(0).err().unwrap())); assert!(is_invalid_column_type(row.get::<_, c_double>(0).err().unwrap())); assert!(is_invalid_column_type(row.get::<_, String>(0).err().unwrap())); - #[cfg(feature = "time")] - assert!(is_invalid_column_type( - row.get::<_, time::OffsetDateTime>(0).err().unwrap() - )); assert!(is_invalid_column_type(row.get::<_, Option>(0).err().unwrap())); // 1 is actually a text (String) @@ -397,10 +357,6 @@ mod test { assert!(is_invalid_column_type(row.get::<_, c_double>(4).err().unwrap())); assert!(is_invalid_column_type(row.get::<_, String>(4).err().unwrap())); assert!(is_invalid_column_type(row.get::<_, Vec>(4).err().unwrap())); - #[cfg(feature = "time")] - assert!(is_invalid_column_type( - row.get::<_, time::OffsetDateTime>(4).err().unwrap() - )); Ok(()) } @@ -421,7 +377,7 @@ mod test { assert_eq!(Value::Text(String::from("text")), row.get::<_, Value>(1)?); assert_eq!(Value::Int(1), row.get::<_, Value>(2)?); match row.get::<_, Value>(3)? { - Value::Float(val) => assert!((1.5 - val).abs() < EPSILON as f32), + Value::Float(val) => assert!((1.5 - val).abs() < f32::EPSILON), x => panic!("Invalid Value {x:?}"), } assert_eq!(Value::Null, row.get::<_, Value>(4)?); diff --git a/crates/duckdb/src/types/ordered_map.rs b/crates/duckdb/src/types/ordered_map.rs new file mode 100644 index 00000000..09d9392f --- /dev/null +++ b/crates/duckdb/src/types/ordered_map.rs @@ -0,0 +1,28 @@ +/// An ordered map of key-value pairs. +#[derive(Clone, Debug, Eq, PartialEq)] +pub struct OrderedMap(Vec<(K, V)>); + +impl From> for OrderedMap { + fn from(value: Vec<(K, V)>) -> Self { + OrderedMap(value) + } +} + +impl OrderedMap { + /// Returns the value corresponding to the key. + pub fn get(&self, key: &K) -> Option<&V> { + self.0.iter().find(|(k, _)| k == key).map(|(_, v)| v) + } + /// Returns an iterator over the keys in the map. + pub fn keys(&self) -> impl Iterator { + self.0.iter().map(|(k, _)| k) + } + /// Returns an iterator over the values in the map. + pub fn values(&self) -> impl Iterator { + self.0.iter().map(|(_, v)| v) + } + /// Returns an iterator over the key-value pairs in the map. + pub fn iter(&self) -> impl Iterator { + self.0.iter() + } +} diff --git a/src/types/serde_json.rs b/crates/duckdb/src/types/serde_json.rs similarity index 100% rename from src/types/serde_json.rs rename to crates/duckdb/src/types/serde_json.rs diff --git a/src/types/to_sql.rs b/crates/duckdb/src/types/to_sql.rs similarity index 100% rename from src/types/to_sql.rs rename to crates/duckdb/src/types/to_sql.rs diff --git a/src/types/url.rs b/crates/duckdb/src/types/url.rs similarity index 100% rename from src/types/url.rs rename to crates/duckdb/src/types/url.rs diff --git a/src/types/value.rs b/crates/duckdb/src/types/value.rs similarity index 92% rename from src/types/value.rs rename to crates/duckdb/src/types/value.rs index 78ee8b39..03c7b3dd 100644 --- a/src/types/value.rs +++ b/crates/duckdb/src/types/value.rs @@ -1,4 +1,4 @@ -use super::{Null, TimeUnit, Type}; +use super::{Null, OrderedMap, TimeUnit, Type}; use rust_decimal::prelude::*; /// Owning [dynamic type value](http://sqlite.org/datatype3.html). Value's type is typically @@ -59,6 +59,14 @@ pub enum Value { List(Vec), /// The value is an enum Enum(String), + /// The value is a struct + Struct(OrderedMap), + /// The value is an array + Array(Vec), + /// The value is a map + Map(OrderedMap), + /// The value is a union + Union(Box), } impl From for Value { @@ -226,7 +234,7 @@ impl Value { Value::Date32(_) => Type::Date32, Value::Time64(..) => Type::Time64, Value::Interval { .. } => Type::Interval, - Value::List(_) => todo!(), + Value::Union(..) | Value::Struct(..) | Value::List(..) | Value::Array(..) | Value::Map(..) => todo!(), Value::Enum(..) => Type::Enum, } } diff --git a/src/types/value_ref.rs b/crates/duckdb/src/types/value_ref.rs similarity index 74% rename from src/types/value_ref.rs rename to crates/duckdb/src/types/value_ref.rs index 60ef8c7d..45e53c9d 100644 --- a/src/types/value_ref.rs +++ b/crates/duckdb/src/types/value_ref.rs @@ -1,11 +1,16 @@ use super::{Type, Value}; -use crate::types::{FromSqlError, FromSqlResult}; +use crate::types::{FromSqlError, FromSqlResult, OrderedMap}; use crate::Row; use rust_decimal::prelude::*; -use arrow::array::{Array, ArrayRef, DictionaryArray, LargeListArray, ListArray}; -use arrow::datatypes::{UInt16Type, UInt32Type, UInt8Type}; +use arrow::{ + array::{ + Array, ArrayRef, DictionaryArray, FixedSizeListArray, LargeListArray, ListArray, MapArray, StructArray, + UnionArray, + }, + datatypes::{UInt16Type, UInt32Type, UInt8Type}, +}; /// An absolute length of time in seconds, milliseconds, microseconds or nanoseconds. /// Copy from arrow::datatypes::TimeUnit @@ -21,6 +26,18 @@ pub enum TimeUnit { Nanosecond, } +impl TimeUnit { + /// Convert a number of `TimeUnit` to microseconds. + pub fn to_micros(&self, value: i64) -> i64 { + match self { + TimeUnit::Second => value * 1_000_000, + TimeUnit::Millisecond => value * 1000, + TimeUnit::Microsecond => value, + TimeUnit::Nanosecond => value / 1000, + } + } +} + /// A non-owning [static type value](https://duckdb.org/docs/sql/data_types/overview). Typically the /// memory backing this value is owned by SQLite. /// @@ -78,6 +95,14 @@ pub enum ValueRef<'a> { List(ListType<'a>, usize), /// The value is an enum Enum(EnumType<'a>, usize), + /// The value is a struct + Struct(&'a StructArray, usize), + /// The value is an array + Array(&'a FixedSizeListArray, usize), + /// The value is a map + Map(&'a MapArray, usize), + /// The value is a union + Union(&'a ArrayRef, usize), } /// Wrapper type for different list sizes @@ -125,11 +150,15 @@ impl ValueRef<'_> { ValueRef::Date32(_) => Type::Date32, ValueRef::Time64(..) => Type::Time64, ValueRef::Interval { .. } => Type::Interval, + ValueRef::Struct(arr, _) => arr.data_type().into(), + ValueRef::Map(arr, _) => arr.data_type().into(), + ValueRef::Array(arr, _) => arr.data_type().into(), ValueRef::List(arr, _) => match arr { ListType::Large(arr) => arr.data_type().into(), ListType::Regular(arr) => arr.data_type().into(), }, ValueRef::Enum(..) => Type::Enum, + ValueRef::Union(arr, _) => arr.data_type().into(), } } @@ -227,6 +256,50 @@ impl From> for Value { panic!("Enum value is not a string") } } + ValueRef::Struct(items, idx) => { + let value: Vec<(String, Value)> = items + .columns() + .iter() + .zip(items.fields().iter().map(|f| f.name().to_owned())) + .map(|(column, name)| -> (String, Value) { + (name, Row::value_ref_internal(idx, 0, column).to_owned()) + }) + .collect(); + Value::Struct(OrderedMap::from(value)) + } + ValueRef::Map(arr, idx) => { + let keys = arr.keys(); + let values = arr.values(); + let offsets = arr.offsets(); + let range = offsets[idx]..offsets[idx + 1]; + Value::Map(OrderedMap::from( + range + .map(|row| { + let row = row.try_into().unwrap(); + let key = Row::value_ref_internal(row, idx, keys).to_owned(); + let value = Row::value_ref_internal(row, idx, values).to_owned(); + (key, value) + }) + .collect::>(), + )) + } + ValueRef::Array(items, idx) => { + let value_length = usize::try_from(items.value_length()).unwrap(); + let range = (idx * value_length)..((idx + 1) * value_length); + Value::Array( + range + .map(|row| Row::value_ref_internal(row, idx, items.values()).to_owned()) + .collect(), + ) + } + ValueRef::Union(column, idx) => { + let column = column.as_any().downcast_ref::().unwrap(); + let type_id = column.type_id(idx); + let value_offset = column.value_offset(idx); + + let tag = Row::value_ref_internal(idx, value_offset, column.child(type_id)); + Value::Union(Box::new(tag.to_owned())) + } } } } @@ -277,8 +350,10 @@ impl<'a> From<&'a Value> for ValueRef<'a> { Value::Date32(d) => ValueRef::Date32(d), Value::Time64(t, d) => ValueRef::Time64(t, d), Value::Interval { months, days, nanos } => ValueRef::Interval { months, days, nanos }, - Value::List(..) => unimplemented!(), Value::Enum(..) => todo!(), + Value::List(..) | Value::Struct(..) | Value::Map(..) | Value::Array(..) | Value::Union(..) => { + unimplemented!() + } } } } diff --git a/src/util/mod.rs b/crates/duckdb/src/util/mod.rs similarity index 100% rename from src/util/mod.rs rename to crates/duckdb/src/util/mod.rs diff --git a/src/util/small_cstr.rs b/crates/duckdb/src/util/small_cstr.rs similarity index 100% rename from src/util/small_cstr.rs rename to crates/duckdb/src/util/small_cstr.rs diff --git a/src/vtab/arrow.rs b/crates/duckdb/src/vtab/arrow.rs similarity index 65% rename from src/vtab/arrow.rs rename to crates/duckdb/src/vtab/arrow.rs index b5835cbe..671cc983 100644 --- a/src/vtab/arrow.rs +++ b/crates/duckdb/src/vtab/arrow.rs @@ -1,14 +1,15 @@ -use super::{ - vector::{FlatVector, ListVector, Vector}, - BindInfo, DataChunk, Free, FunctionInfo, InitInfo, LogicalType, LogicalTypeId, StructVector, VTab, -}; +use super::{BindInfo, DataChunkHandle, Free, FunctionInfo, InitInfo, LogicalTypeHandle, LogicalTypeId, VTab}; use std::ptr::null_mut; -use crate::vtab::vector::Inserter; -use arrow::array::{ - as_boolean_array, as_large_list_array, as_list_array, as_primitive_array, as_string_array, as_struct_array, Array, - ArrayData, AsArray, BooleanArray, Decimal128Array, FixedSizeListArray, GenericListArray, OffsetSizeTrait, - PrimitiveArray, StringArray, StructArray, +use crate::core::{ArrayVector, FlatVector, Inserter, ListVector, StructVector, Vector}; +use arrow::{ + array::{ + as_boolean_array, as_generic_binary_array, as_large_list_array, as_list_array, as_primitive_array, + as_string_array, as_struct_array, Array, ArrayData, AsArray, BinaryArray, BooleanArray, Decimal128Array, + FixedSizeBinaryArray, FixedSizeListArray, GenericListArray, GenericStringArray, IntervalMonthDayNanoArray, + LargeBinaryArray, LargeStringArray, OffsetSizeTrait, PrimitiveArray, StructArray, + }, + compute::cast, }; use arrow::{ @@ -17,7 +18,7 @@ use arrow::{ record_batch::RecordBatch, }; -use num::cast::AsPrimitive; +use num::{cast::AsPrimitive, ToPrimitive}; /// A pointer to the Arrow record batch for the table function. #[repr(C)] @@ -102,7 +103,7 @@ impl VTab for ArrowVTab { Ok(()) } - unsafe fn func(func: &FunctionInfo, output: &mut DataChunk) -> Result<(), Box> { + unsafe fn func(func: &FunctionInfo, output: &mut DataChunkHandle) -> Result<(), Box> { let init_info = func.get_init_data::(); let bind_info = func.get_bind_data::(); unsafe { @@ -119,10 +120,10 @@ impl VTab for ArrowVTab { Ok(()) } - fn parameters() -> Option> { + fn parameters() -> Option> { Some(vec![ - LogicalType::new(LogicalTypeId::UBigint), // file path - LogicalType::new(LogicalTypeId::UBigint), // sheet name + LogicalTypeHandle::from(LogicalTypeId::UBigint), // file path + LogicalTypeHandle::from(LogicalTypeId::UBigint), // sheet name ]) } } @@ -165,7 +166,7 @@ pub fn to_duckdb_type_id(data_type: &DataType) -> Result Decimal, // DataType::Decimal256(_, _) => Decimal, - DataType::Decimal128(_, _) => Double, + DataType::Decimal128(_, _) => Decimal, DataType::Decimal256(_, _) => Double, DataType::Map(_, _) => Map, _ => { @@ -176,33 +177,38 @@ pub fn to_duckdb_type_id(data_type: &DataType) -> Result Result> { - if data_type.is_primitive() - || matches!( - data_type, - DataType::Boolean | DataType::Utf8 | DataType::LargeUtf8 | DataType::Binary | DataType::LargeBinary - ) - { - Ok(LogicalType::new(to_duckdb_type_id(data_type)?)) - } else if let DataType::Dictionary(_, value_type) = data_type { - to_duckdb_logical_type(value_type) - } else if let DataType::Struct(fields) = data_type { - let mut shape = vec![]; - for field in fields.iter() { - shape.push((field.name().as_str(), to_duckdb_logical_type(field.data_type())?)); - } - Ok(LogicalType::struct_type(shape.as_slice())) - } else if let DataType::List(child) = data_type { - Ok(LogicalType::list(&to_duckdb_logical_type(child.data_type())?)) - } else if let DataType::LargeList(child) = data_type { - Ok(LogicalType::list(&to_duckdb_logical_type(child.data_type())?)) - } else if let DataType::FixedSizeList(child, _) = data_type { - Ok(LogicalType::list(&to_duckdb_logical_type(child.data_type())?)) - } else { - Err( - format!("Unsupported data type: {data_type}, please file an issue https://github.com/wangfenjin/duckdb-rs") - .into(), +pub fn to_duckdb_logical_type(data_type: &DataType) -> Result> { + match data_type { + DataType::Dictionary(_, value_type) => to_duckdb_logical_type(value_type), + DataType::Struct(fields) => { + let mut shape = vec![]; + for field in fields.iter() { + shape.push((field.name().as_str(), to_duckdb_logical_type(field.data_type())?)); + } + Ok(LogicalTypeHandle::struct_type(shape.as_slice())) + } + DataType::List(child) | DataType::LargeList(child) => { + Ok(LogicalTypeHandle::list(&to_duckdb_logical_type(child.data_type())?)) + } + DataType::FixedSizeList(child, array_size) => Ok(LogicalTypeHandle::array( + &to_duckdb_logical_type(child.data_type())?, + *array_size as u64, + )), + DataType::Decimal128(width, scale) if *scale > 0 => { + // DuckDB does not support negative decimal scales + Ok(LogicalTypeHandle::decimal(*width, (*scale).try_into().unwrap())) + } + DataType::Boolean + | DataType::Utf8 + | DataType::LargeUtf8 + | DataType::Binary + | DataType::LargeBinary + | DataType::FixedSizeBinary(_) => Ok(LogicalTypeHandle::from(to_duckdb_type_id(data_type)?)), + dtype if dtype.is_primitive() => Ok(LogicalTypeHandle::from(to_duckdb_type_id(data_type)?)), + _ => Err(format!( + "Unsupported data type: {data_type}, please file an issue https://github.com/wangfenjin/duckdb-rs" ) + .into()), } } @@ -214,7 +220,7 @@ pub fn to_duckdb_logical_type(data_type: &DataType) -> Result Result<(), Box> { // Fill the row assert_eq!(batch.num_columns(), chunk.num_columns()); @@ -227,6 +233,30 @@ pub fn record_batch_to_duckdb_data_chunk( DataType::Utf8 => { string_array_to_vector(as_string_array(col.as_ref()), &mut chunk.flat_vector(i)); } + DataType::LargeUtf8 => { + string_array_to_vector( + col.as_ref() + .as_any() + .downcast_ref::() + .ok_or_else(|| Box::::from("Unable to downcast to LargeStringArray"))?, + &mut chunk.flat_vector(i), + ); + } + DataType::Binary => { + binary_array_to_vector(as_generic_binary_array(col.as_ref()), &mut chunk.flat_vector(i)); + } + DataType::FixedSizeBinary(_) => { + fixed_size_binary_array_to_vector(col.as_ref().as_fixed_size_binary(), &mut chunk.flat_vector(i)); + } + DataType::LargeBinary => { + large_binary_array_to_vector( + col.as_ref() + .as_any() + .downcast_ref::() + .ok_or_else(|| Box::::from("Unable to downcast to LargeBinaryArray"))?, + &mut chunk.flat_vector(i), + ); + } DataType::List(_) => { list_array_to_vector(as_list_array(col.as_ref()), &mut chunk.list_vector(i))?; } @@ -234,7 +264,7 @@ pub fn record_batch_to_duckdb_data_chunk( list_array_to_vector(as_large_list_array(col.as_ref()), &mut chunk.list_vector(i))?; } DataType::FixedSizeList(_, _) => { - fixed_size_list_array_to_vector(as_fixed_size_list_array(col.as_ref()), &mut chunk.list_vector(i))?; + fixed_size_list_array_to_vector(as_fixed_size_list_array(col.as_ref()), &mut chunk.array_vector(i))?; } DataType::Struct(_) => { let struct_array = as_struct_array(col.as_ref()); @@ -271,7 +301,7 @@ fn primitive_array_to_flat_vector_cast( array: &dyn Array, out_vector: &mut dyn Vector, ) { - let array = arrow::compute::kernels::cast::cast(array, &data_type).unwrap(); + let array = cast(array, &data_type).unwrap_or_else(|_| panic!("array is casted into {data_type}")); let out_vector: &mut FlatVector = out_vector.as_mut_any().downcast_mut().unwrap(); out_vector.copy::(array.as_primitive::().values()); if let Some(nulls) = array.nulls() { @@ -348,16 +378,28 @@ fn primitive_array_to_vector(array: &dyn Array, out: &mut dyn Vector) -> Result< out.as_mut_any().downcast_mut().unwrap(), ); } - DataType::Decimal128(_, _) => { + DataType::Decimal128(width, _) => { decimal_array_to_vector( - array - .as_any() - .downcast_ref::() - .expect("Unable to downcast to BooleanArray"), + as_primitive_array(array), + out.as_mut_any().downcast_mut().unwrap(), + *width, + ); + } + DataType::Interval(_) | DataType::Duration(_) => { + let array = IntervalMonthDayNanoArray::from( + cast(array, &DataType::Interval(IntervalUnit::MonthDayNano)) + .expect("array is casted into IntervalMonthDayNanoArray") + .as_primitive::() + .values() + .iter() + .map(|a| IntervalMonthDayNanoType::make_value(a.months, a.days, a.nanoseconds / 1000)) + .collect::>(), + ); + primitive_array_to_flat_vector::( + as_primitive_array(&array), out.as_mut_any().downcast_mut().unwrap(), ); } - // DuckDB Only supports timetamp_tz in microsecond precision DataType::Timestamp(_, Some(tz)) => primitive_array_to_flat_vector_cast::( DataType::Timestamp(TimeUnit::Microsecond, Some(tz.clone())), @@ -401,10 +443,43 @@ fn primitive_array_to_vector(array: &dyn Array, out: &mut dyn Vector) -> Result< } /// Convert Arrow [Decimal128Array] to a duckdb vector. -fn decimal_array_to_vector(array: &Decimal128Array, out: &mut FlatVector) { - assert!(array.len() <= out.capacity()); - for i in 0..array.len() { - out.as_mut_slice()[i] = array.value_as_string(i).parse::().unwrap(); +fn decimal_array_to_vector(array: &Decimal128Array, out: &mut FlatVector, width: u8) { + match width { + 1..=4 => { + let out_data = out.as_mut_slice(); + for (i, value) in array.values().iter().enumerate() { + out_data[i] = value.to_i16().unwrap(); + } + } + 5..=9 => { + let out_data = out.as_mut_slice(); + for (i, value) in array.values().iter().enumerate() { + out_data[i] = value.to_i32().unwrap(); + } + } + 10..=18 => { + let out_data = out.as_mut_slice(); + for (i, value) in array.values().iter().enumerate() { + out_data[i] = value.to_i64().unwrap(); + } + } + 19..=38 => { + let out_data = out.as_mut_slice(); + for (i, value) in array.values().iter().enumerate() { + out_data[i] = value.to_i128().unwrap(); + } + } + // This should never happen, arrow only supports 1-38 decimal digits + _ => panic!("Invalid decimal width: {}", width), + } + + // Set nulls + if let Some(nulls) = array.nulls() { + for (i, null) in nulls.into_iter().enumerate() { + if !null { + out.set_null(i); + } + } } } @@ -417,7 +492,7 @@ fn boolean_array_to_vector(array: &BooleanArray, out: &mut FlatVector) { } } -fn string_array_to_vector(array: &StringArray, out: &mut FlatVector) { +fn string_array_to_vector(array: &GenericStringArray, out: &mut FlatVector) { assert!(array.len() <= out.capacity()); // TODO: zero copy assignment @@ -427,6 +502,37 @@ fn string_array_to_vector(array: &StringArray, out: &mut FlatVector) { } } +fn binary_array_to_vector(array: &BinaryArray, out: &mut FlatVector) { + assert!(array.len() <= out.capacity()); + + for i in 0..array.len() { + let s = array.value(i); + out.insert(i, s); + } +} + +fn fixed_size_binary_array_to_vector(array: &FixedSizeBinaryArray, out: &mut FlatVector) { + assert!(array.len() <= out.capacity()); + + for i in 0..array.len() { + let s = array.value(i); + out.insert(i, s); + } + // Put this back once the other PR # + // set_nulls_in_flat_vector(array, out); +} + +fn large_binary_array_to_vector(array: &LargeBinaryArray, out: &mut FlatVector) { + assert!(array.len() <= out.capacity()); + + for i in 0..array.len() { + let s = array.value(i); + out.insert(i, s); + } + // Put this back once the other PR # + // set_nulls_in_flat_vector(array, out); +} + fn list_array_to_vector>( array: &GenericListArray, out: &mut ListVector, @@ -440,6 +546,9 @@ fn list_array_to_vector>( DataType::Utf8 => { string_array_to_vector(as_string_array(value_array.as_ref()), &mut child); } + DataType::Binary => { + binary_array_to_vector(as_generic_binary_array(value_array.as_ref()), &mut child); + } _ => { return Err("Nested list is not supported yet.".into()); } @@ -455,33 +564,24 @@ fn list_array_to_vector>( fn fixed_size_list_array_to_vector( array: &FixedSizeListArray, - out: &mut ListVector, + out: &mut ArrayVector, ) -> Result<(), Box> { let value_array = array.values(); let mut child = out.child(value_array.len()); match value_array.data_type() { dt if dt.is_primitive() => { primitive_array_to_vector(value_array.as_ref(), &mut child)?; - for i in 0..array.len() { - let offset = array.value_offset(i); - let length = array.value_length(); - out.set_entry(i, offset as usize, length as usize); - } - out.set_len(value_array.len()); } DataType::Utf8 => { string_array_to_vector(as_string_array(value_array.as_ref()), &mut child); } + DataType::Binary => { + binary_array_to_vector(as_generic_binary_array(value_array.as_ref()), &mut child); + } _ => { - return Err("Nested list is not supported yet.".into()); + return Err("Nested array is not supported yet.".into()); } } - for i in 0..array.len() { - let offset = array.value_offset(i); - let length = array.value_length(); - out.set_entry(i, offset as usize, length as usize); - } - out.set_len(value_array.len()); Ok(()) } @@ -502,6 +602,9 @@ fn struct_array_to_vector(array: &StructArray, out: &mut StructVector) -> Result DataType::Utf8 => { string_array_to_vector(as_string_array(column.as_ref()), &mut out.child(i)); } + DataType::Binary => { + binary_array_to_vector(as_generic_binary_array(column.as_ref()), &mut out.child(i)); + } DataType::List(_) => { list_array_to_vector(as_list_array(column.as_ref()), &mut out.list_vector_child(i))?; } @@ -511,7 +614,7 @@ fn struct_array_to_vector(array: &StructArray, out: &mut StructVector) -> Result DataType::FixedSizeList(_, _) => { fixed_size_list_array_to_vector( as_fixed_size_list_array(column.as_ref()), - &mut out.list_vector_child(i), + &mut out.array_vector_child(i), )?; } DataType::Struct(_) => { @@ -569,13 +672,17 @@ mod test { use crate::{Connection, Result}; use arrow::{ array::{ - Array, ArrayRef, AsArray, Date32Array, Date64Array, Decimal256Array, Float64Array, GenericListArray, - Int32Array, ListArray, OffsetSizeTrait, PrimitiveArray, StringArray, StructArray, Time32SecondArray, - Time64MicrosecondArray, TimestampMicrosecondArray, TimestampMillisecondArray, TimestampNanosecondArray, - TimestampSecondArray, + Array, ArrayRef, AsArray, BinaryArray, Date32Array, Date64Array, Decimal128Array, Decimal256Array, + DurationSecondArray, FixedSizeListArray, GenericByteArray, GenericListArray, Int32Array, + IntervalDayTimeArray, IntervalMonthDayNanoArray, IntervalYearMonthArray, LargeStringArray, ListArray, + OffsetSizeTrait, PrimitiveArray, StringArray, StructArray, Time32SecondArray, Time64MicrosecondArray, + TimestampMicrosecondArray, TimestampMillisecondArray, TimestampNanosecondArray, TimestampSecondArray, }, buffer::{OffsetBuffer, ScalarBuffer}, - datatypes::{i256, ArrowPrimitiveType, DataType, Field, Fields, Schema}, + datatypes::{ + i256, ArrowPrimitiveType, ByteArrayType, DataType, DurationSecondType, Field, Fields, IntervalDayTimeType, + IntervalMonthDayNanoType, IntervalYearMonthType, Schema, + }, record_batch::RecordBatch, }; use std::{error::Error, sync::Arc}; @@ -594,9 +701,9 @@ mod test { let mut arr = stmt.query_arrow(param)?; let rb = arr.next().expect("no record batch"); assert_eq!(rb.num_columns(), 1); - let column = rb.column(0).as_any().downcast_ref::().unwrap(); + let column = rb.column(0).as_any().downcast_ref::().unwrap(); assert_eq!(column.len(), 1); - assert_eq!(column.value(0), 300.0); + assert_eq!(column.value(0), i128::from(30000)); Ok(()) } @@ -742,6 +849,48 @@ mod test { Ok(()) } + fn check_generic_byte_roundtrip( + arry_in: GenericByteArray, + arry_out: GenericByteArray, + ) -> Result<(), Box> + where + T1: ByteArrayType, + T2: ByteArrayType, + { + let db = Connection::open_in_memory()?; + db.register_table_function::("arrow")?; + + // Roundtrip a record batch from Rust to DuckDB and back to Rust + let schema = Schema::new(vec![Field::new("a", arry_in.data_type().clone(), false)]); + + let rb = RecordBatch::try_new(Arc::new(schema), vec![Arc::new(arry_in.clone())])?; + let param = arrow_recordbatch_to_query_params(rb); + let mut stmt = db.prepare("select a from arrow(?, ?)")?; + let rb = stmt.query_arrow(param)?.next().expect("no record batch"); + + let output_any_array = rb.column(0); + + assert!( + output_any_array.data_type().equals_datatype(arry_out.data_type()), + "{} != {}", + output_any_array.data_type(), + arry_out.data_type() + ); + + match output_any_array.as_bytes_opt::() { + Some(output_array) => { + assert_eq!(output_array.len(), arry_out.len()); + for i in 0..output_array.len() { + assert_eq!(output_array.is_valid(i), arry_out.is_valid(i)); + assert_eq!(output_array.value_data(), arry_out.value_data()) + } + } + None => panic!("Expected GenericByteArray"), + } + + Ok(()) + } + #[test] fn test_array_roundtrip() -> Result<(), Box> { check_generic_array_roundtrip(ListArray::new( @@ -760,6 +909,50 @@ mod test { Ok(()) } + //field: FieldRef, size: i32, values: ArrayRef, nulls: Option + #[test] + fn test_fixed_array_roundtrip() -> Result<(), Box> { + let array = FixedSizeListArray::new( + Arc::new(Field::new("item", DataType::Int32, true)), + 2, + Arc::new(Int32Array::from(vec![Some(1), Some(2), Some(3), Some(4), Some(5)])), + None, + ); + + let expected_output_array = array.clone(); + + let db = Connection::open_in_memory()?; + db.register_table_function::("arrow")?; + + // Roundtrip a record batch from Rust to DuckDB and back to Rust + let schema = Schema::new(vec![Field::new("a", array.data_type().clone(), false)]); + + let rb = RecordBatch::try_new(Arc::new(schema), vec![Arc::new(array.clone())])?; + let param = arrow_recordbatch_to_query_params(rb); + let mut stmt = db.prepare("select a from arrow(?, ?)")?; + let rb = stmt.query_arrow(param)?.next().expect("no record batch"); + + let output_any_array = rb.column(0); + assert!(output_any_array + .data_type() + .equals_datatype(expected_output_array.data_type())); + + match output_any_array.as_fixed_size_list_opt() { + Some(output_array) => { + assert_eq!(output_array.len(), expected_output_array.len()); + for i in 0..output_array.len() { + assert_eq!(output_array.is_valid(i), expected_output_array.is_valid(i)); + if output_array.is_valid(i) { + assert!(expected_output_array.value(i).eq(&output_array.value(i))); + } + } + } + None => panic!("Expected FixedSizeListArray"), + } + + Ok(()) + } + #[test] fn test_primitive_roundtrip_contains_nulls() -> Result<(), Box> { let mut builder = arrow::array::PrimitiveBuilder::::new(); @@ -776,6 +969,21 @@ mod test { Ok(()) } + #[test] + fn test_utf8_roundtrip() -> Result<(), Box> { + check_generic_byte_roundtrip( + StringArray::from(vec![Some("foo"), Some("Baz"), Some("bar")]), + StringArray::from(vec![Some("foo"), Some("Baz"), Some("bar")]), + )?; + + // [`LargeStringArray`] will be downcasted to [`StringArray`]. + check_generic_byte_roundtrip( + LargeStringArray::from(vec![Some("foo"), Some("Baz"), Some("bar")]), + StringArray::from(vec![Some("foo"), Some("Baz"), Some("bar")]), + )?; + Ok(()) + } + #[test] fn test_timestamp_roundtrip() -> Result<(), Box> { check_rust_primitive_array_roundtrip(Int32Array::from(vec![1, 2, 3]), Int32Array::from(vec![1, 2, 3]))?; @@ -840,6 +1048,68 @@ mod test { Ok(()) } + #[test] + fn test_decimal128_roundtrip() -> Result<(), Box> { + let array: PrimitiveArray = + Decimal128Array::from(vec![i128::from(1), i128::from(2), i128::from(3)]); + check_rust_primitive_array_roundtrip(array.clone(), array)?; + + // With width and scale + let array: PrimitiveArray = + Decimal128Array::from(vec![i128::from(12345)]).with_data_type(DataType::Decimal128(5, 2)); + check_rust_primitive_array_roundtrip(array.clone(), array)?; + Ok(()) + } + + #[test] + fn test_interval_roundtrip() -> Result<(), Box> { + let array: PrimitiveArray = IntervalMonthDayNanoArray::from(vec![ + IntervalMonthDayNanoType::make_value(1, 1, 1000), + IntervalMonthDayNanoType::make_value(2, 2, 2000), + IntervalMonthDayNanoType::make_value(3, 3, 3000), + ]); + check_rust_primitive_array_roundtrip(array.clone(), array)?; + + let array: PrimitiveArray = IntervalYearMonthArray::from(vec![ + IntervalYearMonthType::make_value(1, 10), + IntervalYearMonthType::make_value(2, 20), + IntervalYearMonthType::make_value(3, 30), + ]); + let expected_array: PrimitiveArray = IntervalMonthDayNanoArray::from(vec![ + IntervalMonthDayNanoType::make_value(22, 0, 0), + IntervalMonthDayNanoType::make_value(44, 0, 0), + IntervalMonthDayNanoType::make_value(66, 0, 0), + ]); + check_rust_primitive_array_roundtrip(array, expected_array)?; + + let array: PrimitiveArray = IntervalDayTimeArray::from(vec![ + IntervalDayTimeType::make_value(1, 1), + IntervalDayTimeType::make_value(2, 2), + IntervalDayTimeType::make_value(3, 3), + ]); + let expected_array: PrimitiveArray = IntervalMonthDayNanoArray::from(vec![ + IntervalMonthDayNanoType::make_value(0, 1, 1_000_000), + IntervalMonthDayNanoType::make_value(0, 2, 2_000_000), + IntervalMonthDayNanoType::make_value(0, 3, 3_000_000), + ]); + check_rust_primitive_array_roundtrip(array, expected_array)?; + + Ok(()) + } + + #[test] + fn test_duration_roundtrip() -> Result<(), Box> { + let array: PrimitiveArray = DurationSecondArray::from(vec![1, 2, 3]); + let expected_array: PrimitiveArray = IntervalMonthDayNanoArray::from(vec![ + IntervalMonthDayNanoType::make_value(0, 0, 1_000_000_000), + IntervalMonthDayNanoType::make_value(0, 0, 2_000_000_000), + IntervalMonthDayNanoType::make_value(0, 0, 3_000_000_000), + ]); + check_rust_primitive_array_roundtrip(array, expected_array)?; + + Ok(()) + } + #[test] fn test_timestamp_tz_insert() -> Result<(), Box> { // TODO: This test should be reworked once we support TIMESTAMP_TZ properly @@ -889,4 +1159,23 @@ mod test { ) ); } + + #[test] + fn test_arrow_binary() { + let byte_array = BinaryArray::from_iter_values([b"test"].iter()); + let arc: ArrayRef = Arc::new(byte_array); + let batch = RecordBatch::try_from_iter(vec![("x", arc)]).unwrap(); + + let db = Connection::open_in_memory().unwrap(); + db.register_table_function::("arrow").unwrap(); + + let mut stmt = db.prepare("SELECT * FROM arrow(?, ?)").unwrap(); + + let mut arr = stmt.query_arrow(arrow_recordbatch_to_query_params(batch)).unwrap(); + let rb = arr.next().expect("no record batch"); + + let column = rb.column(0).as_any().downcast_ref::().unwrap(); + assert_eq!(column.len(), 1); + assert_eq!(column.value(0), b"test"); + } } diff --git a/src/vtab/excel.rs b/crates/duckdb/src/vtab/excel.rs similarity index 92% rename from src/vtab/excel.rs rename to crates/duckdb/src/vtab/excel.rs index 355d9d30..b9bfad59 100644 --- a/src/vtab/excel.rs +++ b/crates/duckdb/src/vtab/excel.rs @@ -1,5 +1,5 @@ -use super::{BindInfo, DataChunk, Free, FunctionInfo, InitInfo, LogicalType, LogicalTypeId, VTab}; -use crate::vtab::vector::Inserter; +use super::{BindInfo, DataChunkHandle, Free, FunctionInfo, InitInfo, LogicalTypeHandle, LogicalTypeId, VTab}; +use crate::core::Inserter; use calamine::{open_workbook_auto, DataType, Range, Reader}; #[repr(C)] @@ -74,7 +74,7 @@ impl VTab for ExcelVTab { header[idx] .get_string() .unwrap_or_else(|| panic!("idx {} header empty?", idx)), - LogicalType::new(LogicalTypeId::Varchar), + LogicalTypeHandle::from(LogicalTypeId::Varchar), ); } DataType::Float(_) => { @@ -82,7 +82,7 @@ impl VTab for ExcelVTab { header[idx] .get_string() .unwrap_or_else(|| panic!("idx {} header empty?", idx)), - LogicalType::new(LogicalTypeId::Double), + LogicalTypeHandle::from(LogicalTypeId::Double), ); } DataType::Int(_) => { @@ -90,7 +90,7 @@ impl VTab for ExcelVTab { header[idx] .get_string() .unwrap_or_else(|| panic!("idx {} header empty?", idx)), - LogicalType::new(LogicalTypeId::Bigint), + LogicalTypeHandle::from(LogicalTypeId::Bigint), ); } DataType::Bool(_) => { @@ -98,7 +98,7 @@ impl VTab for ExcelVTab { header[idx] .get_string() .unwrap_or_else(|| panic!("idx {} header empty?", idx)), - LogicalType::new(LogicalTypeId::Boolean), + LogicalTypeHandle::from(LogicalTypeId::Boolean), ); } DataType::DateTime(_) => { @@ -106,7 +106,7 @@ impl VTab for ExcelVTab { header[idx] .get_string() .unwrap_or_else(|| panic!("idx {} header empty?", idx)), - LogicalType::new(LogicalTypeId::Date), + LogicalTypeHandle::from(LogicalTypeId::Date), ); } _ => { @@ -132,7 +132,7 @@ impl VTab for ExcelVTab { Ok(()) } - unsafe fn func(func: &FunctionInfo, output: &mut DataChunk) -> Result<(), Box> { + unsafe fn func(func: &FunctionInfo, output: &mut DataChunkHandle) -> Result<(), Box> { let init_info = func.get_init_data::(); let bind_info = func.get_bind_data::(); unsafe { @@ -180,10 +180,10 @@ impl VTab for ExcelVTab { Ok(()) } - fn parameters() -> Option> { + fn parameters() -> Option> { Some(vec![ - LogicalType::new(LogicalTypeId::Varchar), // file path - LogicalType::new(LogicalTypeId::Varchar), // sheet name + LogicalTypeHandle::from(LogicalTypeId::Varchar), // file path + LogicalTypeHandle::from(LogicalTypeId::Varchar), // sheet name ]) } } diff --git a/src/vtab/function.rs b/crates/duckdb/src/vtab/function.rs similarity index 98% rename from src/vtab/function.rs rename to crates/duckdb/src/vtab/function.rs index e3131d4c..9d14b510 100644 --- a/src/vtab/function.rs +++ b/crates/duckdb/src/vtab/function.rs @@ -9,7 +9,7 @@ use super::{ duckdb_table_function_set_init, duckdb_table_function_set_local_init, duckdb_table_function_set_name, duckdb_table_function_supports_projection_pushdown, idx_t, }, - LogicalType, Value, + LogicalTypeHandle, Value, }; use std::{ ffi::{c_void, CString}, @@ -19,7 +19,7 @@ use std::{ /// An interface to store and retrieve data during the function bind stage #[derive(Debug)] pub struct BindInfo { - ptr: *mut c_void, + ptr: duckdb_bind_info, } impl BindInfo { @@ -28,7 +28,7 @@ impl BindInfo { /// # Arguments /// * `name`: The name of the column /// * `type`: The logical type of the column - pub fn add_result_column(&self, column_name: &str, column_type: LogicalType) { + pub fn add_result_column(&self, column_name: &str, column_type: LogicalTypeHandle) { let c_str = CString::new(column_name).unwrap(); unsafe { duckdb_bind_add_result_column(self.ptr, c_str.as_ptr() as *const c_char, column_type.ptr); @@ -226,7 +226,7 @@ impl TableFunction { /// /// # Arguments /// * `logical_type`: The type of the parameter to add. - pub fn add_parameter(&self, logical_type: &LogicalType) -> &Self { + pub fn add_parameter(&self, logical_type: &LogicalTypeHandle) -> &Self { unsafe { duckdb_table_function_add_parameter(self.ptr, logical_type.ptr); } @@ -238,7 +238,7 @@ impl TableFunction { /// # Arguments /// * `name`: The name of the parameter to add. /// * `logical_type`: The type of the parameter to add. - pub fn add_named_parameter(&self, name: &str, logical_type: &LogicalType) -> &Self { + pub fn add_named_parameter(&self, name: &str, logical_type: &LogicalTypeHandle) -> &Self { unsafe { let string = CString::new(name).unwrap(); duckdb_table_function_add_named_parameter(self.ptr, string.as_ptr(), logical_type.ptr); @@ -264,7 +264,7 @@ impl TableFunction { /// /// # Arguments /// * `function`: The init function - pub fn set_init(&self, init_func: Option) -> &Self { + pub fn set_init(&self, init_func: Option) -> &Self { unsafe { duckdb_table_function_set_init(self.ptr, init_func); } @@ -275,7 +275,7 @@ impl TableFunction { /// /// # Arguments /// * `function`: The bind function - pub fn set_bind(&self, bind_func: Option) -> &Self { + pub fn set_bind(&self, bind_func: Option) -> &Self { unsafe { duckdb_table_function_set_bind(self.ptr, bind_func); } diff --git a/src/vtab/mod.rs b/crates/duckdb/src/vtab/mod.rs similarity index 91% rename from src/vtab/mod.rs rename to crates/duckdb/src/vtab/mod.rs index 40717819..9249fb1e 100644 --- a/src/vtab/mod.rs +++ b/crates/duckdb/src/vtab/mod.rs @@ -3,11 +3,8 @@ use crate::{error::Error, inner_connection::InnerConnection, Connection, Result} use super::{ffi, ffi::duckdb_free}; use std::ffi::c_void; -mod data_chunk; mod function; -mod logical_type; mod value; -mod vector; /// The duckdb Arrow table function interface #[cfg(feature = "vtab-arrow")] @@ -20,12 +17,10 @@ pub use self::arrow::{ #[cfg(feature = "vtab-excel")] mod excel; -pub use data_chunk::DataChunk; pub use function::{BindInfo, FunctionInfo, InitInfo, TableFunction}; -pub use logical_type::{LogicalType, LogicalTypeId}; pub use value::Value; -pub use vector::{FlatVector, Inserter, ListVector, StructVector, Vector}; +use crate::core::{DataChunkHandle, LogicalTypeHandle, LogicalTypeId}; use ffi::{duckdb_bind_info, duckdb_data_chunk, duckdb_function_info, duckdb_init_info}; use ffi::duckdb_malloc; @@ -105,7 +100,7 @@ pub trait VTab: Sized { /// - The `init_info` and `bind_info` data pointed to remains valid and is not freed until after this function completes. /// - No other threads are concurrently mutating the data pointed to by `init_info` and `bind_info` without proper synchronization. /// - The `output` parameter is correctly initialized and can safely be written to. - unsafe fn func(func: &FunctionInfo, output: &mut DataChunk) -> Result<(), Box>; + unsafe fn func(func: &FunctionInfo, output: &mut DataChunkHandle) -> Result<(), Box>; /// Does the table function support pushdown /// default is false fn supports_pushdown() -> bool { @@ -113,12 +108,12 @@ pub trait VTab: Sized { } /// The parameters of the table function /// default is None - fn parameters() -> Option> { + fn parameters() -> Option> { None } /// The named parameters of the table function /// default is None - fn named_parameters() -> Option> { + fn named_parameters() -> Option> { None } } @@ -128,8 +123,8 @@ where T: VTab, { let info = FunctionInfo::from(info); - let mut output = DataChunk::from(output); - let result = T::func(&info, &mut output); + let mut data_chunk_handle = DataChunkHandle::new_unowned(output); + let result = T::func(&info, &mut data_chunk_handle); if result.is_err() { info.set_error(&result.err().unwrap().to_string()); } @@ -198,6 +193,7 @@ impl InnerConnection { #[cfg(test)] mod test { use super::*; + use crate::core::Inserter; use std::{ error::Error, ffi::{c_char, CString}, @@ -233,7 +229,7 @@ mod test { type BindData = HelloBindData; unsafe fn bind(bind: &BindInfo, data: *mut HelloBindData) -> Result<(), Box> { - bind.add_result_column("column0", LogicalType::new(LogicalTypeId::Varchar)); + bind.add_result_column("column0", LogicalTypeHandle::from(LogicalTypeId::Varchar)); let param = bind.get_parameter(0).to_string(); unsafe { (*data).name = CString::new(param).unwrap().into_raw(); @@ -248,7 +244,7 @@ mod test { Ok(()) } - unsafe fn func(func: &FunctionInfo, output: &mut DataChunk) -> Result<(), Box> { + unsafe fn func(func: &FunctionInfo, output: &mut DataChunkHandle) -> Result<(), Box> { let init_info = func.get_init_data::(); let bind_info = func.get_bind_data::(); @@ -269,8 +265,8 @@ mod test { Ok(()) } - fn parameters() -> Option> { - Some(vec![LogicalType::new(LogicalTypeId::Varchar)]) + fn parameters() -> Option> { + Some(vec![LogicalTypeHandle::from(LogicalTypeId::Varchar)]) } } @@ -280,7 +276,7 @@ mod test { type BindData = HelloBindData; unsafe fn bind(bind: &BindInfo, data: *mut HelloBindData) -> Result<(), Box> { - bind.add_result_column("column0", LogicalType::new(LogicalTypeId::Varchar)); + bind.add_result_column("column0", LogicalTypeHandle::from(LogicalTypeId::Varchar)); let param = bind.get_named_parameter("name").unwrap().to_string(); assert!(bind.get_named_parameter("unknown_name").is_none()); unsafe { @@ -293,12 +289,15 @@ mod test { HelloVTab::init(init_info, data) } - unsafe fn func(func: &FunctionInfo, output: &mut DataChunk) -> Result<(), Box> { + unsafe fn func(func: &FunctionInfo, output: &mut DataChunkHandle) -> Result<(), Box> { HelloVTab::func(func, output) } - fn named_parameters() -> Option> { - Some(vec![("name".to_string(), LogicalType::new(LogicalTypeId::Varchar))]) + fn named_parameters() -> Option> { + Some(vec![( + "name".to_string(), + LogicalTypeHandle::from(LogicalTypeId::Varchar), + )]) } } diff --git a/src/vtab/value.rs b/crates/duckdb/src/vtab/value.rs similarity index 100% rename from src/vtab/value.rs rename to crates/duckdb/src/vtab/value.rs diff --git a/crates/libduckdb-sys/Cargo.toml b/crates/libduckdb-sys/Cargo.toml new file mode 100644 index 00000000..d02c0ea0 --- /dev/null +++ b/crates/libduckdb-sys/Cargo.toml @@ -0,0 +1,40 @@ +[package] +name = "libduckdb-sys" +version = "1.0.0" +authors.workspace = true +edition.workspace = true +license.workspace = true +repository.workspace = true +homepage.workspace = true +keywords.workspace = true +readme.workspace = true +build = "build.rs" +categories = ["external-ffi-bindings", "database"] +description = "Native bindings to the libduckdb library, C API" +exclude = ["duckdb-sources"] + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[features] +default = ["vcpkg", "pkg-config"] +bundled = ["cc"] +buildtime_bindgen = ["bindgen", "pkg-config", "vcpkg"] +json = ["bundled"] +parquet = ["bundled"] +extensions-full = ["json", "parquet"] + +[dependencies] + +[build-dependencies] +autocfg = { workspace = true } +bindgen = { workspace = true, features = ["runtime"], optional = true } +flate2 = { workspace = true } +pkg-config = { workspace = true, optional = true } +cc = { workspace = true, features = ["parallel"], optional = true } +vcpkg = { workspace = true, optional = true } +serde = { workspace = true, features = ["derive"] } +serde_json = { workspace = true } +tar = { workspace = true } + +[dev-dependencies] +arrow = { workspace = true, features = ["ffi"] } diff --git a/crates/libduckdb-sys/LICENSE b/crates/libduckdb-sys/LICENSE new file mode 120000 index 00000000..30cff740 --- /dev/null +++ b/crates/libduckdb-sys/LICENSE @@ -0,0 +1 @@ +../../LICENSE \ No newline at end of file diff --git a/crates/libduckdb-sys/README.md b/crates/libduckdb-sys/README.md new file mode 120000 index 00000000..fe840054 --- /dev/null +++ b/crates/libduckdb-sys/README.md @@ -0,0 +1 @@ +../../README.md \ No newline at end of file diff --git a/libduckdb-sys/bindgen.sh b/crates/libduckdb-sys/bindgen.sh similarity index 100% rename from libduckdb-sys/bindgen.sh rename to crates/libduckdb-sys/bindgen.sh diff --git a/libduckdb-sys/build.rs b/crates/libduckdb-sys/build.rs similarity index 93% rename from libduckdb-sys/build.rs rename to crates/libduckdb-sys/build.rs index 92031acb..8a279e27 100644 --- a/libduckdb-sys/build.rs +++ b/crates/libduckdb-sys/build.rs @@ -1,8 +1,5 @@ use std::{env, path::Path}; -#[cfg(feature = "httpfs")] -mod openssl; - /// Tells whether we're building for Windows. This is more suitable than a plain /// `cfg!(windows)`, since the latter does not properly handle cross-compilation /// @@ -75,19 +72,19 @@ mod build_bundled { ); } - fn untar_archive() { + fn untar_archive(out_dir: &str) { let path = "duckdb.tar.gz"; let tar_gz = std::fs::File::open(path).expect("archive file"); let tar = flate2::read::GzDecoder::new(tar_gz); let mut archive = tar::Archive::new(tar); - archive.unpack(".").expect("archive"); + archive.unpack(out_dir).expect("archive"); } pub fn main(out_dir: &str, out_path: &Path) { let lib_name = super::lib_name(); - untar_archive(); + untar_archive(out_dir); if !cfg!(feature = "bundled") { // This is just a sanity check, the top level `main` should ensure this. @@ -97,7 +94,7 @@ mod build_bundled { #[cfg(feature = "buildtime_bindgen")] { use super::{bindings, HeaderLocation}; - let header = HeaderLocation::FromPath(format!("{}/src/include/duckdb.h", lib_name)); + let header = HeaderLocation::FromPath(format!("{out_dir}/{lib_name}/src/include/duckdb.h")); bindings::write_to_out_dir(header, out_path); } #[cfg(not(feature = "buildtime_bindgen"))] @@ -106,7 +103,7 @@ mod build_bundled { fs::copy("src/bindgen_bundled_version.rs", out_path).expect("Could not copy bindings to output directory"); } - let manifest_file = std::fs::File::open(format!("{}/manifest.json", lib_name)).expect("manifest file"); + let manifest_file = std::fs::File::open(format!("{out_dir}/{lib_name}/manifest.json")).expect("manifest file"); let manifest: Manifest = serde_json::from_reader(manifest_file).expect("reading manifest file"); let mut cpp_files = HashSet::new(); @@ -120,14 +117,6 @@ mod build_bundled { let mut cfg = cc::Build::new(); - #[cfg(feature = "httpfs")] - { - if let Ok((_, openssl_include_dir)) = super::openssl::get_openssl_v2() { - cfg.include(openssl_include_dir); - } - add_extension(&mut cfg, &manifest, "httpfs", &mut cpp_files, &mut include_dirs); - } - #[cfg(feature = "parquet")] add_extension(&mut cfg, &manifest, "parquet", &mut cpp_files, &mut include_dirs); @@ -140,15 +129,14 @@ mod build_bundled { // Since the manifest controls the set of files, we require it to be changed to know whether // to rebuild the project - println!("cargo:rerun-if-changed={}/manifest.json", lib_name); + println!("cargo:rerun-if-changed={out_dir}/{lib_name}/manifest.json"); // Make sure to rebuild the project if tar file changed println!("cargo:rerun-if-changed=duckdb.tar.gz"); cfg.include(lib_name); + cfg.includes(include_dirs.iter().map(|dir| format!("{out_dir}/{lib_name}/{dir}"))); - cfg.includes(include_dirs.iter().map(|x| format!("{}/{}", lib_name, x))); - - for f in cpp_files { + for f in cpp_files.into_iter().map(|file| format!("{out_dir}/{file}")) { cfg.file(f); } @@ -163,8 +151,8 @@ mod build_bundled { if win_target() { cfg.define("DUCKDB_BUILD_LIBRARY", None); } - cfg.compile(lib_name); + println!("cargo:lib_dir={out_dir}"); } } diff --git a/crates/libduckdb-sys/duckdb.tar.gz b/crates/libduckdb-sys/duckdb.tar.gz new file mode 100644 index 00000000..b1b20a77 Binary files /dev/null and b/crates/libduckdb-sys/duckdb.tar.gz differ diff --git a/libduckdb-sys/openssl/cfgs.rs b/crates/libduckdb-sys/openssl/cfgs.rs similarity index 100% rename from libduckdb-sys/openssl/cfgs.rs rename to crates/libduckdb-sys/openssl/cfgs.rs diff --git a/libduckdb-sys/openssl/expando.c b/crates/libduckdb-sys/openssl/expando.c similarity index 100% rename from libduckdb-sys/openssl/expando.c rename to crates/libduckdb-sys/openssl/expando.c diff --git a/libduckdb-sys/openssl/find_normal.rs b/crates/libduckdb-sys/openssl/find_normal.rs similarity index 98% rename from libduckdb-sys/openssl/find_normal.rs rename to crates/libduckdb-sys/openssl/find_normal.rs index 4655a8af..591857dd 100644 --- a/libduckdb-sys/openssl/find_normal.rs +++ b/crates/libduckdb-sys/openssl/find_normal.rs @@ -141,7 +141,7 @@ openssl-sys = {} openssl-sys crate build failed: no supported version of OpenSSL found. Ways to fix it: -- Use the `vendored` feature of openssl-sys crate to build OpenSSL from source. +- Use the `openssl_vendored` feature of libduckdb-sys crate to build OpenSSL from source. - Use Homebrew to install the `openssl` package. ", diff --git a/libduckdb-sys/openssl/find_vendored.rs b/crates/libduckdb-sys/openssl/find_vendored.rs similarity index 86% rename from libduckdb-sys/openssl/find_vendored.rs rename to crates/libduckdb-sys/openssl/find_vendored.rs index 2ab44cfa..82348b6e 100644 --- a/libduckdb-sys/openssl/find_vendored.rs +++ b/crates/libduckdb-sys/openssl/find_vendored.rs @@ -1,9 +1,8 @@ -use openssl_src; use std::path::PathBuf; pub fn get_openssl(_target: &str) -> (Vec, PathBuf) { let artifacts = openssl_src::Build::new().build(); - println!("cargo:vendored=1"); + println!("cargo:openssl_vendored=1"); println!("cargo:root={}", artifacts.lib_dir().parent().unwrap().display()); ( diff --git a/libduckdb-sys/openssl/mod.rs b/crates/libduckdb-sys/openssl/mod.rs similarity index 99% rename from libduckdb-sys/openssl/mod.rs rename to crates/libduckdb-sys/openssl/mod.rs index a7bf791c..4877258a 100644 --- a/libduckdb-sys/openssl/mod.rs +++ b/crates/libduckdb-sys/openssl/mod.rs @@ -22,7 +22,7 @@ extern crate autocfg; #[cfg(feature = "openssl_bindgen")] extern crate bindgen; extern crate cc; -#[cfg(feature = "vendored")] +#[cfg(feature = "openssl_vendored")] extern crate openssl_src; extern crate pkg_config; #[cfg(target_env = "msvc")] @@ -37,7 +37,7 @@ use std::{ mod cfgs; mod find_normal; -#[cfg(feature = "vendored")] +#[cfg(feature = "openssl_vendored")] mod find_vendored; #[cfg(feature = "openssl_bindgen")] mod run_bindgen; @@ -69,7 +69,7 @@ fn env(name: &str) -> Option { } fn find_openssl(target: &str) -> Result<(Vec, PathBuf), ()> { - #[cfg(feature = "vendored")] + #[cfg(feature = "openssl_vendored")] { // vendor if the feature is present, unless // OPENSSL_NO_VENDOR exists and isn't `0` @@ -183,7 +183,7 @@ fn postprocess(include_dirs: &[PathBuf]) -> Version { } } #[cfg(feature = "openssl_bindgen")] - run_bindgen::run(&include_dirs); + run_bindgen::run(include_dirs); version } diff --git a/libduckdb-sys/openssl/run_bindgen.rs b/crates/libduckdb-sys/openssl/run_bindgen.rs similarity index 100% rename from libduckdb-sys/openssl/run_bindgen.rs rename to crates/libduckdb-sys/openssl/run_bindgen.rs diff --git a/crates/libduckdb-sys/src/bindgen_bundled_version.rs b/crates/libduckdb-sys/src/bindgen_bundled_version.rs new file mode 100644 index 00000000..1449f079 --- /dev/null +++ b/crates/libduckdb-sys/src/bindgen_bundled_version.rs @@ -0,0 +1,3 @@ +/* automatically generated by rust-bindgen 0.69.4 */ + +pub const DUCKDB_API_0_3_1 : u32 = 1 ; pub const DUCKDB_API_0_3_2 : u32 = 2 ; pub const DUCKDB_API_LATEST : u32 = 2 ; pub const DUCKDB_API_VERSION : u32 = 2 ; pub const __bool_true_false_are_defined : u32 = 1 ; pub const true_ : u32 = 1 ; pub const false_ : u32 = 0 ; pub const _STDINT_H : u32 = 1 ; pub const _FEATURES_H : u32 = 1 ; pub const _DEFAULT_SOURCE : u32 = 1 ; pub const __GLIBC_USE_ISOC2X : u32 = 0 ; pub const __USE_ISOC11 : u32 = 1 ; pub const __USE_ISOC99 : u32 = 1 ; pub const __USE_ISOC95 : u32 = 1 ; pub const __USE_POSIX_IMPLICITLY : u32 = 1 ; pub const _POSIX_SOURCE : u32 = 1 ; pub const _POSIX_C_SOURCE : u32 = 200809 ; pub const __USE_POSIX : u32 = 1 ; pub const __USE_POSIX2 : u32 = 1 ; pub const __USE_POSIX199309 : u32 = 1 ; pub const __USE_POSIX199506 : u32 = 1 ; pub const __USE_XOPEN2K : u32 = 1 ; pub const __USE_XOPEN2K8 : u32 = 1 ; pub const _ATFILE_SOURCE : u32 = 1 ; pub const __WORDSIZE : u32 = 64 ; pub const __WORDSIZE_TIME64_COMPAT32 : u32 = 0 ; pub const __TIMESIZE : u32 = 64 ; pub const __USE_MISC : u32 = 1 ; pub const __USE_ATFILE : u32 = 1 ; pub const __USE_FORTIFY_LEVEL : u32 = 0 ; pub const __GLIBC_USE_DEPRECATED_GETS : u32 = 0 ; pub const __GLIBC_USE_DEPRECATED_SCANF : u32 = 0 ; pub const __GLIBC_USE_C2X_STRTOL : u32 = 0 ; pub const _STDC_PREDEF_H : u32 = 1 ; pub const __STDC_IEC_559__ : u32 = 1 ; pub const __STDC_IEC_60559_BFP__ : u32 = 201404 ; pub const __STDC_IEC_559_COMPLEX__ : u32 = 1 ; pub const __STDC_IEC_60559_COMPLEX__ : u32 = 201404 ; pub const __STDC_ISO_10646__ : u32 = 201706 ; pub const __GNU_LIBRARY__ : u32 = 6 ; pub const __GLIBC__ : u32 = 2 ; pub const __GLIBC_MINOR__ : u32 = 39 ; pub const _SYS_CDEFS_H : u32 = 1 ; pub const __glibc_c99_flexarr_available : u32 = 1 ; pub const __LDOUBLE_REDIRECTS_TO_FLOAT128_ABI : u32 = 0 ; pub const __HAVE_GENERIC_SELECTION : u32 = 1 ; pub const __GLIBC_USE_LIB_EXT2 : u32 = 0 ; pub const __GLIBC_USE_IEC_60559_BFP_EXT : u32 = 0 ; pub const __GLIBC_USE_IEC_60559_BFP_EXT_C2X : u32 = 0 ; pub const __GLIBC_USE_IEC_60559_EXT : u32 = 0 ; pub const __GLIBC_USE_IEC_60559_FUNCS_EXT : u32 = 0 ; pub const __GLIBC_USE_IEC_60559_FUNCS_EXT_C2X : u32 = 0 ; pub const __GLIBC_USE_IEC_60559_TYPES_EXT : u32 = 0 ; pub const _BITS_TYPES_H : u32 = 1 ; pub const _BITS_TYPESIZES_H : u32 = 1 ; pub const __OFF_T_MATCHES_OFF64_T : u32 = 1 ; pub const __INO_T_MATCHES_INO64_T : u32 = 1 ; pub const __RLIM_T_MATCHES_RLIM64_T : u32 = 1 ; pub const __STATFS_MATCHES_STATFS64 : u32 = 1 ; pub const __FD_SETSIZE : u32 = 1024 ; pub const _BITS_TIME64_H : u32 = 1 ; pub const _BITS_WCHAR_H : u32 = 1 ; pub const _BITS_STDINT_INTN_H : u32 = 1 ; pub const _BITS_STDINT_UINTN_H : u32 = 1 ; pub const _BITS_STDINT_LEAST_H : u32 = 1 ; pub const INT8_MIN : i32 = - 128 ; pub const INT16_MIN : i32 = - 32768 ; pub const INT32_MIN : i32 = - 2147483648 ; pub const INT8_MAX : u32 = 127 ; pub const INT16_MAX : u32 = 32767 ; pub const INT32_MAX : u32 = 2147483647 ; pub const UINT8_MAX : u32 = 255 ; pub const UINT16_MAX : u32 = 65535 ; pub const UINT32_MAX : u32 = 4294967295 ; pub const INT_LEAST8_MIN : i32 = - 128 ; pub const INT_LEAST16_MIN : i32 = - 32768 ; pub const INT_LEAST32_MIN : i32 = - 2147483648 ; pub const INT_LEAST8_MAX : u32 = 127 ; pub const INT_LEAST16_MAX : u32 = 32767 ; pub const INT_LEAST32_MAX : u32 = 2147483647 ; pub const UINT_LEAST8_MAX : u32 = 255 ; pub const UINT_LEAST16_MAX : u32 = 65535 ; pub const UINT_LEAST32_MAX : u32 = 4294967295 ; pub const INT_FAST8_MIN : i32 = - 128 ; pub const INT_FAST16_MIN : i64 = - 9223372036854775808 ; pub const INT_FAST32_MIN : i64 = - 9223372036854775808 ; pub const INT_FAST8_MAX : u32 = 127 ; pub const INT_FAST16_MAX : u64 = 9223372036854775807 ; pub const INT_FAST32_MAX : u64 = 9223372036854775807 ; pub const UINT_FAST8_MAX : u32 = 255 ; pub const UINT_FAST16_MAX : i32 = - 1 ; pub const UINT_FAST32_MAX : i32 = - 1 ; pub const INTPTR_MIN : i64 = - 9223372036854775808 ; pub const INTPTR_MAX : u64 = 9223372036854775807 ; pub const UINTPTR_MAX : i32 = - 1 ; pub const PTRDIFF_MIN : i64 = - 9223372036854775808 ; pub const PTRDIFF_MAX : u64 = 9223372036854775807 ; pub const SIG_ATOMIC_MIN : i32 = - 2147483648 ; pub const SIG_ATOMIC_MAX : u32 = 2147483647 ; pub const SIZE_MAX : i32 = - 1 ; pub const WINT_MIN : u32 = 0 ; pub const WINT_MAX : u32 = 4294967295 ; pub type __u_char = :: std :: os :: raw :: c_uchar ; pub type __u_short = :: std :: os :: raw :: c_ushort ; pub type __u_int = :: std :: os :: raw :: c_uint ; pub type __u_long = :: std :: os :: raw :: c_ulong ; pub type __int8_t = :: std :: os :: raw :: c_schar ; pub type __uint8_t = :: std :: os :: raw :: c_uchar ; pub type __int16_t = :: std :: os :: raw :: c_short ; pub type __uint16_t = :: std :: os :: raw :: c_ushort ; pub type __int32_t = :: std :: os :: raw :: c_int ; pub type __uint32_t = :: std :: os :: raw :: c_uint ; pub type __int64_t = :: std :: os :: raw :: c_long ; pub type __uint64_t = :: std :: os :: raw :: c_ulong ; pub type __int_least8_t = __int8_t ; pub type __uint_least8_t = __uint8_t ; pub type __int_least16_t = __int16_t ; pub type __uint_least16_t = __uint16_t ; pub type __int_least32_t = __int32_t ; pub type __uint_least32_t = __uint32_t ; pub type __int_least64_t = __int64_t ; pub type __uint_least64_t = __uint64_t ; pub type __quad_t = :: std :: os :: raw :: c_long ; pub type __u_quad_t = :: std :: os :: raw :: c_ulong ; pub type __intmax_t = :: std :: os :: raw :: c_long ; pub type __uintmax_t = :: std :: os :: raw :: c_ulong ; pub type __dev_t = :: std :: os :: raw :: c_ulong ; pub type __uid_t = :: std :: os :: raw :: c_uint ; pub type __gid_t = :: std :: os :: raw :: c_uint ; pub type __ino_t = :: std :: os :: raw :: c_ulong ; pub type __ino64_t = :: std :: os :: raw :: c_ulong ; pub type __mode_t = :: std :: os :: raw :: c_uint ; pub type __nlink_t = :: std :: os :: raw :: c_uint ; pub type __off_t = :: std :: os :: raw :: c_long ; pub type __off64_t = :: std :: os :: raw :: c_long ; pub type __pid_t = :: std :: os :: raw :: c_int ; # [repr (C)] # [derive (Debug , Copy , Clone)] pub struct __fsid_t { pub __val : [:: std :: os :: raw :: c_int ; 2usize] , } # [test] fn bindgen_test_layout___fsid_t () { const UNINIT : :: std :: mem :: MaybeUninit < __fsid_t > = :: std :: mem :: MaybeUninit :: uninit () ; let ptr = UNINIT . as_ptr () ; assert_eq ! (:: std :: mem :: size_of :: < __fsid_t > () , 8usize , concat ! ("Size of: " , stringify ! (__fsid_t))) ; assert_eq ! (:: std :: mem :: align_of :: < __fsid_t > () , 4usize , concat ! ("Alignment of " , stringify ! (__fsid_t))) ; assert_eq ! (unsafe { :: std :: ptr :: addr_of ! ((* ptr) . __val) as usize - ptr as usize } , 0usize , concat ! ("Offset of field: " , stringify ! (__fsid_t) , "::" , stringify ! (__val))) ; } pub type __clock_t = :: std :: os :: raw :: c_long ; pub type __rlim_t = :: std :: os :: raw :: c_ulong ; pub type __rlim64_t = :: std :: os :: raw :: c_ulong ; pub type __id_t = :: std :: os :: raw :: c_uint ; pub type __time_t = :: std :: os :: raw :: c_long ; pub type __useconds_t = :: std :: os :: raw :: c_uint ; pub type __suseconds_t = :: std :: os :: raw :: c_long ; pub type __suseconds64_t = :: std :: os :: raw :: c_long ; pub type __daddr_t = :: std :: os :: raw :: c_int ; pub type __key_t = :: std :: os :: raw :: c_int ; pub type __clockid_t = :: std :: os :: raw :: c_int ; pub type __timer_t = * mut :: std :: os :: raw :: c_void ; pub type __blksize_t = :: std :: os :: raw :: c_int ; pub type __blkcnt_t = :: std :: os :: raw :: c_long ; pub type __blkcnt64_t = :: std :: os :: raw :: c_long ; pub type __fsblkcnt_t = :: std :: os :: raw :: c_ulong ; pub type __fsblkcnt64_t = :: std :: os :: raw :: c_ulong ; pub type __fsfilcnt_t = :: std :: os :: raw :: c_ulong ; pub type __fsfilcnt64_t = :: std :: os :: raw :: c_ulong ; pub type __fsword_t = :: std :: os :: raw :: c_long ; pub type __ssize_t = :: std :: os :: raw :: c_long ; pub type __syscall_slong_t = :: std :: os :: raw :: c_long ; pub type __syscall_ulong_t = :: std :: os :: raw :: c_ulong ; pub type __loff_t = __off64_t ; pub type __caddr_t = * mut :: std :: os :: raw :: c_char ; pub type __intptr_t = :: std :: os :: raw :: c_long ; pub type __socklen_t = :: std :: os :: raw :: c_uint ; pub type __sig_atomic_t = :: std :: os :: raw :: c_int ; pub type int_least8_t = __int_least8_t ; pub type int_least16_t = __int_least16_t ; pub type int_least32_t = __int_least32_t ; pub type int_least64_t = __int_least64_t ; pub type uint_least8_t = __uint_least8_t ; pub type uint_least16_t = __uint_least16_t ; pub type uint_least32_t = __uint_least32_t ; pub type uint_least64_t = __uint_least64_t ; pub type int_fast8_t = :: std :: os :: raw :: c_schar ; pub type int_fast16_t = :: std :: os :: raw :: c_long ; pub type int_fast32_t = :: std :: os :: raw :: c_long ; pub type int_fast64_t = :: std :: os :: raw :: c_long ; pub type uint_fast8_t = :: std :: os :: raw :: c_uchar ; pub type uint_fast16_t = :: std :: os :: raw :: c_ulong ; pub type uint_fast32_t = :: std :: os :: raw :: c_ulong ; pub type uint_fast64_t = :: std :: os :: raw :: c_ulong ; pub type intmax_t = __intmax_t ; pub type uintmax_t = __uintmax_t ; pub type wchar_t = :: std :: os :: raw :: c_uint ; # [repr (C)] # [repr (align (16))] # [derive (Debug , Copy , Clone)] pub struct max_align_t { pub __clang_max_align_nonce1 : :: std :: os :: raw :: c_longlong , pub __bindgen_padding_0 : u64 , pub __clang_max_align_nonce2 : u128 , } # [test] fn bindgen_test_layout_max_align_t () { const UNINIT : :: std :: mem :: MaybeUninit < max_align_t > = :: std :: mem :: MaybeUninit :: uninit () ; let ptr = UNINIT . as_ptr () ; assert_eq ! (:: std :: mem :: size_of :: < max_align_t > () , 32usize , concat ! ("Size of: " , stringify ! (max_align_t))) ; assert_eq ! (:: std :: mem :: align_of :: < max_align_t > () , 16usize , concat ! ("Alignment of " , stringify ! (max_align_t))) ; assert_eq ! (unsafe { :: std :: ptr :: addr_of ! ((* ptr) . __clang_max_align_nonce1) as usize - ptr as usize } , 0usize , concat ! ("Offset of field: " , stringify ! (max_align_t) , "::" , stringify ! (__clang_max_align_nonce1))) ; assert_eq ! (unsafe { :: std :: ptr :: addr_of ! ((* ptr) . __clang_max_align_nonce2) as usize - ptr as usize } , 16usize , concat ! ("Offset of field: " , stringify ! (max_align_t) , "::" , stringify ! (__clang_max_align_nonce2))) ; } pub const DUCKDB_TYPE_DUCKDB_TYPE_INVALID : DUCKDB_TYPE = 0 ; pub const DUCKDB_TYPE_DUCKDB_TYPE_BOOLEAN : DUCKDB_TYPE = 1 ; pub const DUCKDB_TYPE_DUCKDB_TYPE_TINYINT : DUCKDB_TYPE = 2 ; pub const DUCKDB_TYPE_DUCKDB_TYPE_SMALLINT : DUCKDB_TYPE = 3 ; pub const DUCKDB_TYPE_DUCKDB_TYPE_INTEGER : DUCKDB_TYPE = 4 ; pub const DUCKDB_TYPE_DUCKDB_TYPE_BIGINT : DUCKDB_TYPE = 5 ; pub const DUCKDB_TYPE_DUCKDB_TYPE_UTINYINT : DUCKDB_TYPE = 6 ; pub const DUCKDB_TYPE_DUCKDB_TYPE_USMALLINT : DUCKDB_TYPE = 7 ; pub const DUCKDB_TYPE_DUCKDB_TYPE_UINTEGER : DUCKDB_TYPE = 8 ; pub const DUCKDB_TYPE_DUCKDB_TYPE_UBIGINT : DUCKDB_TYPE = 9 ; pub const DUCKDB_TYPE_DUCKDB_TYPE_FLOAT : DUCKDB_TYPE = 10 ; pub const DUCKDB_TYPE_DUCKDB_TYPE_DOUBLE : DUCKDB_TYPE = 11 ; pub const DUCKDB_TYPE_DUCKDB_TYPE_TIMESTAMP : DUCKDB_TYPE = 12 ; pub const DUCKDB_TYPE_DUCKDB_TYPE_DATE : DUCKDB_TYPE = 13 ; pub const DUCKDB_TYPE_DUCKDB_TYPE_TIME : DUCKDB_TYPE = 14 ; pub const DUCKDB_TYPE_DUCKDB_TYPE_INTERVAL : DUCKDB_TYPE = 15 ; pub const DUCKDB_TYPE_DUCKDB_TYPE_HUGEINT : DUCKDB_TYPE = 16 ; pub const DUCKDB_TYPE_DUCKDB_TYPE_UHUGEINT : DUCKDB_TYPE = 32 ; pub const DUCKDB_TYPE_DUCKDB_TYPE_VARCHAR : DUCKDB_TYPE = 17 ; pub const DUCKDB_TYPE_DUCKDB_TYPE_BLOB : DUCKDB_TYPE = 18 ; pub const DUCKDB_TYPE_DUCKDB_TYPE_DECIMAL : DUCKDB_TYPE = 19 ; pub const DUCKDB_TYPE_DUCKDB_TYPE_TIMESTAMP_S : DUCKDB_TYPE = 20 ; pub const DUCKDB_TYPE_DUCKDB_TYPE_TIMESTAMP_MS : DUCKDB_TYPE = 21 ; pub const DUCKDB_TYPE_DUCKDB_TYPE_TIMESTAMP_NS : DUCKDB_TYPE = 22 ; pub const DUCKDB_TYPE_DUCKDB_TYPE_ENUM : DUCKDB_TYPE = 23 ; pub const DUCKDB_TYPE_DUCKDB_TYPE_LIST : DUCKDB_TYPE = 24 ; pub const DUCKDB_TYPE_DUCKDB_TYPE_STRUCT : DUCKDB_TYPE = 25 ; pub const DUCKDB_TYPE_DUCKDB_TYPE_MAP : DUCKDB_TYPE = 26 ; pub const DUCKDB_TYPE_DUCKDB_TYPE_ARRAY : DUCKDB_TYPE = 33 ; pub const DUCKDB_TYPE_DUCKDB_TYPE_UUID : DUCKDB_TYPE = 27 ; pub const DUCKDB_TYPE_DUCKDB_TYPE_UNION : DUCKDB_TYPE = 28 ; pub const DUCKDB_TYPE_DUCKDB_TYPE_BIT : DUCKDB_TYPE = 29 ; pub const DUCKDB_TYPE_DUCKDB_TYPE_TIME_TZ : DUCKDB_TYPE = 30 ; pub const DUCKDB_TYPE_DUCKDB_TYPE_TIMESTAMP_TZ : DUCKDB_TYPE = 31 ; # [doc = "! An enum over DuckDB's internal types."] pub type DUCKDB_TYPE = :: std :: os :: raw :: c_uint ; # [doc = "! An enum over DuckDB's internal types."] pub use self :: DUCKDB_TYPE as duckdb_type ; pub const duckdb_state_DuckDBSuccess : duckdb_state = 0 ; pub const duckdb_state_DuckDBError : duckdb_state = 1 ; # [doc = "! An enum over the returned state of different functions."] pub type duckdb_state = :: std :: os :: raw :: c_uint ; pub const duckdb_pending_state_DUCKDB_PENDING_RESULT_READY : duckdb_pending_state = 0 ; pub const duckdb_pending_state_DUCKDB_PENDING_RESULT_NOT_READY : duckdb_pending_state = 1 ; pub const duckdb_pending_state_DUCKDB_PENDING_ERROR : duckdb_pending_state = 2 ; pub const duckdb_pending_state_DUCKDB_PENDING_NO_TASKS_AVAILABLE : duckdb_pending_state = 3 ; # [doc = "! An enum over the pending state of a pending query result."] pub type duckdb_pending_state = :: std :: os :: raw :: c_uint ; pub const duckdb_result_type_DUCKDB_RESULT_TYPE_INVALID : duckdb_result_type = 0 ; pub const duckdb_result_type_DUCKDB_RESULT_TYPE_CHANGED_ROWS : duckdb_result_type = 1 ; pub const duckdb_result_type_DUCKDB_RESULT_TYPE_NOTHING : duckdb_result_type = 2 ; pub const duckdb_result_type_DUCKDB_RESULT_TYPE_QUERY_RESULT : duckdb_result_type = 3 ; # [doc = "! An enum over DuckDB's different result types."] pub type duckdb_result_type = :: std :: os :: raw :: c_uint ; pub const duckdb_statement_type_DUCKDB_STATEMENT_TYPE_INVALID : duckdb_statement_type = 0 ; pub const duckdb_statement_type_DUCKDB_STATEMENT_TYPE_SELECT : duckdb_statement_type = 1 ; pub const duckdb_statement_type_DUCKDB_STATEMENT_TYPE_INSERT : duckdb_statement_type = 2 ; pub const duckdb_statement_type_DUCKDB_STATEMENT_TYPE_UPDATE : duckdb_statement_type = 3 ; pub const duckdb_statement_type_DUCKDB_STATEMENT_TYPE_EXPLAIN : duckdb_statement_type = 4 ; pub const duckdb_statement_type_DUCKDB_STATEMENT_TYPE_DELETE : duckdb_statement_type = 5 ; pub const duckdb_statement_type_DUCKDB_STATEMENT_TYPE_PREPARE : duckdb_statement_type = 6 ; pub const duckdb_statement_type_DUCKDB_STATEMENT_TYPE_CREATE : duckdb_statement_type = 7 ; pub const duckdb_statement_type_DUCKDB_STATEMENT_TYPE_EXECUTE : duckdb_statement_type = 8 ; pub const duckdb_statement_type_DUCKDB_STATEMENT_TYPE_ALTER : duckdb_statement_type = 9 ; pub const duckdb_statement_type_DUCKDB_STATEMENT_TYPE_TRANSACTION : duckdb_statement_type = 10 ; pub const duckdb_statement_type_DUCKDB_STATEMENT_TYPE_COPY : duckdb_statement_type = 11 ; pub const duckdb_statement_type_DUCKDB_STATEMENT_TYPE_ANALYZE : duckdb_statement_type = 12 ; pub const duckdb_statement_type_DUCKDB_STATEMENT_TYPE_VARIABLE_SET : duckdb_statement_type = 13 ; pub const duckdb_statement_type_DUCKDB_STATEMENT_TYPE_CREATE_FUNC : duckdb_statement_type = 14 ; pub const duckdb_statement_type_DUCKDB_STATEMENT_TYPE_DROP : duckdb_statement_type = 15 ; pub const duckdb_statement_type_DUCKDB_STATEMENT_TYPE_EXPORT : duckdb_statement_type = 16 ; pub const duckdb_statement_type_DUCKDB_STATEMENT_TYPE_PRAGMA : duckdb_statement_type = 17 ; pub const duckdb_statement_type_DUCKDB_STATEMENT_TYPE_VACUUM : duckdb_statement_type = 18 ; pub const duckdb_statement_type_DUCKDB_STATEMENT_TYPE_CALL : duckdb_statement_type = 19 ; pub const duckdb_statement_type_DUCKDB_STATEMENT_TYPE_SET : duckdb_statement_type = 20 ; pub const duckdb_statement_type_DUCKDB_STATEMENT_TYPE_LOAD : duckdb_statement_type = 21 ; pub const duckdb_statement_type_DUCKDB_STATEMENT_TYPE_RELATION : duckdb_statement_type = 22 ; pub const duckdb_statement_type_DUCKDB_STATEMENT_TYPE_EXTENSION : duckdb_statement_type = 23 ; pub const duckdb_statement_type_DUCKDB_STATEMENT_TYPE_LOGICAL_PLAN : duckdb_statement_type = 24 ; pub const duckdb_statement_type_DUCKDB_STATEMENT_TYPE_ATTACH : duckdb_statement_type = 25 ; pub const duckdb_statement_type_DUCKDB_STATEMENT_TYPE_DETACH : duckdb_statement_type = 26 ; pub const duckdb_statement_type_DUCKDB_STATEMENT_TYPE_MULTI : duckdb_statement_type = 27 ; # [doc = "! An enum over DuckDB's different statement types."] pub type duckdb_statement_type = :: std :: os :: raw :: c_uint ; # [doc = "! DuckDB's index type."] pub type idx_t = u64 ; # [doc = "! The callback that will be called to destroy data, e.g.,\n! bind data (if any), init data (if any), extra data for replacement scans (if any)"] pub type duckdb_delete_callback_t = :: std :: option :: Option < unsafe extern "C" fn (data : * mut :: std :: os :: raw :: c_void) > ; # [doc = "! Used for threading, contains a task state. Must be destroyed with `duckdb_destroy_state`."] pub type duckdb_task_state = * mut :: std :: os :: raw :: c_void ; # [doc = "! Days are stored as days since 1970-01-01\n! Use the duckdb_from_date/duckdb_to_date function to extract individual information"] # [repr (C)] # [derive (Debug , Copy , Clone)] pub struct duckdb_date { pub days : i32 , } # [test] fn bindgen_test_layout_duckdb_date () { const UNINIT : :: std :: mem :: MaybeUninit < duckdb_date > = :: std :: mem :: MaybeUninit :: uninit () ; let ptr = UNINIT . as_ptr () ; assert_eq ! (:: std :: mem :: size_of :: < duckdb_date > () , 4usize , concat ! ("Size of: " , stringify ! (duckdb_date))) ; assert_eq ! (:: std :: mem :: align_of :: < duckdb_date > () , 4usize , concat ! ("Alignment of " , stringify ! (duckdb_date))) ; assert_eq ! (unsafe { :: std :: ptr :: addr_of ! ((* ptr) . days) as usize - ptr as usize } , 0usize , concat ! ("Offset of field: " , stringify ! (duckdb_date) , "::" , stringify ! (days))) ; } # [repr (C)] # [derive (Debug , Copy , Clone)] pub struct duckdb_date_struct { pub year : i32 , pub month : i8 , pub day : i8 , } # [test] fn bindgen_test_layout_duckdb_date_struct () { const UNINIT : :: std :: mem :: MaybeUninit < duckdb_date_struct > = :: std :: mem :: MaybeUninit :: uninit () ; let ptr = UNINIT . as_ptr () ; assert_eq ! (:: std :: mem :: size_of :: < duckdb_date_struct > () , 8usize , concat ! ("Size of: " , stringify ! (duckdb_date_struct))) ; assert_eq ! (:: std :: mem :: align_of :: < duckdb_date_struct > () , 4usize , concat ! ("Alignment of " , stringify ! (duckdb_date_struct))) ; assert_eq ! (unsafe { :: std :: ptr :: addr_of ! ((* ptr) . year) as usize - ptr as usize } , 0usize , concat ! ("Offset of field: " , stringify ! (duckdb_date_struct) , "::" , stringify ! (year))) ; assert_eq ! (unsafe { :: std :: ptr :: addr_of ! ((* ptr) . month) as usize - ptr as usize } , 4usize , concat ! ("Offset of field: " , stringify ! (duckdb_date_struct) , "::" , stringify ! (month))) ; assert_eq ! (unsafe { :: std :: ptr :: addr_of ! ((* ptr) . day) as usize - ptr as usize } , 5usize , concat ! ("Offset of field: " , stringify ! (duckdb_date_struct) , "::" , stringify ! (day))) ; } # [doc = "! Time is stored as microseconds since 00:00:00\n! Use the duckdb_from_time/duckdb_to_time function to extract individual information"] # [repr (C)] # [derive (Debug , Copy , Clone)] pub struct duckdb_time { pub micros : i64 , } # [test] fn bindgen_test_layout_duckdb_time () { const UNINIT : :: std :: mem :: MaybeUninit < duckdb_time > = :: std :: mem :: MaybeUninit :: uninit () ; let ptr = UNINIT . as_ptr () ; assert_eq ! (:: std :: mem :: size_of :: < duckdb_time > () , 8usize , concat ! ("Size of: " , stringify ! (duckdb_time))) ; assert_eq ! (:: std :: mem :: align_of :: < duckdb_time > () , 8usize , concat ! ("Alignment of " , stringify ! (duckdb_time))) ; assert_eq ! (unsafe { :: std :: ptr :: addr_of ! ((* ptr) . micros) as usize - ptr as usize } , 0usize , concat ! ("Offset of field: " , stringify ! (duckdb_time) , "::" , stringify ! (micros))) ; } # [repr (C)] # [derive (Debug , Copy , Clone)] pub struct duckdb_time_struct { pub hour : i8 , pub min : i8 , pub sec : i8 , pub micros : i32 , } # [test] fn bindgen_test_layout_duckdb_time_struct () { const UNINIT : :: std :: mem :: MaybeUninit < duckdb_time_struct > = :: std :: mem :: MaybeUninit :: uninit () ; let ptr = UNINIT . as_ptr () ; assert_eq ! (:: std :: mem :: size_of :: < duckdb_time_struct > () , 8usize , concat ! ("Size of: " , stringify ! (duckdb_time_struct))) ; assert_eq ! (:: std :: mem :: align_of :: < duckdb_time_struct > () , 4usize , concat ! ("Alignment of " , stringify ! (duckdb_time_struct))) ; assert_eq ! (unsafe { :: std :: ptr :: addr_of ! ((* ptr) . hour) as usize - ptr as usize } , 0usize , concat ! ("Offset of field: " , stringify ! (duckdb_time_struct) , "::" , stringify ! (hour))) ; assert_eq ! (unsafe { :: std :: ptr :: addr_of ! ((* ptr) . min) as usize - ptr as usize } , 1usize , concat ! ("Offset of field: " , stringify ! (duckdb_time_struct) , "::" , stringify ! (min))) ; assert_eq ! (unsafe { :: std :: ptr :: addr_of ! ((* ptr) . sec) as usize - ptr as usize } , 2usize , concat ! ("Offset of field: " , stringify ! (duckdb_time_struct) , "::" , stringify ! (sec))) ; assert_eq ! (unsafe { :: std :: ptr :: addr_of ! ((* ptr) . micros) as usize - ptr as usize } , 4usize , concat ! ("Offset of field: " , stringify ! (duckdb_time_struct) , "::" , stringify ! (micros))) ; } # [doc = "! TIME_TZ is stored as 40 bits for int64_t micros, and 24 bits for int32_t offset"] # [repr (C)] # [derive (Debug , Copy , Clone)] pub struct duckdb_time_tz { pub bits : u64 , } # [test] fn bindgen_test_layout_duckdb_time_tz () { const UNINIT : :: std :: mem :: MaybeUninit < duckdb_time_tz > = :: std :: mem :: MaybeUninit :: uninit () ; let ptr = UNINIT . as_ptr () ; assert_eq ! (:: std :: mem :: size_of :: < duckdb_time_tz > () , 8usize , concat ! ("Size of: " , stringify ! (duckdb_time_tz))) ; assert_eq ! (:: std :: mem :: align_of :: < duckdb_time_tz > () , 8usize , concat ! ("Alignment of " , stringify ! (duckdb_time_tz))) ; assert_eq ! (unsafe { :: std :: ptr :: addr_of ! ((* ptr) . bits) as usize - ptr as usize } , 0usize , concat ! ("Offset of field: " , stringify ! (duckdb_time_tz) , "::" , stringify ! (bits))) ; } # [repr (C)] # [derive (Debug , Copy , Clone)] pub struct duckdb_time_tz_struct { pub time : duckdb_time_struct , pub offset : i32 , } # [test] fn bindgen_test_layout_duckdb_time_tz_struct () { const UNINIT : :: std :: mem :: MaybeUninit < duckdb_time_tz_struct > = :: std :: mem :: MaybeUninit :: uninit () ; let ptr = UNINIT . as_ptr () ; assert_eq ! (:: std :: mem :: size_of :: < duckdb_time_tz_struct > () , 12usize , concat ! ("Size of: " , stringify ! (duckdb_time_tz_struct))) ; assert_eq ! (:: std :: mem :: align_of :: < duckdb_time_tz_struct > () , 4usize , concat ! ("Alignment of " , stringify ! (duckdb_time_tz_struct))) ; assert_eq ! (unsafe { :: std :: ptr :: addr_of ! ((* ptr) . time) as usize - ptr as usize } , 0usize , concat ! ("Offset of field: " , stringify ! (duckdb_time_tz_struct) , "::" , stringify ! (time))) ; assert_eq ! (unsafe { :: std :: ptr :: addr_of ! ((* ptr) . offset) as usize - ptr as usize } , 8usize , concat ! ("Offset of field: " , stringify ! (duckdb_time_tz_struct) , "::" , stringify ! (offset))) ; } # [doc = "! Timestamps are stored as microseconds since 1970-01-01\n! Use the duckdb_from_timestamp/duckdb_to_timestamp function to extract individual information"] # [repr (C)] # [derive (Debug , Copy , Clone)] pub struct duckdb_timestamp { pub micros : i64 , } # [test] fn bindgen_test_layout_duckdb_timestamp () { const UNINIT : :: std :: mem :: MaybeUninit < duckdb_timestamp > = :: std :: mem :: MaybeUninit :: uninit () ; let ptr = UNINIT . as_ptr () ; assert_eq ! (:: std :: mem :: size_of :: < duckdb_timestamp > () , 8usize , concat ! ("Size of: " , stringify ! (duckdb_timestamp))) ; assert_eq ! (:: std :: mem :: align_of :: < duckdb_timestamp > () , 8usize , concat ! ("Alignment of " , stringify ! (duckdb_timestamp))) ; assert_eq ! (unsafe { :: std :: ptr :: addr_of ! ((* ptr) . micros) as usize - ptr as usize } , 0usize , concat ! ("Offset of field: " , stringify ! (duckdb_timestamp) , "::" , stringify ! (micros))) ; } # [repr (C)] # [derive (Debug , Copy , Clone)] pub struct duckdb_timestamp_struct { pub date : duckdb_date_struct , pub time : duckdb_time_struct , } # [test] fn bindgen_test_layout_duckdb_timestamp_struct () { const UNINIT : :: std :: mem :: MaybeUninit < duckdb_timestamp_struct > = :: std :: mem :: MaybeUninit :: uninit () ; let ptr = UNINIT . as_ptr () ; assert_eq ! (:: std :: mem :: size_of :: < duckdb_timestamp_struct > () , 16usize , concat ! ("Size of: " , stringify ! (duckdb_timestamp_struct))) ; assert_eq ! (:: std :: mem :: align_of :: < duckdb_timestamp_struct > () , 4usize , concat ! ("Alignment of " , stringify ! (duckdb_timestamp_struct))) ; assert_eq ! (unsafe { :: std :: ptr :: addr_of ! ((* ptr) . date) as usize - ptr as usize } , 0usize , concat ! ("Offset of field: " , stringify ! (duckdb_timestamp_struct) , "::" , stringify ! (date))) ; assert_eq ! (unsafe { :: std :: ptr :: addr_of ! ((* ptr) . time) as usize - ptr as usize } , 8usize , concat ! ("Offset of field: " , stringify ! (duckdb_timestamp_struct) , "::" , stringify ! (time))) ; } # [repr (C)] # [derive (Debug , Copy , Clone)] pub struct duckdb_interval { pub months : i32 , pub days : i32 , pub micros : i64 , } # [test] fn bindgen_test_layout_duckdb_interval () { const UNINIT : :: std :: mem :: MaybeUninit < duckdb_interval > = :: std :: mem :: MaybeUninit :: uninit () ; let ptr = UNINIT . as_ptr () ; assert_eq ! (:: std :: mem :: size_of :: < duckdb_interval > () , 16usize , concat ! ("Size of: " , stringify ! (duckdb_interval))) ; assert_eq ! (:: std :: mem :: align_of :: < duckdb_interval > () , 8usize , concat ! ("Alignment of " , stringify ! (duckdb_interval))) ; assert_eq ! (unsafe { :: std :: ptr :: addr_of ! ((* ptr) . months) as usize - ptr as usize } , 0usize , concat ! ("Offset of field: " , stringify ! (duckdb_interval) , "::" , stringify ! (months))) ; assert_eq ! (unsafe { :: std :: ptr :: addr_of ! ((* ptr) . days) as usize - ptr as usize } , 4usize , concat ! ("Offset of field: " , stringify ! (duckdb_interval) , "::" , stringify ! (days))) ; assert_eq ! (unsafe { :: std :: ptr :: addr_of ! ((* ptr) . micros) as usize - ptr as usize } , 8usize , concat ! ("Offset of field: " , stringify ! (duckdb_interval) , "::" , stringify ! (micros))) ; } # [doc = "! Hugeints are composed of a (lower, upper) component\n! The value of the hugeint is upper * 2^64 + lower\n! For easy usage, the functions duckdb_hugeint_to_double/duckdb_double_to_hugeint are recommended"] # [repr (C)] # [derive (Debug , Copy , Clone)] pub struct duckdb_hugeint { pub lower : u64 , pub upper : i64 , } # [test] fn bindgen_test_layout_duckdb_hugeint () { const UNINIT : :: std :: mem :: MaybeUninit < duckdb_hugeint > = :: std :: mem :: MaybeUninit :: uninit () ; let ptr = UNINIT . as_ptr () ; assert_eq ! (:: std :: mem :: size_of :: < duckdb_hugeint > () , 16usize , concat ! ("Size of: " , stringify ! (duckdb_hugeint))) ; assert_eq ! (:: std :: mem :: align_of :: < duckdb_hugeint > () , 8usize , concat ! ("Alignment of " , stringify ! (duckdb_hugeint))) ; assert_eq ! (unsafe { :: std :: ptr :: addr_of ! ((* ptr) . lower) as usize - ptr as usize } , 0usize , concat ! ("Offset of field: " , stringify ! (duckdb_hugeint) , "::" , stringify ! (lower))) ; assert_eq ! (unsafe { :: std :: ptr :: addr_of ! ((* ptr) . upper) as usize - ptr as usize } , 8usize , concat ! ("Offset of field: " , stringify ! (duckdb_hugeint) , "::" , stringify ! (upper))) ; } # [repr (C)] # [derive (Debug , Copy , Clone)] pub struct duckdb_uhugeint { pub lower : u64 , pub upper : u64 , } # [test] fn bindgen_test_layout_duckdb_uhugeint () { const UNINIT : :: std :: mem :: MaybeUninit < duckdb_uhugeint > = :: std :: mem :: MaybeUninit :: uninit () ; let ptr = UNINIT . as_ptr () ; assert_eq ! (:: std :: mem :: size_of :: < duckdb_uhugeint > () , 16usize , concat ! ("Size of: " , stringify ! (duckdb_uhugeint))) ; assert_eq ! (:: std :: mem :: align_of :: < duckdb_uhugeint > () , 8usize , concat ! ("Alignment of " , stringify ! (duckdb_uhugeint))) ; assert_eq ! (unsafe { :: std :: ptr :: addr_of ! ((* ptr) . lower) as usize - ptr as usize } , 0usize , concat ! ("Offset of field: " , stringify ! (duckdb_uhugeint) , "::" , stringify ! (lower))) ; assert_eq ! (unsafe { :: std :: ptr :: addr_of ! ((* ptr) . upper) as usize - ptr as usize } , 8usize , concat ! ("Offset of field: " , stringify ! (duckdb_uhugeint) , "::" , stringify ! (upper))) ; } # [doc = "! Decimals are composed of a width and a scale, and are stored in a hugeint"] # [repr (C)] # [derive (Debug , Copy , Clone)] pub struct duckdb_decimal { pub width : u8 , pub scale : u8 , pub value : duckdb_hugeint , } # [test] fn bindgen_test_layout_duckdb_decimal () { const UNINIT : :: std :: mem :: MaybeUninit < duckdb_decimal > = :: std :: mem :: MaybeUninit :: uninit () ; let ptr = UNINIT . as_ptr () ; assert_eq ! (:: std :: mem :: size_of :: < duckdb_decimal > () , 24usize , concat ! ("Size of: " , stringify ! (duckdb_decimal))) ; assert_eq ! (:: std :: mem :: align_of :: < duckdb_decimal > () , 8usize , concat ! ("Alignment of " , stringify ! (duckdb_decimal))) ; assert_eq ! (unsafe { :: std :: ptr :: addr_of ! ((* ptr) . width) as usize - ptr as usize } , 0usize , concat ! ("Offset of field: " , stringify ! (duckdb_decimal) , "::" , stringify ! (width))) ; assert_eq ! (unsafe { :: std :: ptr :: addr_of ! ((* ptr) . scale) as usize - ptr as usize } , 1usize , concat ! ("Offset of field: " , stringify ! (duckdb_decimal) , "::" , stringify ! (scale))) ; assert_eq ! (unsafe { :: std :: ptr :: addr_of ! ((* ptr) . value) as usize - ptr as usize } , 8usize , concat ! ("Offset of field: " , stringify ! (duckdb_decimal) , "::" , stringify ! (value))) ; } # [doc = "! A type holding information about the query execution progress"] # [repr (C)] # [derive (Debug , Copy , Clone)] pub struct duckdb_query_progress_type { pub percentage : f64 , pub rows_processed : u64 , pub total_rows_to_process : u64 , } # [test] fn bindgen_test_layout_duckdb_query_progress_type () { const UNINIT : :: std :: mem :: MaybeUninit < duckdb_query_progress_type > = :: std :: mem :: MaybeUninit :: uninit () ; let ptr = UNINIT . as_ptr () ; assert_eq ! (:: std :: mem :: size_of :: < duckdb_query_progress_type > () , 24usize , concat ! ("Size of: " , stringify ! (duckdb_query_progress_type))) ; assert_eq ! (:: std :: mem :: align_of :: < duckdb_query_progress_type > () , 8usize , concat ! ("Alignment of " , stringify ! (duckdb_query_progress_type))) ; assert_eq ! (unsafe { :: std :: ptr :: addr_of ! ((* ptr) . percentage) as usize - ptr as usize } , 0usize , concat ! ("Offset of field: " , stringify ! (duckdb_query_progress_type) , "::" , stringify ! (percentage))) ; assert_eq ! (unsafe { :: std :: ptr :: addr_of ! ((* ptr) . rows_processed) as usize - ptr as usize } , 8usize , concat ! ("Offset of field: " , stringify ! (duckdb_query_progress_type) , "::" , stringify ! (rows_processed))) ; assert_eq ! (unsafe { :: std :: ptr :: addr_of ! ((* ptr) . total_rows_to_process) as usize - ptr as usize } , 16usize , concat ! ("Offset of field: " , stringify ! (duckdb_query_progress_type) , "::" , stringify ! (total_rows_to_process))) ; } # [doc = "! The internal representation of a VARCHAR (string_t). If the VARCHAR does not\n! exceed 12 characters, then we inline it. Otherwise, we inline a prefix for faster\n! string comparisons and store a pointer to the remaining characters. This is a non-\n! owning structure, i.e., it does not have to be freed."] # [repr (C)] # [derive (Copy , Clone)] pub struct duckdb_string_t { pub value : duckdb_string_t__bindgen_ty_1 , } # [repr (C)] # [derive (Copy , Clone)] pub union duckdb_string_t__bindgen_ty_1 { pub pointer : duckdb_string_t__bindgen_ty_1__bindgen_ty_1 , pub inlined : duckdb_string_t__bindgen_ty_1__bindgen_ty_2 , } # [repr (C)] # [derive (Debug , Copy , Clone)] pub struct duckdb_string_t__bindgen_ty_1__bindgen_ty_1 { pub length : u32 , pub prefix : [:: std :: os :: raw :: c_char ; 4usize] , pub ptr : * mut :: std :: os :: raw :: c_char , } # [test] fn bindgen_test_layout_duckdb_string_t__bindgen_ty_1__bindgen_ty_1 () { const UNINIT : :: std :: mem :: MaybeUninit < duckdb_string_t__bindgen_ty_1__bindgen_ty_1 > = :: std :: mem :: MaybeUninit :: uninit () ; let ptr = UNINIT . as_ptr () ; assert_eq ! (:: std :: mem :: size_of :: < duckdb_string_t__bindgen_ty_1__bindgen_ty_1 > () , 16usize , concat ! ("Size of: " , stringify ! (duckdb_string_t__bindgen_ty_1__bindgen_ty_1))) ; assert_eq ! (:: std :: mem :: align_of :: < duckdb_string_t__bindgen_ty_1__bindgen_ty_1 > () , 8usize , concat ! ("Alignment of " , stringify ! (duckdb_string_t__bindgen_ty_1__bindgen_ty_1))) ; assert_eq ! (unsafe { :: std :: ptr :: addr_of ! ((* ptr) . length) as usize - ptr as usize } , 0usize , concat ! ("Offset of field: " , stringify ! (duckdb_string_t__bindgen_ty_1__bindgen_ty_1) , "::" , stringify ! (length))) ; assert_eq ! (unsafe { :: std :: ptr :: addr_of ! ((* ptr) . prefix) as usize - ptr as usize } , 4usize , concat ! ("Offset of field: " , stringify ! (duckdb_string_t__bindgen_ty_1__bindgen_ty_1) , "::" , stringify ! (prefix))) ; assert_eq ! (unsafe { :: std :: ptr :: addr_of ! ((* ptr) . ptr) as usize - ptr as usize } , 8usize , concat ! ("Offset of field: " , stringify ! (duckdb_string_t__bindgen_ty_1__bindgen_ty_1) , "::" , stringify ! (ptr))) ; } # [repr (C)] # [derive (Debug , Copy , Clone)] pub struct duckdb_string_t__bindgen_ty_1__bindgen_ty_2 { pub length : u32 , pub inlined : [:: std :: os :: raw :: c_char ; 12usize] , } # [test] fn bindgen_test_layout_duckdb_string_t__bindgen_ty_1__bindgen_ty_2 () { const UNINIT : :: std :: mem :: MaybeUninit < duckdb_string_t__bindgen_ty_1__bindgen_ty_2 > = :: std :: mem :: MaybeUninit :: uninit () ; let ptr = UNINIT . as_ptr () ; assert_eq ! (:: std :: mem :: size_of :: < duckdb_string_t__bindgen_ty_1__bindgen_ty_2 > () , 16usize , concat ! ("Size of: " , stringify ! (duckdb_string_t__bindgen_ty_1__bindgen_ty_2))) ; assert_eq ! (:: std :: mem :: align_of :: < duckdb_string_t__bindgen_ty_1__bindgen_ty_2 > () , 4usize , concat ! ("Alignment of " , stringify ! (duckdb_string_t__bindgen_ty_1__bindgen_ty_2))) ; assert_eq ! (unsafe { :: std :: ptr :: addr_of ! ((* ptr) . length) as usize - ptr as usize } , 0usize , concat ! ("Offset of field: " , stringify ! (duckdb_string_t__bindgen_ty_1__bindgen_ty_2) , "::" , stringify ! (length))) ; assert_eq ! (unsafe { :: std :: ptr :: addr_of ! ((* ptr) . inlined) as usize - ptr as usize } , 4usize , concat ! ("Offset of field: " , stringify ! (duckdb_string_t__bindgen_ty_1__bindgen_ty_2) , "::" , stringify ! (inlined))) ; } # [test] fn bindgen_test_layout_duckdb_string_t__bindgen_ty_1 () { const UNINIT : :: std :: mem :: MaybeUninit < duckdb_string_t__bindgen_ty_1 > = :: std :: mem :: MaybeUninit :: uninit () ; let ptr = UNINIT . as_ptr () ; assert_eq ! (:: std :: mem :: size_of :: < duckdb_string_t__bindgen_ty_1 > () , 16usize , concat ! ("Size of: " , stringify ! (duckdb_string_t__bindgen_ty_1))) ; assert_eq ! (:: std :: mem :: align_of :: < duckdb_string_t__bindgen_ty_1 > () , 8usize , concat ! ("Alignment of " , stringify ! (duckdb_string_t__bindgen_ty_1))) ; assert_eq ! (unsafe { :: std :: ptr :: addr_of ! ((* ptr) . pointer) as usize - ptr as usize } , 0usize , concat ! ("Offset of field: " , stringify ! (duckdb_string_t__bindgen_ty_1) , "::" , stringify ! (pointer))) ; assert_eq ! (unsafe { :: std :: ptr :: addr_of ! ((* ptr) . inlined) as usize - ptr as usize } , 0usize , concat ! ("Offset of field: " , stringify ! (duckdb_string_t__bindgen_ty_1) , "::" , stringify ! (inlined))) ; } # [test] fn bindgen_test_layout_duckdb_string_t () { const UNINIT : :: std :: mem :: MaybeUninit < duckdb_string_t > = :: std :: mem :: MaybeUninit :: uninit () ; let ptr = UNINIT . as_ptr () ; assert_eq ! (:: std :: mem :: size_of :: < duckdb_string_t > () , 16usize , concat ! ("Size of: " , stringify ! (duckdb_string_t))) ; assert_eq ! (:: std :: mem :: align_of :: < duckdb_string_t > () , 8usize , concat ! ("Alignment of " , stringify ! (duckdb_string_t))) ; assert_eq ! (unsafe { :: std :: ptr :: addr_of ! ((* ptr) . value) as usize - ptr as usize } , 0usize , concat ! ("Offset of field: " , stringify ! (duckdb_string_t) , "::" , stringify ! (value))) ; } # [doc = "! The internal representation of a list metadata entry contains the list's offset in\n! the child vector, and its length. The parent vector holds these metadata entries,\n! whereas the child vector holds the data"] # [repr (C)] # [derive (Debug , Copy , Clone)] pub struct duckdb_list_entry { pub offset : u64 , pub length : u64 , } # [test] fn bindgen_test_layout_duckdb_list_entry () { const UNINIT : :: std :: mem :: MaybeUninit < duckdb_list_entry > = :: std :: mem :: MaybeUninit :: uninit () ; let ptr = UNINIT . as_ptr () ; assert_eq ! (:: std :: mem :: size_of :: < duckdb_list_entry > () , 16usize , concat ! ("Size of: " , stringify ! (duckdb_list_entry))) ; assert_eq ! (:: std :: mem :: align_of :: < duckdb_list_entry > () , 8usize , concat ! ("Alignment of " , stringify ! (duckdb_list_entry))) ; assert_eq ! (unsafe { :: std :: ptr :: addr_of ! ((* ptr) . offset) as usize - ptr as usize } , 0usize , concat ! ("Offset of field: " , stringify ! (duckdb_list_entry) , "::" , stringify ! (offset))) ; assert_eq ! (unsafe { :: std :: ptr :: addr_of ! ((* ptr) . length) as usize - ptr as usize } , 8usize , concat ! ("Offset of field: " , stringify ! (duckdb_list_entry) , "::" , stringify ! (length))) ; } # [doc = "! A column consists of a pointer to its internal data. Don't operate on this type directly.\n! Instead, use functions such as duckdb_column_data, duckdb_nullmask_data,\n! duckdb_column_type, and duckdb_column_name, which take the result and the column index\n! as their parameters"] # [repr (C)] # [derive (Debug , Copy , Clone)] pub struct duckdb_column { pub __deprecated_data : * mut :: std :: os :: raw :: c_void , pub __deprecated_nullmask : * mut bool , pub __deprecated_type : duckdb_type , pub __deprecated_name : * mut :: std :: os :: raw :: c_char , pub internal_data : * mut :: std :: os :: raw :: c_void , } # [test] fn bindgen_test_layout_duckdb_column () { const UNINIT : :: std :: mem :: MaybeUninit < duckdb_column > = :: std :: mem :: MaybeUninit :: uninit () ; let ptr = UNINIT . as_ptr () ; assert_eq ! (:: std :: mem :: size_of :: < duckdb_column > () , 40usize , concat ! ("Size of: " , stringify ! (duckdb_column))) ; assert_eq ! (:: std :: mem :: align_of :: < duckdb_column > () , 8usize , concat ! ("Alignment of " , stringify ! (duckdb_column))) ; assert_eq ! (unsafe { :: std :: ptr :: addr_of ! ((* ptr) . __deprecated_data) as usize - ptr as usize } , 0usize , concat ! ("Offset of field: " , stringify ! (duckdb_column) , "::" , stringify ! (__deprecated_data))) ; assert_eq ! (unsafe { :: std :: ptr :: addr_of ! ((* ptr) . __deprecated_nullmask) as usize - ptr as usize } , 8usize , concat ! ("Offset of field: " , stringify ! (duckdb_column) , "::" , stringify ! (__deprecated_nullmask))) ; assert_eq ! (unsafe { :: std :: ptr :: addr_of ! ((* ptr) . __deprecated_type) as usize - ptr as usize } , 16usize , concat ! ("Offset of field: " , stringify ! (duckdb_column) , "::" , stringify ! (__deprecated_type))) ; assert_eq ! (unsafe { :: std :: ptr :: addr_of ! ((* ptr) . __deprecated_name) as usize - ptr as usize } , 24usize , concat ! ("Offset of field: " , stringify ! (duckdb_column) , "::" , stringify ! (__deprecated_name))) ; assert_eq ! (unsafe { :: std :: ptr :: addr_of ! ((* ptr) . internal_data) as usize - ptr as usize } , 32usize , concat ! ("Offset of field: " , stringify ! (duckdb_column) , "::" , stringify ! (internal_data))) ; } # [doc = "! A vector to a specified column in a data chunk. Lives as long as the\n! data chunk lives, i.e., must not be destroyed."] # [repr (C)] # [derive (Debug , Copy , Clone)] pub struct _duckdb_vector { pub __vctr : * mut :: std :: os :: raw :: c_void , } # [test] fn bindgen_test_layout__duckdb_vector () { const UNINIT : :: std :: mem :: MaybeUninit < _duckdb_vector > = :: std :: mem :: MaybeUninit :: uninit () ; let ptr = UNINIT . as_ptr () ; assert_eq ! (:: std :: mem :: size_of :: < _duckdb_vector > () , 8usize , concat ! ("Size of: " , stringify ! (_duckdb_vector))) ; assert_eq ! (:: std :: mem :: align_of :: < _duckdb_vector > () , 8usize , concat ! ("Alignment of " , stringify ! (_duckdb_vector))) ; assert_eq ! (unsafe { :: std :: ptr :: addr_of ! ((* ptr) . __vctr) as usize - ptr as usize } , 0usize , concat ! ("Offset of field: " , stringify ! (_duckdb_vector) , "::" , stringify ! (__vctr))) ; } # [doc = "! A vector to a specified column in a data chunk. Lives as long as the\n! data chunk lives, i.e., must not be destroyed."] pub type duckdb_vector = * mut _duckdb_vector ; # [doc = "! Strings are composed of a char pointer and a size. You must free string.data\n! with `duckdb_free`."] # [repr (C)] # [derive (Debug , Copy , Clone)] pub struct duckdb_string { pub data : * mut :: std :: os :: raw :: c_char , pub size : idx_t , } # [test] fn bindgen_test_layout_duckdb_string () { const UNINIT : :: std :: mem :: MaybeUninit < duckdb_string > = :: std :: mem :: MaybeUninit :: uninit () ; let ptr = UNINIT . as_ptr () ; assert_eq ! (:: std :: mem :: size_of :: < duckdb_string > () , 16usize , concat ! ("Size of: " , stringify ! (duckdb_string))) ; assert_eq ! (:: std :: mem :: align_of :: < duckdb_string > () , 8usize , concat ! ("Alignment of " , stringify ! (duckdb_string))) ; assert_eq ! (unsafe { :: std :: ptr :: addr_of ! ((* ptr) . data) as usize - ptr as usize } , 0usize , concat ! ("Offset of field: " , stringify ! (duckdb_string) , "::" , stringify ! (data))) ; assert_eq ! (unsafe { :: std :: ptr :: addr_of ! ((* ptr) . size) as usize - ptr as usize } , 8usize , concat ! ("Offset of field: " , stringify ! (duckdb_string) , "::" , stringify ! (size))) ; } # [doc = "! BLOBs are composed of a byte pointer and a size. You must free blob.data\n! with `duckdb_free`."] # [repr (C)] # [derive (Debug , Copy , Clone)] pub struct duckdb_blob { pub data : * mut :: std :: os :: raw :: c_void , pub size : idx_t , } # [test] fn bindgen_test_layout_duckdb_blob () { const UNINIT : :: std :: mem :: MaybeUninit < duckdb_blob > = :: std :: mem :: MaybeUninit :: uninit () ; let ptr = UNINIT . as_ptr () ; assert_eq ! (:: std :: mem :: size_of :: < duckdb_blob > () , 16usize , concat ! ("Size of: " , stringify ! (duckdb_blob))) ; assert_eq ! (:: std :: mem :: align_of :: < duckdb_blob > () , 8usize , concat ! ("Alignment of " , stringify ! (duckdb_blob))) ; assert_eq ! (unsafe { :: std :: ptr :: addr_of ! ((* ptr) . data) as usize - ptr as usize } , 0usize , concat ! ("Offset of field: " , stringify ! (duckdb_blob) , "::" , stringify ! (data))) ; assert_eq ! (unsafe { :: std :: ptr :: addr_of ! ((* ptr) . size) as usize - ptr as usize } , 8usize , concat ! ("Offset of field: " , stringify ! (duckdb_blob) , "::" , stringify ! (size))) ; } # [doc = "! A query result consists of a pointer to its internal data.\n! Must be freed with 'duckdb_destroy_result'."] # [repr (C)] # [derive (Debug , Copy , Clone)] pub struct duckdb_result { pub __deprecated_column_count : idx_t , pub __deprecated_row_count : idx_t , pub __deprecated_rows_changed : idx_t , pub __deprecated_columns : * mut duckdb_column , pub __deprecated_error_message : * mut :: std :: os :: raw :: c_char , pub internal_data : * mut :: std :: os :: raw :: c_void , } # [test] fn bindgen_test_layout_duckdb_result () { const UNINIT : :: std :: mem :: MaybeUninit < duckdb_result > = :: std :: mem :: MaybeUninit :: uninit () ; let ptr = UNINIT . as_ptr () ; assert_eq ! (:: std :: mem :: size_of :: < duckdb_result > () , 48usize , concat ! ("Size of: " , stringify ! (duckdb_result))) ; assert_eq ! (:: std :: mem :: align_of :: < duckdb_result > () , 8usize , concat ! ("Alignment of " , stringify ! (duckdb_result))) ; assert_eq ! (unsafe { :: std :: ptr :: addr_of ! ((* ptr) . __deprecated_column_count) as usize - ptr as usize } , 0usize , concat ! ("Offset of field: " , stringify ! (duckdb_result) , "::" , stringify ! (__deprecated_column_count))) ; assert_eq ! (unsafe { :: std :: ptr :: addr_of ! ((* ptr) . __deprecated_row_count) as usize - ptr as usize } , 8usize , concat ! ("Offset of field: " , stringify ! (duckdb_result) , "::" , stringify ! (__deprecated_row_count))) ; assert_eq ! (unsafe { :: std :: ptr :: addr_of ! ((* ptr) . __deprecated_rows_changed) as usize - ptr as usize } , 16usize , concat ! ("Offset of field: " , stringify ! (duckdb_result) , "::" , stringify ! (__deprecated_rows_changed))) ; assert_eq ! (unsafe { :: std :: ptr :: addr_of ! ((* ptr) . __deprecated_columns) as usize - ptr as usize } , 24usize , concat ! ("Offset of field: " , stringify ! (duckdb_result) , "::" , stringify ! (__deprecated_columns))) ; assert_eq ! (unsafe { :: std :: ptr :: addr_of ! ((* ptr) . __deprecated_error_message) as usize - ptr as usize } , 32usize , concat ! ("Offset of field: " , stringify ! (duckdb_result) , "::" , stringify ! (__deprecated_error_message))) ; assert_eq ! (unsafe { :: std :: ptr :: addr_of ! ((* ptr) . internal_data) as usize - ptr as usize } , 40usize , concat ! ("Offset of field: " , stringify ! (duckdb_result) , "::" , stringify ! (internal_data))) ; } # [doc = "! A database object. Should be closed with `duckdb_close`."] # [repr (C)] # [derive (Debug , Copy , Clone)] pub struct _duckdb_database { pub __db : * mut :: std :: os :: raw :: c_void , } # [test] fn bindgen_test_layout__duckdb_database () { const UNINIT : :: std :: mem :: MaybeUninit < _duckdb_database > = :: std :: mem :: MaybeUninit :: uninit () ; let ptr = UNINIT . as_ptr () ; assert_eq ! (:: std :: mem :: size_of :: < _duckdb_database > () , 8usize , concat ! ("Size of: " , stringify ! (_duckdb_database))) ; assert_eq ! (:: std :: mem :: align_of :: < _duckdb_database > () , 8usize , concat ! ("Alignment of " , stringify ! (_duckdb_database))) ; assert_eq ! (unsafe { :: std :: ptr :: addr_of ! ((* ptr) . __db) as usize - ptr as usize } , 0usize , concat ! ("Offset of field: " , stringify ! (_duckdb_database) , "::" , stringify ! (__db))) ; } # [doc = "! A database object. Should be closed with `duckdb_close`."] pub type duckdb_database = * mut _duckdb_database ; # [doc = "! A connection to a duckdb database. Must be closed with `duckdb_disconnect`."] # [repr (C)] # [derive (Debug , Copy , Clone)] pub struct _duckdb_connection { pub __conn : * mut :: std :: os :: raw :: c_void , } # [test] fn bindgen_test_layout__duckdb_connection () { const UNINIT : :: std :: mem :: MaybeUninit < _duckdb_connection > = :: std :: mem :: MaybeUninit :: uninit () ; let ptr = UNINIT . as_ptr () ; assert_eq ! (:: std :: mem :: size_of :: < _duckdb_connection > () , 8usize , concat ! ("Size of: " , stringify ! (_duckdb_connection))) ; assert_eq ! (:: std :: mem :: align_of :: < _duckdb_connection > () , 8usize , concat ! ("Alignment of " , stringify ! (_duckdb_connection))) ; assert_eq ! (unsafe { :: std :: ptr :: addr_of ! ((* ptr) . __conn) as usize - ptr as usize } , 0usize , concat ! ("Offset of field: " , stringify ! (_duckdb_connection) , "::" , stringify ! (__conn))) ; } # [doc = "! A connection to a duckdb database. Must be closed with `duckdb_disconnect`."] pub type duckdb_connection = * mut _duckdb_connection ; # [doc = "! A prepared statement is a parameterized query that allows you to bind parameters to it.\n! Must be destroyed with `duckdb_destroy_prepare`."] # [repr (C)] # [derive (Debug , Copy , Clone)] pub struct _duckdb_prepared_statement { pub __prep : * mut :: std :: os :: raw :: c_void , } # [test] fn bindgen_test_layout__duckdb_prepared_statement () { const UNINIT : :: std :: mem :: MaybeUninit < _duckdb_prepared_statement > = :: std :: mem :: MaybeUninit :: uninit () ; let ptr = UNINIT . as_ptr () ; assert_eq ! (:: std :: mem :: size_of :: < _duckdb_prepared_statement > () , 8usize , concat ! ("Size of: " , stringify ! (_duckdb_prepared_statement))) ; assert_eq ! (:: std :: mem :: align_of :: < _duckdb_prepared_statement > () , 8usize , concat ! ("Alignment of " , stringify ! (_duckdb_prepared_statement))) ; assert_eq ! (unsafe { :: std :: ptr :: addr_of ! ((* ptr) . __prep) as usize - ptr as usize } , 0usize , concat ! ("Offset of field: " , stringify ! (_duckdb_prepared_statement) , "::" , stringify ! (__prep))) ; } # [doc = "! A prepared statement is a parameterized query that allows you to bind parameters to it.\n! Must be destroyed with `duckdb_destroy_prepare`."] pub type duckdb_prepared_statement = * mut _duckdb_prepared_statement ; # [doc = "! Extracted statements. Must be destroyed with `duckdb_destroy_extracted`."] # [repr (C)] # [derive (Debug , Copy , Clone)] pub struct _duckdb_extracted_statements { pub __extrac : * mut :: std :: os :: raw :: c_void , } # [test] fn bindgen_test_layout__duckdb_extracted_statements () { const UNINIT : :: std :: mem :: MaybeUninit < _duckdb_extracted_statements > = :: std :: mem :: MaybeUninit :: uninit () ; let ptr = UNINIT . as_ptr () ; assert_eq ! (:: std :: mem :: size_of :: < _duckdb_extracted_statements > () , 8usize , concat ! ("Size of: " , stringify ! (_duckdb_extracted_statements))) ; assert_eq ! (:: std :: mem :: align_of :: < _duckdb_extracted_statements > () , 8usize , concat ! ("Alignment of " , stringify ! (_duckdb_extracted_statements))) ; assert_eq ! (unsafe { :: std :: ptr :: addr_of ! ((* ptr) . __extrac) as usize - ptr as usize } , 0usize , concat ! ("Offset of field: " , stringify ! (_duckdb_extracted_statements) , "::" , stringify ! (__extrac))) ; } # [doc = "! Extracted statements. Must be destroyed with `duckdb_destroy_extracted`."] pub type duckdb_extracted_statements = * mut _duckdb_extracted_statements ; # [doc = "! The pending result represents an intermediate structure for a query that is not yet fully executed.\n! Must be destroyed with `duckdb_destroy_pending`."] # [repr (C)] # [derive (Debug , Copy , Clone)] pub struct _duckdb_pending_result { pub __pend : * mut :: std :: os :: raw :: c_void , } # [test] fn bindgen_test_layout__duckdb_pending_result () { const UNINIT : :: std :: mem :: MaybeUninit < _duckdb_pending_result > = :: std :: mem :: MaybeUninit :: uninit () ; let ptr = UNINIT . as_ptr () ; assert_eq ! (:: std :: mem :: size_of :: < _duckdb_pending_result > () , 8usize , concat ! ("Size of: " , stringify ! (_duckdb_pending_result))) ; assert_eq ! (:: std :: mem :: align_of :: < _duckdb_pending_result > () , 8usize , concat ! ("Alignment of " , stringify ! (_duckdb_pending_result))) ; assert_eq ! (unsafe { :: std :: ptr :: addr_of ! ((* ptr) . __pend) as usize - ptr as usize } , 0usize , concat ! ("Offset of field: " , stringify ! (_duckdb_pending_result) , "::" , stringify ! (__pend))) ; } # [doc = "! The pending result represents an intermediate structure for a query that is not yet fully executed.\n! Must be destroyed with `duckdb_destroy_pending`."] pub type duckdb_pending_result = * mut _duckdb_pending_result ; # [doc = "! The appender enables fast data loading into DuckDB.\n! Must be destroyed with `duckdb_appender_destroy`."] # [repr (C)] # [derive (Debug , Copy , Clone)] pub struct _duckdb_appender { pub __appn : * mut :: std :: os :: raw :: c_void , } # [test] fn bindgen_test_layout__duckdb_appender () { const UNINIT : :: std :: mem :: MaybeUninit < _duckdb_appender > = :: std :: mem :: MaybeUninit :: uninit () ; let ptr = UNINIT . as_ptr () ; assert_eq ! (:: std :: mem :: size_of :: < _duckdb_appender > () , 8usize , concat ! ("Size of: " , stringify ! (_duckdb_appender))) ; assert_eq ! (:: std :: mem :: align_of :: < _duckdb_appender > () , 8usize , concat ! ("Alignment of " , stringify ! (_duckdb_appender))) ; assert_eq ! (unsafe { :: std :: ptr :: addr_of ! ((* ptr) . __appn) as usize - ptr as usize } , 0usize , concat ! ("Offset of field: " , stringify ! (_duckdb_appender) , "::" , stringify ! (__appn))) ; } # [doc = "! The appender enables fast data loading into DuckDB.\n! Must be destroyed with `duckdb_appender_destroy`."] pub type duckdb_appender = * mut _duckdb_appender ; # [doc = "! Can be used to provide start-up options for the DuckDB instance.\n! Must be destroyed with `duckdb_destroy_config`."] # [repr (C)] # [derive (Debug , Copy , Clone)] pub struct _duckdb_config { pub __cnfg : * mut :: std :: os :: raw :: c_void , } # [test] fn bindgen_test_layout__duckdb_config () { const UNINIT : :: std :: mem :: MaybeUninit < _duckdb_config > = :: std :: mem :: MaybeUninit :: uninit () ; let ptr = UNINIT . as_ptr () ; assert_eq ! (:: std :: mem :: size_of :: < _duckdb_config > () , 8usize , concat ! ("Size of: " , stringify ! (_duckdb_config))) ; assert_eq ! (:: std :: mem :: align_of :: < _duckdb_config > () , 8usize , concat ! ("Alignment of " , stringify ! (_duckdb_config))) ; assert_eq ! (unsafe { :: std :: ptr :: addr_of ! ((* ptr) . __cnfg) as usize - ptr as usize } , 0usize , concat ! ("Offset of field: " , stringify ! (_duckdb_config) , "::" , stringify ! (__cnfg))) ; } # [doc = "! Can be used to provide start-up options for the DuckDB instance.\n! Must be destroyed with `duckdb_destroy_config`."] pub type duckdb_config = * mut _duckdb_config ; # [doc = "! Holds an internal logical type.\n! Must be destroyed with `duckdb_destroy_logical_type`."] # [repr (C)] # [derive (Debug , Copy , Clone)] pub struct _duckdb_logical_type { pub __lglt : * mut :: std :: os :: raw :: c_void , } # [test] fn bindgen_test_layout__duckdb_logical_type () { const UNINIT : :: std :: mem :: MaybeUninit < _duckdb_logical_type > = :: std :: mem :: MaybeUninit :: uninit () ; let ptr = UNINIT . as_ptr () ; assert_eq ! (:: std :: mem :: size_of :: < _duckdb_logical_type > () , 8usize , concat ! ("Size of: " , stringify ! (_duckdb_logical_type))) ; assert_eq ! (:: std :: mem :: align_of :: < _duckdb_logical_type > () , 8usize , concat ! ("Alignment of " , stringify ! (_duckdb_logical_type))) ; assert_eq ! (unsafe { :: std :: ptr :: addr_of ! ((* ptr) . __lglt) as usize - ptr as usize } , 0usize , concat ! ("Offset of field: " , stringify ! (_duckdb_logical_type) , "::" , stringify ! (__lglt))) ; } # [doc = "! Holds an internal logical type.\n! Must be destroyed with `duckdb_destroy_logical_type`."] pub type duckdb_logical_type = * mut _duckdb_logical_type ; # [doc = "! Contains a data chunk from a duckdb_result.\n! Must be destroyed with `duckdb_destroy_data_chunk`."] # [repr (C)] # [derive (Debug , Copy , Clone)] pub struct _duckdb_data_chunk { pub __dtck : * mut :: std :: os :: raw :: c_void , } # [test] fn bindgen_test_layout__duckdb_data_chunk () { const UNINIT : :: std :: mem :: MaybeUninit < _duckdb_data_chunk > = :: std :: mem :: MaybeUninit :: uninit () ; let ptr = UNINIT . as_ptr () ; assert_eq ! (:: std :: mem :: size_of :: < _duckdb_data_chunk > () , 8usize , concat ! ("Size of: " , stringify ! (_duckdb_data_chunk))) ; assert_eq ! (:: std :: mem :: align_of :: < _duckdb_data_chunk > () , 8usize , concat ! ("Alignment of " , stringify ! (_duckdb_data_chunk))) ; assert_eq ! (unsafe { :: std :: ptr :: addr_of ! ((* ptr) . __dtck) as usize - ptr as usize } , 0usize , concat ! ("Offset of field: " , stringify ! (_duckdb_data_chunk) , "::" , stringify ! (__dtck))) ; } # [doc = "! Contains a data chunk from a duckdb_result.\n! Must be destroyed with `duckdb_destroy_data_chunk`."] pub type duckdb_data_chunk = * mut _duckdb_data_chunk ; # [doc = "! Holds a DuckDB value, which wraps a type.\n! Must be destroyed with `duckdb_destroy_value`."] # [repr (C)] # [derive (Debug , Copy , Clone)] pub struct _duckdb_value { pub __val : * mut :: std :: os :: raw :: c_void , } # [test] fn bindgen_test_layout__duckdb_value () { const UNINIT : :: std :: mem :: MaybeUninit < _duckdb_value > = :: std :: mem :: MaybeUninit :: uninit () ; let ptr = UNINIT . as_ptr () ; assert_eq ! (:: std :: mem :: size_of :: < _duckdb_value > () , 8usize , concat ! ("Size of: " , stringify ! (_duckdb_value))) ; assert_eq ! (:: std :: mem :: align_of :: < _duckdb_value > () , 8usize , concat ! ("Alignment of " , stringify ! (_duckdb_value))) ; assert_eq ! (unsafe { :: std :: ptr :: addr_of ! ((* ptr) . __val) as usize - ptr as usize } , 0usize , concat ! ("Offset of field: " , stringify ! (_duckdb_value) , "::" , stringify ! (__val))) ; } # [doc = "! Holds a DuckDB value, which wraps a type.\n! Must be destroyed with `duckdb_destroy_value`."] pub type duckdb_value = * mut _duckdb_value ; # [doc = "! A table function. Must be destroyed with `duckdb_destroy_table_function`."] pub type duckdb_table_function = * mut :: std :: os :: raw :: c_void ; # [doc = "! The bind info of the function. When setting this info, it is necessary to pass a destroy-callback function."] pub type duckdb_bind_info = * mut :: std :: os :: raw :: c_void ; # [doc = "! Additional function init info. When setting this info, it is necessary to pass a destroy-callback function."] pub type duckdb_init_info = * mut :: std :: os :: raw :: c_void ; # [doc = "! Additional function info. When setting this info, it is necessary to pass a destroy-callback function."] pub type duckdb_function_info = * mut :: std :: os :: raw :: c_void ; # [doc = "! The bind function of the table function."] pub type duckdb_table_function_bind_t = :: std :: option :: Option < unsafe extern "C" fn (info : duckdb_bind_info) > ; # [doc = "! The (possibly thread-local) init function of the table function."] pub type duckdb_table_function_init_t = :: std :: option :: Option < unsafe extern "C" fn (info : duckdb_init_info) > ; # [doc = "! The main function of the table function."] pub type duckdb_table_function_t = :: std :: option :: Option < unsafe extern "C" fn (info : duckdb_function_info , output : duckdb_data_chunk) > ; # [doc = "! Additional replacement scan info. When setting this info, it is necessary to pass a destroy-callback function."] pub type duckdb_replacement_scan_info = * mut :: std :: os :: raw :: c_void ; # [doc = "! A replacement scan function that can be added to a database."] pub type duckdb_replacement_callback_t = :: std :: option :: Option < unsafe extern "C" fn (info : duckdb_replacement_scan_info , table_name : * const :: std :: os :: raw :: c_char , data : * mut :: std :: os :: raw :: c_void) > ; # [doc = "! Holds an arrow query result. Must be destroyed with `duckdb_destroy_arrow`."] # [repr (C)] # [derive (Debug , Copy , Clone)] pub struct _duckdb_arrow { pub __arrw : * mut :: std :: os :: raw :: c_void , } # [test] fn bindgen_test_layout__duckdb_arrow () { const UNINIT : :: std :: mem :: MaybeUninit < _duckdb_arrow > = :: std :: mem :: MaybeUninit :: uninit () ; let ptr = UNINIT . as_ptr () ; assert_eq ! (:: std :: mem :: size_of :: < _duckdb_arrow > () , 8usize , concat ! ("Size of: " , stringify ! (_duckdb_arrow))) ; assert_eq ! (:: std :: mem :: align_of :: < _duckdb_arrow > () , 8usize , concat ! ("Alignment of " , stringify ! (_duckdb_arrow))) ; assert_eq ! (unsafe { :: std :: ptr :: addr_of ! ((* ptr) . __arrw) as usize - ptr as usize } , 0usize , concat ! ("Offset of field: " , stringify ! (_duckdb_arrow) , "::" , stringify ! (__arrw))) ; } # [doc = "! Holds an arrow query result. Must be destroyed with `duckdb_destroy_arrow`."] pub type duckdb_arrow = * mut _duckdb_arrow ; # [doc = "! Holds an arrow array stream. Must be destroyed with `duckdb_destroy_arrow_stream`."] # [repr (C)] # [derive (Debug , Copy , Clone)] pub struct _duckdb_arrow_stream { pub __arrwstr : * mut :: std :: os :: raw :: c_void , } # [test] fn bindgen_test_layout__duckdb_arrow_stream () { const UNINIT : :: std :: mem :: MaybeUninit < _duckdb_arrow_stream > = :: std :: mem :: MaybeUninit :: uninit () ; let ptr = UNINIT . as_ptr () ; assert_eq ! (:: std :: mem :: size_of :: < _duckdb_arrow_stream > () , 8usize , concat ! ("Size of: " , stringify ! (_duckdb_arrow_stream))) ; assert_eq ! (:: std :: mem :: align_of :: < _duckdb_arrow_stream > () , 8usize , concat ! ("Alignment of " , stringify ! (_duckdb_arrow_stream))) ; assert_eq ! (unsafe { :: std :: ptr :: addr_of ! ((* ptr) . __arrwstr) as usize - ptr as usize } , 0usize , concat ! ("Offset of field: " , stringify ! (_duckdb_arrow_stream) , "::" , stringify ! (__arrwstr))) ; } # [doc = "! Holds an arrow array stream. Must be destroyed with `duckdb_destroy_arrow_stream`."] pub type duckdb_arrow_stream = * mut _duckdb_arrow_stream ; # [doc = "! Holds an arrow schema. Remember to release the respective ArrowSchema object."] # [repr (C)] # [derive (Debug , Copy , Clone)] pub struct _duckdb_arrow_schema { pub __arrs : * mut :: std :: os :: raw :: c_void , } # [test] fn bindgen_test_layout__duckdb_arrow_schema () { const UNINIT : :: std :: mem :: MaybeUninit < _duckdb_arrow_schema > = :: std :: mem :: MaybeUninit :: uninit () ; let ptr = UNINIT . as_ptr () ; assert_eq ! (:: std :: mem :: size_of :: < _duckdb_arrow_schema > () , 8usize , concat ! ("Size of: " , stringify ! (_duckdb_arrow_schema))) ; assert_eq ! (:: std :: mem :: align_of :: < _duckdb_arrow_schema > () , 8usize , concat ! ("Alignment of " , stringify ! (_duckdb_arrow_schema))) ; assert_eq ! (unsafe { :: std :: ptr :: addr_of ! ((* ptr) . __arrs) as usize - ptr as usize } , 0usize , concat ! ("Offset of field: " , stringify ! (_duckdb_arrow_schema) , "::" , stringify ! (__arrs))) ; } # [doc = "! Holds an arrow schema. Remember to release the respective ArrowSchema object."] pub type duckdb_arrow_schema = * mut _duckdb_arrow_schema ; # [doc = "! Holds an arrow array. Remember to release the respective ArrowArray object."] # [repr (C)] # [derive (Debug , Copy , Clone)] pub struct _duckdb_arrow_array { pub __arra : * mut :: std :: os :: raw :: c_void , } # [test] fn bindgen_test_layout__duckdb_arrow_array () { const UNINIT : :: std :: mem :: MaybeUninit < _duckdb_arrow_array > = :: std :: mem :: MaybeUninit :: uninit () ; let ptr = UNINIT . as_ptr () ; assert_eq ! (:: std :: mem :: size_of :: < _duckdb_arrow_array > () , 8usize , concat ! ("Size of: " , stringify ! (_duckdb_arrow_array))) ; assert_eq ! (:: std :: mem :: align_of :: < _duckdb_arrow_array > () , 8usize , concat ! ("Alignment of " , stringify ! (_duckdb_arrow_array))) ; assert_eq ! (unsafe { :: std :: ptr :: addr_of ! ((* ptr) . __arra) as usize - ptr as usize } , 0usize , concat ! ("Offset of field: " , stringify ! (_duckdb_arrow_array) , "::" , stringify ! (__arra))) ; } # [doc = "! Holds an arrow array. Remember to release the respective ArrowArray object."] pub type duckdb_arrow_array = * mut _duckdb_arrow_array ; extern "C" { # [doc = "Creates a new database or opens an existing database file stored at the given path.\nIf no path is given a new in-memory database is created instead.\nThe instantiated database should be closed with 'duckdb_close'.\n\n path: Path to the database file on disk, or `nullptr` or `:memory:` to open an in-memory database.\n out_database: The result database object.\n returns: `DuckDBSuccess` on success or `DuckDBError` on failure."] pub fn duckdb_open (path : * const :: std :: os :: raw :: c_char , out_database : * mut duckdb_database) -> duckdb_state ; } extern "C" { # [doc = "Extended version of duckdb_open. Creates a new database or opens an existing database file stored at the given path.\nThe instantiated database should be closed with 'duckdb_close'.\n\n path: Path to the database file on disk, or `nullptr` or `:memory:` to open an in-memory database.\n out_database: The result database object.\n config: (Optional) configuration used to start up the database system.\n out_error: If set and the function returns DuckDBError, this will contain the reason why the start-up failed.\nNote that the error must be freed using `duckdb_free`.\n returns: `DuckDBSuccess` on success or `DuckDBError` on failure."] pub fn duckdb_open_ext (path : * const :: std :: os :: raw :: c_char , out_database : * mut duckdb_database , config : duckdb_config , out_error : * mut * mut :: std :: os :: raw :: c_char) -> duckdb_state ; } extern "C" { # [doc = "Closes the specified database and de-allocates all memory allocated for that database.\nThis should be called after you are done with any database allocated through `duckdb_open` or `duckdb_open_ext`.\nNote that failing to call `duckdb_close` (in case of e.g. a program crash) will not cause data corruption.\nStill, it is recommended to always correctly close a database object after you are done with it.\n\n database: The database object to shut down."] pub fn duckdb_close (database : * mut duckdb_database) ; } extern "C" { # [doc = "Opens a connection to a database. Connections are required to query the database, and store transactional state\nassociated with the connection.\nThe instantiated connection should be closed using 'duckdb_disconnect'.\n\n database: The database file to connect to.\n out_connection: The result connection object.\n returns: `DuckDBSuccess` on success or `DuckDBError` on failure."] pub fn duckdb_connect (database : duckdb_database , out_connection : * mut duckdb_connection) -> duckdb_state ; } extern "C" { # [doc = "Interrupt running query\n\n connection: The connection to interrupt"] pub fn duckdb_interrupt (connection : duckdb_connection) ; } extern "C" { # [doc = "Get progress of the running query\n\n connection: The working connection\n returns: -1 if no progress or a percentage of the progress"] pub fn duckdb_query_progress (connection : duckdb_connection) -> duckdb_query_progress_type ; } extern "C" { # [doc = "Closes the specified connection and de-allocates all memory allocated for that connection.\n\n connection: The connection to close."] pub fn duckdb_disconnect (connection : * mut duckdb_connection) ; } extern "C" { # [doc = "Returns the version of the linked DuckDB, with a version postfix for dev versions\n\nUsually used for developing C extensions that must return this for a compatibility check."] pub fn duckdb_library_version () -> * const :: std :: os :: raw :: c_char ; } extern "C" { # [doc = "Initializes an empty configuration object that can be used to provide start-up options for the DuckDB instance\nthrough `duckdb_open_ext`.\nThe duckdb_config must be destroyed using 'duckdb_destroy_config'\n\nThis will always succeed unless there is a malloc failure.\n\n out_config: The result configuration object.\n returns: `DuckDBSuccess` on success or `DuckDBError` on failure."] pub fn duckdb_create_config (out_config : * mut duckdb_config) -> duckdb_state ; } extern "C" { # [doc = "This returns the total amount of configuration options available for usage with `duckdb_get_config_flag`.\n\nThis should not be called in a loop as it internally loops over all the options.\n\n returns: The amount of config options available."] pub fn duckdb_config_count () -> usize ; } extern "C" { # [doc = "Obtains a human-readable name and description of a specific configuration option. This can be used to e.g.\ndisplay configuration options. This will succeed unless `index` is out of range (i.e. `>= duckdb_config_count`).\n\nThe result name or description MUST NOT be freed.\n\n index: The index of the configuration option (between 0 and `duckdb_config_count`)\n out_name: A name of the configuration flag.\n out_description: A description of the configuration flag.\n returns: `DuckDBSuccess` on success or `DuckDBError` on failure."] pub fn duckdb_get_config_flag (index : usize , out_name : * mut * const :: std :: os :: raw :: c_char , out_description : * mut * const :: std :: os :: raw :: c_char) -> duckdb_state ; } extern "C" { # [doc = "Sets the specified option for the specified configuration. The configuration option is indicated by name.\nTo obtain a list of config options, see `duckdb_get_config_flag`.\n\nIn the source code, configuration options are defined in `config.cpp`.\n\nThis can fail if either the name is invalid, or if the value provided for the option is invalid.\n\n duckdb_config: The configuration object to set the option on.\n name: The name of the configuration flag to set.\n option: The value to set the configuration flag to.\n returns: `DuckDBSuccess` on success or `DuckDBError` on failure."] pub fn duckdb_set_config (config : duckdb_config , name : * const :: std :: os :: raw :: c_char , option : * const :: std :: os :: raw :: c_char) -> duckdb_state ; } extern "C" { # [doc = "Destroys the specified configuration object and de-allocates all memory allocated for the object.\n\n config: The configuration object to destroy."] pub fn duckdb_destroy_config (config : * mut duckdb_config) ; } extern "C" { # [doc = "Executes a SQL query within a connection and stores the full (materialized) result in the out_result pointer.\nIf the query fails to execute, DuckDBError is returned and the error message can be retrieved by calling\n`duckdb_result_error`.\n\nNote that after running `duckdb_query`, `duckdb_destroy_result` must be called on the result object even if the\nquery fails, otherwise the error stored within the result will not be freed correctly.\n\n connection: The connection to perform the query in.\n query: The SQL query to run.\n out_result: The query result.\n returns: `DuckDBSuccess` on success or `DuckDBError` on failure."] pub fn duckdb_query (connection : duckdb_connection , query : * const :: std :: os :: raw :: c_char , out_result : * mut duckdb_result) -> duckdb_state ; } extern "C" { # [doc = "Closes the result and de-allocates all memory allocated for that connection.\n\n result: The result to destroy."] pub fn duckdb_destroy_result (result : * mut duckdb_result) ; } extern "C" { # [doc = "Returns the column name of the specified column. The result should not need to be freed; the column names will\nautomatically be destroyed when the result is destroyed.\n\nReturns `NULL` if the column is out of range.\n\n result: The result object to fetch the column name from.\n col: The column index.\n returns: The column name of the specified column."] pub fn duckdb_column_name (result : * mut duckdb_result , col : idx_t) -> * const :: std :: os :: raw :: c_char ; } extern "C" { # [doc = "Returns the column type of the specified column.\n\nReturns `DUCKDB_TYPE_INVALID` if the column is out of range.\n\n result: The result object to fetch the column type from.\n col: The column index.\n returns: The column type of the specified column."] pub fn duckdb_column_type (result : * mut duckdb_result , col : idx_t) -> duckdb_type ; } extern "C" { # [doc = "Returns the statement type of the statement that was executed\n\n result: The result object to fetch the statement type from.\n returns: duckdb_statement_type value or DUCKDB_STATEMENT_TYPE_INVALID"] pub fn duckdb_result_statement_type (result : duckdb_result) -> duckdb_statement_type ; } extern "C" { # [doc = "Returns the logical column type of the specified column.\n\nThe return type of this call should be destroyed with `duckdb_destroy_logical_type`.\n\nReturns `NULL` if the column is out of range.\n\n result: The result object to fetch the column type from.\n col: The column index.\n returns: The logical column type of the specified column."] pub fn duckdb_column_logical_type (result : * mut duckdb_result , col : idx_t) -> duckdb_logical_type ; } extern "C" { # [doc = "Returns the number of columns present in a the result object.\n\n result: The result object.\n returns: The number of columns present in the result object."] pub fn duckdb_column_count (result : * mut duckdb_result) -> idx_t ; } extern "C" { # [doc = "DEPRECATION NOTICE**: This method is scheduled for removal in a future release.\n\nReturns the number of rows present in the result object.\n\n result: The result object.\n returns: The number of rows present in the result object."] pub fn duckdb_row_count (result : * mut duckdb_result) -> idx_t ; } extern "C" { # [doc = "Returns the number of rows changed by the query stored in the result. This is relevant only for INSERT/UPDATE/DELETE\nqueries. For other queries the rows_changed will be 0.\n\n result: The result object.\n returns: The number of rows changed."] pub fn duckdb_rows_changed (result : * mut duckdb_result) -> idx_t ; } extern "C" { # [doc = "DEPRECATED**: Prefer using `duckdb_result_get_chunk` instead.\n\nReturns the data of a specific column of a result in columnar format.\n\nThe function returns a dense array which contains the result data. The exact type stored in the array depends on the\ncorresponding duckdb_type (as provided by `duckdb_column_type`). For the exact type by which the data should be\naccessed, see the comments in [the types section](types) or the `DUCKDB_TYPE` enum.\n\nFor example, for a column of type `DUCKDB_TYPE_INTEGER`, rows can be accessed in the following manner:\n```c\nint32_t *data = (int32_t *) duckdb_column_data(&result, 0);\nprintf(\"Data for row %d: %d\\n\", row, data[row]);\n```\n\n result: The result object to fetch the column data from.\n col: The column index.\n returns: The column data of the specified column."] pub fn duckdb_column_data (result : * mut duckdb_result , col : idx_t) -> * mut :: std :: os :: raw :: c_void ; } extern "C" { # [doc = "DEPRECATED**: Prefer using `duckdb_result_get_chunk` instead.\n\nReturns the nullmask of a specific column of a result in columnar format. The nullmask indicates for every row\nwhether or not the corresponding row is `NULL`. If a row is `NULL`, the values present in the array provided\nby `duckdb_column_data` are undefined.\n\n```c\nint32_t *data = (int32_t *) duckdb_column_data(&result, 0);\nbool *nullmask = duckdb_nullmask_data(&result, 0);\nif (nullmask[row]) {\nprintf(\"Data for row %d: NULL\\n\", row);\n} else {\nprintf(\"Data for row %d: %d\\n\", row, data[row]);\n}\n```\n\n result: The result object to fetch the nullmask from.\n col: The column index.\n returns: The nullmask of the specified column."] pub fn duckdb_nullmask_data (result : * mut duckdb_result , col : idx_t) -> * mut bool ; } extern "C" { # [doc = "Returns the error message contained within the result. The error is only set if `duckdb_query` returns `DuckDBError`.\n\nThe result of this function must not be freed. It will be cleaned up when `duckdb_destroy_result` is called.\n\n result: The result object to fetch the error from.\n returns: The error of the result."] pub fn duckdb_result_error (result : * mut duckdb_result) -> * const :: std :: os :: raw :: c_char ; } extern "C" { # [doc = "DEPRECATION NOTICE**: This method is scheduled for removal in a future release.\n\nFetches a data chunk from the duckdb_result. This function should be called repeatedly until the result is exhausted.\n\nThe result must be destroyed with `duckdb_destroy_data_chunk`.\n\nThis function supersedes all `duckdb_value` functions, as well as the `duckdb_column_data` and `duckdb_nullmask_data`\nfunctions. It results in significantly better performance, and should be preferred in newer code-bases.\n\nIf this function is used, none of the other result functions can be used and vice versa (i.e. this function cannot be\nmixed with the legacy result functions).\n\nUse `duckdb_result_chunk_count` to figure out how many chunks there are in the result.\n\n result: The result object to fetch the data chunk from.\n chunk_index: The chunk index to fetch from.\n returns: The resulting data chunk. Returns `NULL` if the chunk index is out of bounds."] pub fn duckdb_result_get_chunk (result : duckdb_result , chunk_index : idx_t) -> duckdb_data_chunk ; } extern "C" { # [doc = "DEPRECATION NOTICE**: This method is scheduled for removal in a future release.\n\nChecks if the type of the internal result is StreamQueryResult.\n\n result: The result object to check.\n returns: Whether or not the result object is of the type StreamQueryResult"] pub fn duckdb_result_is_streaming (result : duckdb_result) -> bool ; } extern "C" { # [doc = "DEPRECATION NOTICE**: This method is scheduled for removal in a future release.\n\nReturns the number of data chunks present in the result.\n\n result: The result object\n returns: Number of data chunks present in the result."] pub fn duckdb_result_chunk_count (result : duckdb_result) -> idx_t ; } extern "C" { # [doc = "Returns the return_type of the given result, or DUCKDB_RETURN_TYPE_INVALID on error\n\n result: The result object\n returns: The return_type"] pub fn duckdb_result_return_type (result : duckdb_result) -> duckdb_result_type ; } extern "C" { # [doc = "DEPRECATION NOTICE**: This method is scheduled for removal in a future release.\n\n returns: The boolean value at the specified location, or false if the value cannot be converted."] pub fn duckdb_value_boolean (result : * mut duckdb_result , col : idx_t , row : idx_t) -> bool ; } extern "C" { # [doc = "DEPRECATION NOTICE**: This method is scheduled for removal in a future release.\n\n returns: The int8_t value at the specified location, or 0 if the value cannot be converted."] pub fn duckdb_value_int8 (result : * mut duckdb_result , col : idx_t , row : idx_t) -> i8 ; } extern "C" { # [doc = "DEPRECATION NOTICE**: This method is scheduled for removal in a future release.\n\n returns: The int16_t value at the specified location, or 0 if the value cannot be converted."] pub fn duckdb_value_int16 (result : * mut duckdb_result , col : idx_t , row : idx_t) -> i16 ; } extern "C" { # [doc = "DEPRECATION NOTICE**: This method is scheduled for removal in a future release.\n\n returns: The int32_t value at the specified location, or 0 if the value cannot be converted."] pub fn duckdb_value_int32 (result : * mut duckdb_result , col : idx_t , row : idx_t) -> i32 ; } extern "C" { # [doc = "DEPRECATION NOTICE**: This method is scheduled for removal in a future release.\n\n returns: The int64_t value at the specified location, or 0 if the value cannot be converted."] pub fn duckdb_value_int64 (result : * mut duckdb_result , col : idx_t , row : idx_t) -> i64 ; } extern "C" { # [doc = "DEPRECATION NOTICE**: This method is scheduled for removal in a future release.\n\n returns: The duckdb_hugeint value at the specified location, or 0 if the value cannot be converted."] pub fn duckdb_value_hugeint (result : * mut duckdb_result , col : idx_t , row : idx_t) -> duckdb_hugeint ; } extern "C" { # [doc = "DEPRECATION NOTICE**: This method is scheduled for removal in a future release.\n\n returns: The duckdb_uhugeint value at the specified location, or 0 if the value cannot be converted."] pub fn duckdb_value_uhugeint (result : * mut duckdb_result , col : idx_t , row : idx_t) -> duckdb_uhugeint ; } extern "C" { # [doc = "DEPRECATION NOTICE**: This method is scheduled for removal in a future release.\n\n returns: The duckdb_decimal value at the specified location, or 0 if the value cannot be converted."] pub fn duckdb_value_decimal (result : * mut duckdb_result , col : idx_t , row : idx_t) -> duckdb_decimal ; } extern "C" { # [doc = "DEPRECATION NOTICE**: This method is scheduled for removal in a future release.\n\n returns: The uint8_t value at the specified location, or 0 if the value cannot be converted."] pub fn duckdb_value_uint8 (result : * mut duckdb_result , col : idx_t , row : idx_t) -> u8 ; } extern "C" { # [doc = "DEPRECATION NOTICE**: This method is scheduled for removal in a future release.\n\n returns: The uint16_t value at the specified location, or 0 if the value cannot be converted."] pub fn duckdb_value_uint16 (result : * mut duckdb_result , col : idx_t , row : idx_t) -> u16 ; } extern "C" { # [doc = "DEPRECATION NOTICE**: This method is scheduled for removal in a future release.\n\n returns: The uint32_t value at the specified location, or 0 if the value cannot be converted."] pub fn duckdb_value_uint32 (result : * mut duckdb_result , col : idx_t , row : idx_t) -> u32 ; } extern "C" { # [doc = "DEPRECATION NOTICE**: This method is scheduled for removal in a future release.\n\n returns: The uint64_t value at the specified location, or 0 if the value cannot be converted."] pub fn duckdb_value_uint64 (result : * mut duckdb_result , col : idx_t , row : idx_t) -> u64 ; } extern "C" { # [doc = "DEPRECATION NOTICE**: This method is scheduled for removal in a future release.\n\n returns: The float value at the specified location, or 0 if the value cannot be converted."] pub fn duckdb_value_float (result : * mut duckdb_result , col : idx_t , row : idx_t) -> f32 ; } extern "C" { # [doc = "DEPRECATION NOTICE**: This method is scheduled for removal in a future release.\n\n returns: The double value at the specified location, or 0 if the value cannot be converted."] pub fn duckdb_value_double (result : * mut duckdb_result , col : idx_t , row : idx_t) -> f64 ; } extern "C" { # [doc = "DEPRECATION NOTICE**: This method is scheduled for removal in a future release.\n\n returns: The duckdb_date value at the specified location, or 0 if the value cannot be converted."] pub fn duckdb_value_date (result : * mut duckdb_result , col : idx_t , row : idx_t) -> duckdb_date ; } extern "C" { # [doc = "DEPRECATION NOTICE**: This method is scheduled for removal in a future release.\n\n returns: The duckdb_time value at the specified location, or 0 if the value cannot be converted."] pub fn duckdb_value_time (result : * mut duckdb_result , col : idx_t , row : idx_t) -> duckdb_time ; } extern "C" { # [doc = "DEPRECATION NOTICE**: This method is scheduled for removal in a future release.\n\n returns: The duckdb_timestamp value at the specified location, or 0 if the value cannot be converted."] pub fn duckdb_value_timestamp (result : * mut duckdb_result , col : idx_t , row : idx_t) -> duckdb_timestamp ; } extern "C" { # [doc = "DEPRECATION NOTICE**: This method is scheduled for removal in a future release.\n\n returns: The duckdb_interval value at the specified location, or 0 if the value cannot be converted."] pub fn duckdb_value_interval (result : * mut duckdb_result , col : idx_t , row : idx_t) -> duckdb_interval ; } extern "C" { # [doc = " DEPRECATED: use duckdb_value_string instead. This function does not work correctly if the string contains null bytes.\n returns: The text value at the specified location as a null-terminated string, or nullptr if the value cannot be\nconverted. The result must be freed with `duckdb_free`."] pub fn duckdb_value_varchar (result : * mut duckdb_result , col : idx_t , row : idx_t) -> * mut :: std :: os :: raw :: c_char ; } extern "C" { # [doc = "DEPRECATION NOTICE**: This method is scheduled for removal in a future release.\n\n returns: The string value at the specified location. Attempts to cast the result value to string.\n No support for nested types, and for other complex types.\n The resulting field \"string.data\" must be freed with `duckdb_free.`"] pub fn duckdb_value_string (result : * mut duckdb_result , col : idx_t , row : idx_t) -> duckdb_string ; } extern "C" { # [doc = " DEPRECATED: use duckdb_value_string_internal instead. This function does not work correctly if the string contains\nnull bytes.\n returns: The char* value at the specified location. ONLY works on VARCHAR columns and does not auto-cast.\nIf the column is NOT a VARCHAR column this function will return NULL.\n\nThe result must NOT be freed."] pub fn duckdb_value_varchar_internal (result : * mut duckdb_result , col : idx_t , row : idx_t) -> * mut :: std :: os :: raw :: c_char ; } extern "C" { # [doc = " DEPRECATED: use duckdb_value_string_internal instead. This function does not work correctly if the string contains\nnull bytes.\n returns: The char* value at the specified location. ONLY works on VARCHAR columns and does not auto-cast.\nIf the column is NOT a VARCHAR column this function will return NULL.\n\nThe result must NOT be freed."] pub fn duckdb_value_string_internal (result : * mut duckdb_result , col : idx_t , row : idx_t) -> duckdb_string ; } extern "C" { # [doc = "DEPRECATION NOTICE**: This method is scheduled for removal in a future release.\n\n returns: The duckdb_blob value at the specified location. Returns a blob with blob.data set to nullptr if the\nvalue cannot be converted. The resulting field \"blob.data\" must be freed with `duckdb_free.`"] pub fn duckdb_value_blob (result : * mut duckdb_result , col : idx_t , row : idx_t) -> duckdb_blob ; } extern "C" { # [doc = "DEPRECATION NOTICE**: This method is scheduled for removal in a future release.\n\n returns: Returns true if the value at the specified index is NULL, and false otherwise."] pub fn duckdb_value_is_null (result : * mut duckdb_result , col : idx_t , row : idx_t) -> bool ; } extern "C" { # [doc = "Allocate `size` bytes of memory using the duckdb internal malloc function. Any memory allocated in this manner\nshould be freed using `duckdb_free`.\n\n size: The number of bytes to allocate.\n returns: A pointer to the allocated memory region."] pub fn duckdb_malloc (size : usize) -> * mut :: std :: os :: raw :: c_void ; } extern "C" { # [doc = "Free a value returned from `duckdb_malloc`, `duckdb_value_varchar`, `duckdb_value_blob`, or\n`duckdb_value_string`.\n\n ptr: The memory region to de-allocate."] pub fn duckdb_free (ptr : * mut :: std :: os :: raw :: c_void) ; } extern "C" { # [doc = "The internal vector size used by DuckDB.\nThis is the amount of tuples that will fit into a data chunk created by `duckdb_create_data_chunk`.\n\n returns: The vector size."] pub fn duckdb_vector_size () -> idx_t ; } extern "C" { # [doc = "Whether or not the duckdb_string_t value is inlined.\nThis means that the data of the string does not have a separate allocation."] pub fn duckdb_string_is_inlined (string : duckdb_string_t) -> bool ; } extern "C" { # [doc = "Decompose a `duckdb_date` object into year, month and date (stored as `duckdb_date_struct`).\n\n date: The date object, as obtained from a `DUCKDB_TYPE_DATE` column.\n returns: The `duckdb_date_struct` with the decomposed elements."] pub fn duckdb_from_date (date : duckdb_date) -> duckdb_date_struct ; } extern "C" { # [doc = "Re-compose a `duckdb_date` from year, month and date (`duckdb_date_struct`).\n\n date: The year, month and date stored in a `duckdb_date_struct`.\n returns: The `duckdb_date` element."] pub fn duckdb_to_date (date : duckdb_date_struct) -> duckdb_date ; } extern "C" { # [doc = "Test a `duckdb_date` to see if it is a finite value.\n\n date: The date object, as obtained from a `DUCKDB_TYPE_DATE` column.\n returns: True if the date is finite, false if it is ±infinity."] pub fn duckdb_is_finite_date (date : duckdb_date) -> bool ; } extern "C" { # [doc = "Decompose a `duckdb_time` object into hour, minute, second and microsecond (stored as `duckdb_time_struct`).\n\n time: The time object, as obtained from a `DUCKDB_TYPE_TIME` column.\n returns: The `duckdb_time_struct` with the decomposed elements."] pub fn duckdb_from_time (time : duckdb_time) -> duckdb_time_struct ; } extern "C" { # [doc = "Create a `duckdb_time_tz` object from micros and a timezone offset.\n\n micros: The microsecond component of the time.\n offset: The timezone offset component of the time.\n returns: The `duckdb_time_tz` element."] pub fn duckdb_create_time_tz (micros : i64 , offset : i32) -> duckdb_time_tz ; } extern "C" { # [doc = "Decompose a TIME_TZ objects into micros and a timezone offset.\n\nUse `duckdb_from_time` to further decompose the micros into hour, minute, second and microsecond.\n\n micros: The time object, as obtained from a `DUCKDB_TYPE_TIME_TZ` column.\n out_micros: The microsecond component of the time.\n out_offset: The timezone offset component of the time."] pub fn duckdb_from_time_tz (micros : duckdb_time_tz) -> duckdb_time_tz_struct ; } extern "C" { # [doc = "Re-compose a `duckdb_time` from hour, minute, second and microsecond (`duckdb_time_struct`).\n\n time: The hour, minute, second and microsecond in a `duckdb_time_struct`.\n returns: The `duckdb_time` element."] pub fn duckdb_to_time (time : duckdb_time_struct) -> duckdb_time ; } extern "C" { # [doc = "Decompose a `duckdb_timestamp` object into a `duckdb_timestamp_struct`.\n\n ts: The ts object, as obtained from a `DUCKDB_TYPE_TIMESTAMP` column.\n returns: The `duckdb_timestamp_struct` with the decomposed elements."] pub fn duckdb_from_timestamp (ts : duckdb_timestamp) -> duckdb_timestamp_struct ; } extern "C" { # [doc = "Re-compose a `duckdb_timestamp` from a duckdb_timestamp_struct.\n\n ts: The de-composed elements in a `duckdb_timestamp_struct`.\n returns: The `duckdb_timestamp` element."] pub fn duckdb_to_timestamp (ts : duckdb_timestamp_struct) -> duckdb_timestamp ; } extern "C" { # [doc = "Test a `duckdb_timestamp` to see if it is a finite value.\n\n ts: The timestamp object, as obtained from a `DUCKDB_TYPE_TIMESTAMP` column.\n returns: True if the timestamp is finite, false if it is ±infinity."] pub fn duckdb_is_finite_timestamp (ts : duckdb_timestamp) -> bool ; } extern "C" { # [doc = "Converts a duckdb_hugeint object (as obtained from a `DUCKDB_TYPE_HUGEINT` column) into a double.\n\n val: The hugeint value.\n returns: The converted `double` element."] pub fn duckdb_hugeint_to_double (val : duckdb_hugeint) -> f64 ; } extern "C" { # [doc = "Converts a double value to a duckdb_hugeint object.\n\nIf the conversion fails because the double value is too big the result will be 0.\n\n val: The double value.\n returns: The converted `duckdb_hugeint` element."] pub fn duckdb_double_to_hugeint (val : f64) -> duckdb_hugeint ; } extern "C" { # [doc = "Converts a duckdb_uhugeint object (as obtained from a `DUCKDB_TYPE_UHUGEINT` column) into a double.\n\n val: The uhugeint value.\n returns: The converted `double` element."] pub fn duckdb_uhugeint_to_double (val : duckdb_uhugeint) -> f64 ; } extern "C" { # [doc = "Converts a double value to a duckdb_uhugeint object.\n\nIf the conversion fails because the double value is too big the result will be 0.\n\n val: The double value.\n returns: The converted `duckdb_uhugeint` element."] pub fn duckdb_double_to_uhugeint (val : f64) -> duckdb_uhugeint ; } extern "C" { # [doc = "Converts a double value to a duckdb_decimal object.\n\nIf the conversion fails because the double value is too big, or the width/scale are invalid the result will be 0.\n\n val: The double value.\n returns: The converted `duckdb_decimal` element."] pub fn duckdb_double_to_decimal (val : f64 , width : u8 , scale : u8) -> duckdb_decimal ; } extern "C" { # [doc = "Converts a duckdb_decimal object (as obtained from a `DUCKDB_TYPE_DECIMAL` column) into a double.\n\n val: The decimal value.\n returns: The converted `double` element."] pub fn duckdb_decimal_to_double (val : duckdb_decimal) -> f64 ; } extern "C" { # [doc = "Create a prepared statement object from a query.\n\nNote that after calling `duckdb_prepare`, the prepared statement should always be destroyed using\n`duckdb_destroy_prepare`, even if the prepare fails.\n\nIf the prepare fails, `duckdb_prepare_error` can be called to obtain the reason why the prepare failed.\n\n connection: The connection object\n query: The SQL query to prepare\n out_prepared_statement: The resulting prepared statement object\n returns: `DuckDBSuccess` on success or `DuckDBError` on failure."] pub fn duckdb_prepare (connection : duckdb_connection , query : * const :: std :: os :: raw :: c_char , out_prepared_statement : * mut duckdb_prepared_statement) -> duckdb_state ; } extern "C" { # [doc = "Closes the prepared statement and de-allocates all memory allocated for the statement.\n\n prepared_statement: The prepared statement to destroy."] pub fn duckdb_destroy_prepare (prepared_statement : * mut duckdb_prepared_statement) ; } extern "C" { # [doc = "Returns the error message associated with the given prepared statement.\nIf the prepared statement has no error message, this returns `nullptr` instead.\n\nThe error message should not be freed. It will be de-allocated when `duckdb_destroy_prepare` is called.\n\n prepared_statement: The prepared statement to obtain the error from.\n returns: The error message, or `nullptr` if there is none."] pub fn duckdb_prepare_error (prepared_statement : duckdb_prepared_statement) -> * const :: std :: os :: raw :: c_char ; } extern "C" { # [doc = "Returns the number of parameters that can be provided to the given prepared statement.\n\nReturns 0 if the query was not successfully prepared.\n\n prepared_statement: The prepared statement to obtain the number of parameters for."] pub fn duckdb_nparams (prepared_statement : duckdb_prepared_statement) -> idx_t ; } extern "C" { # [doc = "Returns the name used to identify the parameter\nThe returned string should be freed using `duckdb_free`.\n\nReturns NULL if the index is out of range for the provided prepared statement.\n\n prepared_statement: The prepared statement for which to get the parameter name from."] pub fn duckdb_parameter_name (prepared_statement : duckdb_prepared_statement , index : idx_t) -> * const :: std :: os :: raw :: c_char ; } extern "C" { # [doc = "Returns the parameter type for the parameter at the given index.\n\nReturns `DUCKDB_TYPE_INVALID` if the parameter index is out of range or the statement was not successfully prepared.\n\n prepared_statement: The prepared statement.\n param_idx: The parameter index.\n returns: The parameter type"] pub fn duckdb_param_type (prepared_statement : duckdb_prepared_statement , param_idx : idx_t) -> duckdb_type ; } extern "C" { # [doc = "Clear the params bind to the prepared statement."] pub fn duckdb_clear_bindings (prepared_statement : duckdb_prepared_statement) -> duckdb_state ; } extern "C" { # [doc = "Returns the statement type of the statement to be executed\n\n statement: The prepared statement.\n returns: duckdb_statement_type value or DUCKDB_STATEMENT_TYPE_INVALID"] pub fn duckdb_prepared_statement_type (statement : duckdb_prepared_statement) -> duckdb_statement_type ; } extern "C" { # [doc = "Binds a value to the prepared statement at the specified index."] pub fn duckdb_bind_value (prepared_statement : duckdb_prepared_statement , param_idx : idx_t , val : duckdb_value) -> duckdb_state ; } extern "C" { # [doc = "Retrieve the index of the parameter for the prepared statement, identified by name"] pub fn duckdb_bind_parameter_index (prepared_statement : duckdb_prepared_statement , param_idx_out : * mut idx_t , name : * const :: std :: os :: raw :: c_char) -> duckdb_state ; } extern "C" { # [doc = "Binds a bool value to the prepared statement at the specified index."] pub fn duckdb_bind_boolean (prepared_statement : duckdb_prepared_statement , param_idx : idx_t , val : bool) -> duckdb_state ; } extern "C" { # [doc = "Binds an int8_t value to the prepared statement at the specified index."] pub fn duckdb_bind_int8 (prepared_statement : duckdb_prepared_statement , param_idx : idx_t , val : i8) -> duckdb_state ; } extern "C" { # [doc = "Binds an int16_t value to the prepared statement at the specified index."] pub fn duckdb_bind_int16 (prepared_statement : duckdb_prepared_statement , param_idx : idx_t , val : i16) -> duckdb_state ; } extern "C" { # [doc = "Binds an int32_t value to the prepared statement at the specified index."] pub fn duckdb_bind_int32 (prepared_statement : duckdb_prepared_statement , param_idx : idx_t , val : i32) -> duckdb_state ; } extern "C" { # [doc = "Binds an int64_t value to the prepared statement at the specified index."] pub fn duckdb_bind_int64 (prepared_statement : duckdb_prepared_statement , param_idx : idx_t , val : i64) -> duckdb_state ; } extern "C" { # [doc = "Binds a duckdb_hugeint value to the prepared statement at the specified index."] pub fn duckdb_bind_hugeint (prepared_statement : duckdb_prepared_statement , param_idx : idx_t , val : duckdb_hugeint) -> duckdb_state ; } extern "C" { # [doc = "Binds an duckdb_uhugeint value to the prepared statement at the specified index."] pub fn duckdb_bind_uhugeint (prepared_statement : duckdb_prepared_statement , param_idx : idx_t , val : duckdb_uhugeint) -> duckdb_state ; } extern "C" { # [doc = "Binds a duckdb_decimal value to the prepared statement at the specified index."] pub fn duckdb_bind_decimal (prepared_statement : duckdb_prepared_statement , param_idx : idx_t , val : duckdb_decimal) -> duckdb_state ; } extern "C" { # [doc = "Binds an uint8_t value to the prepared statement at the specified index."] pub fn duckdb_bind_uint8 (prepared_statement : duckdb_prepared_statement , param_idx : idx_t , val : u8) -> duckdb_state ; } extern "C" { # [doc = "Binds an uint16_t value to the prepared statement at the specified index."] pub fn duckdb_bind_uint16 (prepared_statement : duckdb_prepared_statement , param_idx : idx_t , val : u16) -> duckdb_state ; } extern "C" { # [doc = "Binds an uint32_t value to the prepared statement at the specified index."] pub fn duckdb_bind_uint32 (prepared_statement : duckdb_prepared_statement , param_idx : idx_t , val : u32) -> duckdb_state ; } extern "C" { # [doc = "Binds an uint64_t value to the prepared statement at the specified index."] pub fn duckdb_bind_uint64 (prepared_statement : duckdb_prepared_statement , param_idx : idx_t , val : u64) -> duckdb_state ; } extern "C" { # [doc = "Binds a float value to the prepared statement at the specified index."] pub fn duckdb_bind_float (prepared_statement : duckdb_prepared_statement , param_idx : idx_t , val : f32) -> duckdb_state ; } extern "C" { # [doc = "Binds a double value to the prepared statement at the specified index."] pub fn duckdb_bind_double (prepared_statement : duckdb_prepared_statement , param_idx : idx_t , val : f64) -> duckdb_state ; } extern "C" { # [doc = "Binds a duckdb_date value to the prepared statement at the specified index."] pub fn duckdb_bind_date (prepared_statement : duckdb_prepared_statement , param_idx : idx_t , val : duckdb_date) -> duckdb_state ; } extern "C" { # [doc = "Binds a duckdb_time value to the prepared statement at the specified index."] pub fn duckdb_bind_time (prepared_statement : duckdb_prepared_statement , param_idx : idx_t , val : duckdb_time) -> duckdb_state ; } extern "C" { # [doc = "Binds a duckdb_timestamp value to the prepared statement at the specified index."] pub fn duckdb_bind_timestamp (prepared_statement : duckdb_prepared_statement , param_idx : idx_t , val : duckdb_timestamp) -> duckdb_state ; } extern "C" { # [doc = "Binds a duckdb_interval value to the prepared statement at the specified index."] pub fn duckdb_bind_interval (prepared_statement : duckdb_prepared_statement , param_idx : idx_t , val : duckdb_interval) -> duckdb_state ; } extern "C" { # [doc = "Binds a null-terminated varchar value to the prepared statement at the specified index."] pub fn duckdb_bind_varchar (prepared_statement : duckdb_prepared_statement , param_idx : idx_t , val : * const :: std :: os :: raw :: c_char) -> duckdb_state ; } extern "C" { # [doc = "Binds a varchar value to the prepared statement at the specified index."] pub fn duckdb_bind_varchar_length (prepared_statement : duckdb_prepared_statement , param_idx : idx_t , val : * const :: std :: os :: raw :: c_char , length : idx_t) -> duckdb_state ; } extern "C" { # [doc = "Binds a blob value to the prepared statement at the specified index."] pub fn duckdb_bind_blob (prepared_statement : duckdb_prepared_statement , param_idx : idx_t , data : * const :: std :: os :: raw :: c_void , length : idx_t) -> duckdb_state ; } extern "C" { # [doc = "Binds a NULL value to the prepared statement at the specified index."] pub fn duckdb_bind_null (prepared_statement : duckdb_prepared_statement , param_idx : idx_t) -> duckdb_state ; } extern "C" { # [doc = "Executes the prepared statement with the given bound parameters, and returns a materialized query result.\n\nThis method can be called multiple times for each prepared statement, and the parameters can be modified\nbetween calls to this function.\n\nNote that the result must be freed with `duckdb_destroy_result`.\n\n prepared_statement: The prepared statement to execute.\n out_result: The query result.\n returns: `DuckDBSuccess` on success or `DuckDBError` on failure."] pub fn duckdb_execute_prepared (prepared_statement : duckdb_prepared_statement , out_result : * mut duckdb_result) -> duckdb_state ; } extern "C" { # [doc = "DEPRECATION NOTICE**: This method is scheduled for removal in a future release.\n\nExecutes the prepared statement with the given bound parameters, and returns an optionally-streaming query result.\nTo determine if the resulting query was in fact streamed, use `duckdb_result_is_streaming`\n\nThis method can be called multiple times for each prepared statement, and the parameters can be modified\nbetween calls to this function.\n\nNote that the result must be freed with `duckdb_destroy_result`.\n\n prepared_statement: The prepared statement to execute.\n out_result: The query result.\n returns: `DuckDBSuccess` on success or `DuckDBError` on failure."] pub fn duckdb_execute_prepared_streaming (prepared_statement : duckdb_prepared_statement , out_result : * mut duckdb_result) -> duckdb_state ; } extern "C" { # [doc = "Extract all statements from a query.\nNote that after calling `duckdb_extract_statements`, the extracted statements should always be destroyed using\n`duckdb_destroy_extracted`, even if no statements were extracted.\n\nIf the extract fails, `duckdb_extract_statements_error` can be called to obtain the reason why the extract failed.\n\n connection: The connection object\n query: The SQL query to extract\n out_extracted_statements: The resulting extracted statements object\n returns: The number of extracted statements or 0 on failure."] pub fn duckdb_extract_statements (connection : duckdb_connection , query : * const :: std :: os :: raw :: c_char , out_extracted_statements : * mut duckdb_extracted_statements) -> idx_t ; } extern "C" { # [doc = "Prepare an extracted statement.\nNote that after calling `duckdb_prepare_extracted_statement`, the prepared statement should always be destroyed using\n`duckdb_destroy_prepare`, even if the prepare fails.\n\nIf the prepare fails, `duckdb_prepare_error` can be called to obtain the reason why the prepare failed.\n\n connection: The connection object\n extracted_statements: The extracted statements object\n index: The index of the extracted statement to prepare\n out_prepared_statement: The resulting prepared statement object\n returns: `DuckDBSuccess` on success or `DuckDBError` on failure."] pub fn duckdb_prepare_extracted_statement (connection : duckdb_connection , extracted_statements : duckdb_extracted_statements , index : idx_t , out_prepared_statement : * mut duckdb_prepared_statement) -> duckdb_state ; } extern "C" { # [doc = "Returns the error message contained within the extracted statements.\nThe result of this function must not be freed. It will be cleaned up when `duckdb_destroy_extracted` is called.\n\n result: The extracted statements to fetch the error from.\n returns: The error of the extracted statements."] pub fn duckdb_extract_statements_error (extracted_statements : duckdb_extracted_statements) -> * const :: std :: os :: raw :: c_char ; } extern "C" { # [doc = "De-allocates all memory allocated for the extracted statements.\n extracted_statements: The extracted statements to destroy."] pub fn duckdb_destroy_extracted (extracted_statements : * mut duckdb_extracted_statements) ; } extern "C" { # [doc = "Executes the prepared statement with the given bound parameters, and returns a pending result.\nThe pending result represents an intermediate structure for a query that is not yet fully executed.\nThe pending result can be used to incrementally execute a query, returning control to the client between tasks.\n\nNote that after calling `duckdb_pending_prepared`, the pending result should always be destroyed using\n`duckdb_destroy_pending`, even if this function returns DuckDBError.\n\n prepared_statement: The prepared statement to execute.\n out_result: The pending query result.\n returns: `DuckDBSuccess` on success or `DuckDBError` on failure."] pub fn duckdb_pending_prepared (prepared_statement : duckdb_prepared_statement , out_result : * mut duckdb_pending_result) -> duckdb_state ; } extern "C" { # [doc = "DEPRECATION NOTICE**: This method is scheduled for removal in a future release.\n\nExecutes the prepared statement with the given bound parameters, and returns a pending result.\nThis pending result will create a streaming duckdb_result when executed.\nThe pending result represents an intermediate structure for a query that is not yet fully executed.\n\nNote that after calling `duckdb_pending_prepared_streaming`, the pending result should always be destroyed using\n`duckdb_destroy_pending`, even if this function returns DuckDBError.\n\n prepared_statement: The prepared statement to execute.\n out_result: The pending query result.\n returns: `DuckDBSuccess` on success or `DuckDBError` on failure."] pub fn duckdb_pending_prepared_streaming (prepared_statement : duckdb_prepared_statement , out_result : * mut duckdb_pending_result) -> duckdb_state ; } extern "C" { # [doc = "Closes the pending result and de-allocates all memory allocated for the result.\n\n pending_result: The pending result to destroy."] pub fn duckdb_destroy_pending (pending_result : * mut duckdb_pending_result) ; } extern "C" { # [doc = "Returns the error message contained within the pending result.\n\nThe result of this function must not be freed. It will be cleaned up when `duckdb_destroy_pending` is called.\n\n result: The pending result to fetch the error from.\n returns: The error of the pending result."] pub fn duckdb_pending_error (pending_result : duckdb_pending_result) -> * const :: std :: os :: raw :: c_char ; } extern "C" { # [doc = "Executes a single task within the query, returning whether or not the query is ready.\n\nIf this returns DUCKDB_PENDING_RESULT_READY, the duckdb_execute_pending function can be called to obtain the result.\nIf this returns DUCKDB_PENDING_RESULT_NOT_READY, the duckdb_pending_execute_task function should be called again.\nIf this returns DUCKDB_PENDING_ERROR, an error occurred during execution.\n\nThe error message can be obtained by calling duckdb_pending_error on the pending_result.\n\n pending_result: The pending result to execute a task within.\n returns: The state of the pending result after the execution."] pub fn duckdb_pending_execute_task (pending_result : duckdb_pending_result) -> duckdb_pending_state ; } extern "C" { # [doc = "If this returns DUCKDB_PENDING_RESULT_READY, the duckdb_execute_pending function can be called to obtain the result.\nIf this returns DUCKDB_PENDING_RESULT_NOT_READY, the duckdb_pending_execute_check_state function should be called again.\nIf this returns DUCKDB_PENDING_ERROR, an error occurred during execution.\n\nThe error message can be obtained by calling duckdb_pending_error on the pending_result.\n\n pending_result: The pending result.\n returns: The state of the pending result."] pub fn duckdb_pending_execute_check_state (pending_result : duckdb_pending_result) -> duckdb_pending_state ; } extern "C" { # [doc = "Fully execute a pending query result, returning the final query result.\n\nIf duckdb_pending_execute_task has been called until DUCKDB_PENDING_RESULT_READY was returned, this will return fast.\nOtherwise, all remaining tasks must be executed first.\n\nNote that the result must be freed with `duckdb_destroy_result`.\n\n pending_result: The pending result to execute.\n out_result: The result object.\n returns: `DuckDBSuccess` on success or `DuckDBError` on failure."] pub fn duckdb_execute_pending (pending_result : duckdb_pending_result , out_result : * mut duckdb_result) -> duckdb_state ; } extern "C" { # [doc = "Returns whether a duckdb_pending_state is finished executing. For example if `pending_state` is\nDUCKDB_PENDING_RESULT_READY, this function will return true.\n\n pending_state: The pending state on which to decide whether to finish execution.\n returns: Boolean indicating pending execution should be considered finished."] pub fn duckdb_pending_execution_is_finished (pending_state : duckdb_pending_state) -> bool ; } extern "C" { # [doc = "Destroys the value and de-allocates all memory allocated for that type.\n\n value: The value to destroy."] pub fn duckdb_destroy_value (value : * mut duckdb_value) ; } extern "C" { # [doc = "Creates a value from a null-terminated string\n\n value: The null-terminated string\n returns: The value. This must be destroyed with `duckdb_destroy_value`."] pub fn duckdb_create_varchar (text : * const :: std :: os :: raw :: c_char) -> duckdb_value ; } extern "C" { # [doc = "Creates a value from a string\n\n value: The text\n length: The length of the text\n returns: The value. This must be destroyed with `duckdb_destroy_value`."] pub fn duckdb_create_varchar_length (text : * const :: std :: os :: raw :: c_char , length : idx_t) -> duckdb_value ; } extern "C" { # [doc = "Creates a value from an int64\n\n value: The bigint value\n returns: The value. This must be destroyed with `duckdb_destroy_value`."] pub fn duckdb_create_int64 (val : i64) -> duckdb_value ; } extern "C" { # [doc = "Creates a struct value from a type and an array of values\n\n type: The type of the struct\n values: The values for the struct fields\n returns: The value. This must be destroyed with `duckdb_destroy_value`."] pub fn duckdb_create_struct_value (type_ : duckdb_logical_type , values : * mut duckdb_value) -> duckdb_value ; } extern "C" { # [doc = "Creates a list value from a type and an array of values of length `value_count`\n\n type: The type of the list\n values: The values for the list\n value_count: The number of values in the list\n returns: The value. This must be destroyed with `duckdb_destroy_value`."] pub fn duckdb_create_list_value (type_ : duckdb_logical_type , values : * mut duckdb_value , value_count : idx_t) -> duckdb_value ; } extern "C" { # [doc = "Creates a array value from a type and an array of values of length `value_count`\n\n type: The type of the array\n values: The values for the array\n value_count: The number of values in the array\n returns: The value. This must be destroyed with `duckdb_destroy_value`."] pub fn duckdb_create_array_value (type_ : duckdb_logical_type , values : * mut duckdb_value , value_count : idx_t) -> duckdb_value ; } extern "C" { # [doc = "Obtains a string representation of the given value.\nThe result must be destroyed with `duckdb_free`.\n\n value: The value\n returns: The string value. This must be destroyed with `duckdb_free`."] pub fn duckdb_get_varchar (value : duckdb_value) -> * mut :: std :: os :: raw :: c_char ; } extern "C" { # [doc = "Obtains an int64 of the given value.\n\n value: The value\n returns: The int64 value, or 0 if no conversion is possible"] pub fn duckdb_get_int64 (value : duckdb_value) -> i64 ; } extern "C" { # [doc = "Creates a `duckdb_logical_type` from a standard primitive type.\nThe resulting type should be destroyed with `duckdb_destroy_logical_type`.\n\nThis should not be used with `DUCKDB_TYPE_DECIMAL`.\n\n type: The primitive type to create.\n returns: The logical type."] pub fn duckdb_create_logical_type (type_ : duckdb_type) -> duckdb_logical_type ; } extern "C" { # [doc = "Returns the alias of a duckdb_logical_type, if one is set, else `NULL`.\nThe result must be destroyed with `duckdb_free`.\n\n type: The logical type to return the alias of\n returns: The alias or `NULL`"] pub fn duckdb_logical_type_get_alias (type_ : duckdb_logical_type) -> * mut :: std :: os :: raw :: c_char ; } extern "C" { # [doc = "Creates a list type from its child type.\nThe resulting type should be destroyed with `duckdb_destroy_logical_type`.\n\n type: The child type of list type to create.\n returns: The logical type."] pub fn duckdb_create_list_type (type_ : duckdb_logical_type) -> duckdb_logical_type ; } extern "C" { # [doc = "Creates a array type from its child type.\nThe resulting type should be destroyed with `duckdb_destroy_logical_type`.\n\n type: The child type of array type to create.\n array_size: The number of elements in the array.\n returns: The logical type."] pub fn duckdb_create_array_type (type_ : duckdb_logical_type , array_size : idx_t) -> duckdb_logical_type ; } extern "C" { # [doc = "Creates a map type from its key type and value type.\nThe resulting type should be destroyed with `duckdb_destroy_logical_type`.\n\n type: The key type and value type of map type to create.\n returns: The logical type."] pub fn duckdb_create_map_type (key_type : duckdb_logical_type , value_type : duckdb_logical_type) -> duckdb_logical_type ; } extern "C" { # [doc = "Creates a UNION type from the passed types array.\nThe resulting type should be destroyed with `duckdb_destroy_logical_type`.\n\n types: The array of types that the union should consist of.\n type_amount: The size of the types array.\n returns: The logical type."] pub fn duckdb_create_union_type (member_types : * mut duckdb_logical_type , member_names : * mut * const :: std :: os :: raw :: c_char , member_count : idx_t) -> duckdb_logical_type ; } extern "C" { # [doc = "Creates a STRUCT type from the passed member name and type arrays.\nThe resulting type should be destroyed with `duckdb_destroy_logical_type`.\n\n member_types: The array of types that the struct should consist of.\n member_names: The array of names that the struct should consist of.\n member_count: The number of members that were specified for both arrays.\n returns: The logical type."] pub fn duckdb_create_struct_type (member_types : * mut duckdb_logical_type , member_names : * mut * const :: std :: os :: raw :: c_char , member_count : idx_t) -> duckdb_logical_type ; } extern "C" { # [doc = "Creates an ENUM type from the passed member name array.\nThe resulting type should be destroyed with `duckdb_destroy_logical_type`.\n\n enum_name: The name of the enum.\n member_names: The array of names that the enum should consist of.\n member_count: The number of elements that were specified in the array.\n returns: The logical type."] pub fn duckdb_create_enum_type (member_names : * mut * const :: std :: os :: raw :: c_char , member_count : idx_t) -> duckdb_logical_type ; } extern "C" { # [doc = "Creates a `duckdb_logical_type` of type decimal with the specified width and scale.\nThe resulting type should be destroyed with `duckdb_destroy_logical_type`.\n\n width: The width of the decimal type\n scale: The scale of the decimal type\n returns: The logical type."] pub fn duckdb_create_decimal_type (width : u8 , scale : u8) -> duckdb_logical_type ; } extern "C" { # [doc = "Retrieves the enum type class of a `duckdb_logical_type`.\n\n type: The logical type object\n returns: The type id"] pub fn duckdb_get_type_id (type_ : duckdb_logical_type) -> duckdb_type ; } extern "C" { # [doc = "Retrieves the width of a decimal type.\n\n type: The logical type object\n returns: The width of the decimal type"] pub fn duckdb_decimal_width (type_ : duckdb_logical_type) -> u8 ; } extern "C" { # [doc = "Retrieves the scale of a decimal type.\n\n type: The logical type object\n returns: The scale of the decimal type"] pub fn duckdb_decimal_scale (type_ : duckdb_logical_type) -> u8 ; } extern "C" { # [doc = "Retrieves the internal storage type of a decimal type.\n\n type: The logical type object\n returns: The internal type of the decimal type"] pub fn duckdb_decimal_internal_type (type_ : duckdb_logical_type) -> duckdb_type ; } extern "C" { # [doc = "Retrieves the internal storage type of an enum type.\n\n type: The logical type object\n returns: The internal type of the enum type"] pub fn duckdb_enum_internal_type (type_ : duckdb_logical_type) -> duckdb_type ; } extern "C" { # [doc = "Retrieves the dictionary size of the enum type.\n\n type: The logical type object\n returns: The dictionary size of the enum type"] pub fn duckdb_enum_dictionary_size (type_ : duckdb_logical_type) -> u32 ; } extern "C" { # [doc = "Retrieves the dictionary value at the specified position from the enum.\n\nThe result must be freed with `duckdb_free`.\n\n type: The logical type object\n index: The index in the dictionary\n returns: The string value of the enum type. Must be freed with `duckdb_free`."] pub fn duckdb_enum_dictionary_value (type_ : duckdb_logical_type , index : idx_t) -> * mut :: std :: os :: raw :: c_char ; } extern "C" { # [doc = "Retrieves the child type of the given list type.\n\nThe result must be freed with `duckdb_destroy_logical_type`.\n\n type: The logical type object\n returns: The child type of the list type. Must be destroyed with `duckdb_destroy_logical_type`."] pub fn duckdb_list_type_child_type (type_ : duckdb_logical_type) -> duckdb_logical_type ; } extern "C" { # [doc = "Retrieves the child type of the given array type.\n\nThe result must be freed with `duckdb_destroy_logical_type`.\n\n type: The logical type object\n returns: The child type of the array type. Must be destroyed with `duckdb_destroy_logical_type`."] pub fn duckdb_array_type_child_type (type_ : duckdb_logical_type) -> duckdb_logical_type ; } extern "C" { # [doc = "Retrieves the array size of the given array type.\n\n type: The logical type object\n returns: The fixed number of elements the values of this array type can store."] pub fn duckdb_array_type_array_size (type_ : duckdb_logical_type) -> idx_t ; } extern "C" { # [doc = "Retrieves the key type of the given map type.\n\nThe result must be freed with `duckdb_destroy_logical_type`.\n\n type: The logical type object\n returns: The key type of the map type. Must be destroyed with `duckdb_destroy_logical_type`."] pub fn duckdb_map_type_key_type (type_ : duckdb_logical_type) -> duckdb_logical_type ; } extern "C" { # [doc = "Retrieves the value type of the given map type.\n\nThe result must be freed with `duckdb_destroy_logical_type`.\n\n type: The logical type object\n returns: The value type of the map type. Must be destroyed with `duckdb_destroy_logical_type`."] pub fn duckdb_map_type_value_type (type_ : duckdb_logical_type) -> duckdb_logical_type ; } extern "C" { # [doc = "Returns the number of children of a struct type.\n\n type: The logical type object\n returns: The number of children of a struct type."] pub fn duckdb_struct_type_child_count (type_ : duckdb_logical_type) -> idx_t ; } extern "C" { # [doc = "Retrieves the name of the struct child.\n\nThe result must be freed with `duckdb_free`.\n\n type: The logical type object\n index: The child index\n returns: The name of the struct type. Must be freed with `duckdb_free`."] pub fn duckdb_struct_type_child_name (type_ : duckdb_logical_type , index : idx_t) -> * mut :: std :: os :: raw :: c_char ; } extern "C" { # [doc = "Retrieves the child type of the given struct type at the specified index.\n\nThe result must be freed with `duckdb_destroy_logical_type`.\n\n type: The logical type object\n index: The child index\n returns: The child type of the struct type. Must be destroyed with `duckdb_destroy_logical_type`."] pub fn duckdb_struct_type_child_type (type_ : duckdb_logical_type , index : idx_t) -> duckdb_logical_type ; } extern "C" { # [doc = "Returns the number of members that the union type has.\n\n type: The logical type (union) object\n returns: The number of members of a union type."] pub fn duckdb_union_type_member_count (type_ : duckdb_logical_type) -> idx_t ; } extern "C" { # [doc = "Retrieves the name of the union member.\n\nThe result must be freed with `duckdb_free`.\n\n type: The logical type object\n index: The child index\n returns: The name of the union member. Must be freed with `duckdb_free`."] pub fn duckdb_union_type_member_name (type_ : duckdb_logical_type , index : idx_t) -> * mut :: std :: os :: raw :: c_char ; } extern "C" { # [doc = "Retrieves the child type of the given union member at the specified index.\n\nThe result must be freed with `duckdb_destroy_logical_type`.\n\n type: The logical type object\n index: The child index\n returns: The child type of the union member. Must be destroyed with `duckdb_destroy_logical_type`."] pub fn duckdb_union_type_member_type (type_ : duckdb_logical_type , index : idx_t) -> duckdb_logical_type ; } extern "C" { # [doc = "Destroys the logical type and de-allocates all memory allocated for that type.\n\n type: The logical type to destroy."] pub fn duckdb_destroy_logical_type (type_ : * mut duckdb_logical_type) ; } extern "C" { # [doc = "Creates an empty DataChunk with the specified set of types.\n\nNote that the result must be destroyed with `duckdb_destroy_data_chunk`.\n\n types: An array of types of the data chunk.\n column_count: The number of columns.\n returns: The data chunk."] pub fn duckdb_create_data_chunk (types : * mut duckdb_logical_type , column_count : idx_t) -> duckdb_data_chunk ; } extern "C" { # [doc = "Destroys the data chunk and de-allocates all memory allocated for that chunk.\n\n chunk: The data chunk to destroy."] pub fn duckdb_destroy_data_chunk (chunk : * mut duckdb_data_chunk) ; } extern "C" { # [doc = "Resets a data chunk, clearing the validity masks and setting the cardinality of the data chunk to 0.\n\n chunk: The data chunk to reset."] pub fn duckdb_data_chunk_reset (chunk : duckdb_data_chunk) ; } extern "C" { # [doc = "Retrieves the number of columns in a data chunk.\n\n chunk: The data chunk to get the data from\n returns: The number of columns in the data chunk"] pub fn duckdb_data_chunk_get_column_count (chunk : duckdb_data_chunk) -> idx_t ; } extern "C" { # [doc = "Retrieves the vector at the specified column index in the data chunk.\n\nThe pointer to the vector is valid for as long as the chunk is alive.\nIt does NOT need to be destroyed.\n\n chunk: The data chunk to get the data from\n returns: The vector"] pub fn duckdb_data_chunk_get_vector (chunk : duckdb_data_chunk , col_idx : idx_t) -> duckdb_vector ; } extern "C" { # [doc = "Retrieves the current number of tuples in a data chunk.\n\n chunk: The data chunk to get the data from\n returns: The number of tuples in the data chunk"] pub fn duckdb_data_chunk_get_size (chunk : duckdb_data_chunk) -> idx_t ; } extern "C" { # [doc = "Sets the current number of tuples in a data chunk.\n\n chunk: The data chunk to set the size in\n size: The number of tuples in the data chunk"] pub fn duckdb_data_chunk_set_size (chunk : duckdb_data_chunk , size : idx_t) ; } extern "C" { # [doc = "Retrieves the column type of the specified vector.\n\nThe result must be destroyed with `duckdb_destroy_logical_type`.\n\n vector: The vector get the data from\n returns: The type of the vector"] pub fn duckdb_vector_get_column_type (vector : duckdb_vector) -> duckdb_logical_type ; } extern "C" { # [doc = "Retrieves the data pointer of the vector.\n\nThe data pointer can be used to read or write values from the vector.\nHow to read or write values depends on the type of the vector.\n\n vector: The vector to get the data from\n returns: The data pointer"] pub fn duckdb_vector_get_data (vector : duckdb_vector) -> * mut :: std :: os :: raw :: c_void ; } extern "C" { # [doc = "Retrieves the validity mask pointer of the specified vector.\n\nIf all values are valid, this function MIGHT return NULL!\n\nThe validity mask is a bitset that signifies null-ness within the data chunk.\nIt is a series of uint64_t values, where each uint64_t value contains validity for 64 tuples.\nThe bit is set to 1 if the value is valid (i.e. not NULL) or 0 if the value is invalid (i.e. NULL).\n\nValidity of a specific value can be obtained like this:\n\nidx_t entry_idx = row_idx / 64;\nidx_t idx_in_entry = row_idx % 64;\nbool is_valid = validity_mask[entry_idx] & (1 << idx_in_entry);\n\nAlternatively, the (slower) duckdb_validity_row_is_valid function can be used.\n\n vector: The vector to get the data from\n returns: The pointer to the validity mask, or NULL if no validity mask is present"] pub fn duckdb_vector_get_validity (vector : duckdb_vector) -> * mut u64 ; } extern "C" { # [doc = "Ensures the validity mask is writable by allocating it.\n\nAfter this function is called, `duckdb_vector_get_validity` will ALWAYS return non-NULL.\nThis allows null values to be written to the vector, regardless of whether a validity mask was present before.\n\n vector: The vector to alter"] pub fn duckdb_vector_ensure_validity_writable (vector : duckdb_vector) ; } extern "C" { # [doc = "Assigns a string element in the vector at the specified location.\n\n vector: The vector to alter\n index: The row position in the vector to assign the string to\n str: The null-terminated string"] pub fn duckdb_vector_assign_string_element (vector : duckdb_vector , index : idx_t , str_ : * const :: std :: os :: raw :: c_char) ; } extern "C" { # [doc = "Assigns a string element in the vector at the specified location. You may also use this function to assign BLOBs.\n\n vector: The vector to alter\n index: The row position in the vector to assign the string to\n str: The string\n str_len: The length of the string (in bytes)"] pub fn duckdb_vector_assign_string_element_len (vector : duckdb_vector , index : idx_t , str_ : * const :: std :: os :: raw :: c_char , str_len : idx_t) ; } extern "C" { # [doc = "Retrieves the child vector of a list vector.\n\nThe resulting vector is valid as long as the parent vector is valid.\n\n vector: The vector\n returns: The child vector"] pub fn duckdb_list_vector_get_child (vector : duckdb_vector) -> duckdb_vector ; } extern "C" { # [doc = "Returns the size of the child vector of the list.\n\n vector: The vector\n returns: The size of the child list"] pub fn duckdb_list_vector_get_size (vector : duckdb_vector) -> idx_t ; } extern "C" { # [doc = "Sets the total size of the underlying child-vector of a list vector.\n\n vector: The list vector.\n size: The size of the child list.\n returns: The duckdb state. Returns DuckDBError if the vector is nullptr."] pub fn duckdb_list_vector_set_size (vector : duckdb_vector , size : idx_t) -> duckdb_state ; } extern "C" { # [doc = "Sets the total capacity of the underlying child-vector of a list.\n\n vector: The list vector.\n required_capacity: the total capacity to reserve.\n return: The duckdb state. Returns DuckDBError if the vector is nullptr."] pub fn duckdb_list_vector_reserve (vector : duckdb_vector , required_capacity : idx_t) -> duckdb_state ; } extern "C" { # [doc = "Retrieves the child vector of a struct vector.\n\nThe resulting vector is valid as long as the parent vector is valid.\n\n vector: The vector\n index: The child index\n returns: The child vector"] pub fn duckdb_struct_vector_get_child (vector : duckdb_vector , index : idx_t) -> duckdb_vector ; } extern "C" { # [doc = "Retrieves the child vector of a array vector.\n\nThe resulting vector is valid as long as the parent vector is valid.\nThe resulting vector has the size of the parent vector multiplied by the array size.\n\n vector: The vector\n returns: The child vector"] pub fn duckdb_array_vector_get_child (vector : duckdb_vector) -> duckdb_vector ; } extern "C" { # [doc = "Returns whether or not a row is valid (i.e. not NULL) in the given validity mask.\n\n validity: The validity mask, as obtained through `duckdb_vector_get_validity`\n row: The row index\n returns: true if the row is valid, false otherwise"] pub fn duckdb_validity_row_is_valid (validity : * mut u64 , row : idx_t) -> bool ; } extern "C" { # [doc = "In a validity mask, sets a specific row to either valid or invalid.\n\nNote that `duckdb_vector_ensure_validity_writable` should be called before calling `duckdb_vector_get_validity`,\nto ensure that there is a validity mask to write to.\n\n validity: The validity mask, as obtained through `duckdb_vector_get_validity`.\n row: The row index\n valid: Whether or not to set the row to valid, or invalid"] pub fn duckdb_validity_set_row_validity (validity : * mut u64 , row : idx_t , valid : bool) ; } extern "C" { # [doc = "In a validity mask, sets a specific row to invalid.\n\nEquivalent to `duckdb_validity_set_row_validity` with valid set to false.\n\n validity: The validity mask\n row: The row index"] pub fn duckdb_validity_set_row_invalid (validity : * mut u64 , row : idx_t) ; } extern "C" { # [doc = "In a validity mask, sets a specific row to valid.\n\nEquivalent to `duckdb_validity_set_row_validity` with valid set to true.\n\n validity: The validity mask\n row: The row index"] pub fn duckdb_validity_set_row_valid (validity : * mut u64 , row : idx_t) ; } extern "C" { # [doc = "Creates a new empty table function.\n\nThe return value should be destroyed with `duckdb_destroy_table_function`.\n\n returns: The table function object."] pub fn duckdb_create_table_function () -> duckdb_table_function ; } extern "C" { # [doc = "Destroys the given table function object.\n\n table_function: The table function to destroy"] pub fn duckdb_destroy_table_function (table_function : * mut duckdb_table_function) ; } extern "C" { # [doc = "Sets the name of the given table function.\n\n table_function: The table function\n name: The name of the table function"] pub fn duckdb_table_function_set_name (table_function : duckdb_table_function , name : * const :: std :: os :: raw :: c_char) ; } extern "C" { # [doc = "Adds a parameter to the table function.\n\n table_function: The table function\n type: The type of the parameter to add."] pub fn duckdb_table_function_add_parameter (table_function : duckdb_table_function , type_ : duckdb_logical_type) ; } extern "C" { # [doc = "Adds a named parameter to the table function.\n\n table_function: The table function\n name: The name of the parameter\n type: The type of the parameter to add."] pub fn duckdb_table_function_add_named_parameter (table_function : duckdb_table_function , name : * const :: std :: os :: raw :: c_char , type_ : duckdb_logical_type) ; } extern "C" { # [doc = "Assigns extra information to the table function that can be fetched during binding, etc.\n\n table_function: The table function\n extra_info: The extra information\n destroy: The callback that will be called to destroy the bind data (if any)"] pub fn duckdb_table_function_set_extra_info (table_function : duckdb_table_function , extra_info : * mut :: std :: os :: raw :: c_void , destroy : duckdb_delete_callback_t) ; } extern "C" { # [doc = "Sets the bind function of the table function.\n\n table_function: The table function\n bind: The bind function"] pub fn duckdb_table_function_set_bind (table_function : duckdb_table_function , bind : duckdb_table_function_bind_t) ; } extern "C" { # [doc = "Sets the init function of the table function.\n\n table_function: The table function\n init: The init function"] pub fn duckdb_table_function_set_init (table_function : duckdb_table_function , init : duckdb_table_function_init_t) ; } extern "C" { # [doc = "Sets the thread-local init function of the table function.\n\n table_function: The table function\n init: The init function"] pub fn duckdb_table_function_set_local_init (table_function : duckdb_table_function , init : duckdb_table_function_init_t) ; } extern "C" { # [doc = "Sets the main function of the table function.\n\n table_function: The table function\n function: The function"] pub fn duckdb_table_function_set_function (table_function : duckdb_table_function , function : duckdb_table_function_t) ; } extern "C" { # [doc = "Sets whether or not the given table function supports projection pushdown.\n\nIf this is set to true, the system will provide a list of all required columns in the `init` stage through\nthe `duckdb_init_get_column_count` and `duckdb_init_get_column_index` functions.\nIf this is set to false (the default), the system will expect all columns to be projected.\n\n table_function: The table function\n pushdown: True if the table function supports projection pushdown, false otherwise."] pub fn duckdb_table_function_supports_projection_pushdown (table_function : duckdb_table_function , pushdown : bool) ; } extern "C" { # [doc = "Register the table function object within the given connection.\n\nThe function requires at least a name, a bind function, an init function and a main function.\n\nIf the function is incomplete or a function with this name already exists DuckDBError is returned.\n\n con: The connection to register it in.\n function: The function pointer\n returns: Whether or not the registration was successful."] pub fn duckdb_register_table_function (con : duckdb_connection , function : duckdb_table_function) -> duckdb_state ; } extern "C" { # [doc = "Retrieves the extra info of the function as set in `duckdb_table_function_set_extra_info`.\n\n info: The info object\n returns: The extra info"] pub fn duckdb_bind_get_extra_info (info : duckdb_bind_info) -> * mut :: std :: os :: raw :: c_void ; } extern "C" { # [doc = "Adds a result column to the output of the table function.\n\n info: The info object\n name: The name of the column\n type: The logical type of the column"] pub fn duckdb_bind_add_result_column (info : duckdb_bind_info , name : * const :: std :: os :: raw :: c_char , type_ : duckdb_logical_type) ; } extern "C" { # [doc = "Retrieves the number of regular (non-named) parameters to the function.\n\n info: The info object\n returns: The number of parameters"] pub fn duckdb_bind_get_parameter_count (info : duckdb_bind_info) -> idx_t ; } extern "C" { # [doc = "Retrieves the parameter at the given index.\n\nThe result must be destroyed with `duckdb_destroy_value`.\n\n info: The info object\n index: The index of the parameter to get\n returns: The value of the parameter. Must be destroyed with `duckdb_destroy_value`."] pub fn duckdb_bind_get_parameter (info : duckdb_bind_info , index : idx_t) -> duckdb_value ; } extern "C" { # [doc = "Retrieves a named parameter with the given name.\n\nThe result must be destroyed with `duckdb_destroy_value`.\n\n info: The info object\n name: The name of the parameter\n returns: The value of the parameter. Must be destroyed with `duckdb_destroy_value`."] pub fn duckdb_bind_get_named_parameter (info : duckdb_bind_info , name : * const :: std :: os :: raw :: c_char) -> duckdb_value ; } extern "C" { # [doc = "Sets the user-provided bind data in the bind object. This object can be retrieved again during execution.\n\n info: The info object\n extra_data: The bind data object.\n destroy: The callback that will be called to destroy the bind data (if any)"] pub fn duckdb_bind_set_bind_data (info : duckdb_bind_info , bind_data : * mut :: std :: os :: raw :: c_void , destroy : duckdb_delete_callback_t) ; } extern "C" { # [doc = "Sets the cardinality estimate for the table function, used for optimization.\n\n info: The bind data object.\n is_exact: Whether or not the cardinality estimate is exact, or an approximation"] pub fn duckdb_bind_set_cardinality (info : duckdb_bind_info , cardinality : idx_t , is_exact : bool) ; } extern "C" { # [doc = "Report that an error has occurred while calling bind.\n\n info: The info object\n error: The error message"] pub fn duckdb_bind_set_error (info : duckdb_bind_info , error : * const :: std :: os :: raw :: c_char) ; } extern "C" { # [doc = "Retrieves the extra info of the function as set in `duckdb_table_function_set_extra_info`.\n\n info: The info object\n returns: The extra info"] pub fn duckdb_init_get_extra_info (info : duckdb_init_info) -> * mut :: std :: os :: raw :: c_void ; } extern "C" { # [doc = "Gets the bind data set by `duckdb_bind_set_bind_data` during the bind.\n\nNote that the bind data should be considered as read-only.\nFor tracking state, use the init data instead.\n\n info: The info object\n returns: The bind data object"] pub fn duckdb_init_get_bind_data (info : duckdb_init_info) -> * mut :: std :: os :: raw :: c_void ; } extern "C" { # [doc = "Sets the user-provided init data in the init object. This object can be retrieved again during execution.\n\n info: The info object\n extra_data: The init data object.\n destroy: The callback that will be called to destroy the init data (if any)"] pub fn duckdb_init_set_init_data (info : duckdb_init_info , init_data : * mut :: std :: os :: raw :: c_void , destroy : duckdb_delete_callback_t) ; } extern "C" { # [doc = "Returns the number of projected columns.\n\nThis function must be used if projection pushdown is enabled to figure out which columns to emit.\n\n info: The info object\n returns: The number of projected columns."] pub fn duckdb_init_get_column_count (info : duckdb_init_info) -> idx_t ; } extern "C" { # [doc = "Returns the column index of the projected column at the specified position.\n\nThis function must be used if projection pushdown is enabled to figure out which columns to emit.\n\n info: The info object\n column_index: The index at which to get the projected column index, from 0..duckdb_init_get_column_count(info)\n returns: The column index of the projected column."] pub fn duckdb_init_get_column_index (info : duckdb_init_info , column_index : idx_t) -> idx_t ; } extern "C" { # [doc = "Sets how many threads can process this table function in parallel (default: 1)\n\n info: The info object\n max_threads: The maximum amount of threads that can process this table function"] pub fn duckdb_init_set_max_threads (info : duckdb_init_info , max_threads : idx_t) ; } extern "C" { # [doc = "Report that an error has occurred while calling init.\n\n info: The info object\n error: The error message"] pub fn duckdb_init_set_error (info : duckdb_init_info , error : * const :: std :: os :: raw :: c_char) ; } extern "C" { # [doc = "Retrieves the extra info of the function as set in `duckdb_table_function_set_extra_info`.\n\n info: The info object\n returns: The extra info"] pub fn duckdb_function_get_extra_info (info : duckdb_function_info) -> * mut :: std :: os :: raw :: c_void ; } extern "C" { # [doc = "Gets the bind data set by `duckdb_bind_set_bind_data` during the bind.\n\nNote that the bind data should be considered as read-only.\nFor tracking state, use the init data instead.\n\n info: The info object\n returns: The bind data object"] pub fn duckdb_function_get_bind_data (info : duckdb_function_info) -> * mut :: std :: os :: raw :: c_void ; } extern "C" { # [doc = "Gets the init data set by `duckdb_init_set_init_data` during the init.\n\n info: The info object\n returns: The init data object"] pub fn duckdb_function_get_init_data (info : duckdb_function_info) -> * mut :: std :: os :: raw :: c_void ; } extern "C" { # [doc = "Gets the thread-local init data set by `duckdb_init_set_init_data` during the local_init.\n\n info: The info object\n returns: The init data object"] pub fn duckdb_function_get_local_init_data (info : duckdb_function_info) -> * mut :: std :: os :: raw :: c_void ; } extern "C" { # [doc = "Report that an error has occurred while executing the function.\n\n info: The info object\n error: The error message"] pub fn duckdb_function_set_error (info : duckdb_function_info , error : * const :: std :: os :: raw :: c_char) ; } extern "C" { # [doc = "Add a replacement scan definition to the specified database.\n\n db: The database object to add the replacement scan to\n replacement: The replacement scan callback\n extra_data: Extra data that is passed back into the specified callback\n delete_callback: The delete callback to call on the extra data, if any"] pub fn duckdb_add_replacement_scan (db : duckdb_database , replacement : duckdb_replacement_callback_t , extra_data : * mut :: std :: os :: raw :: c_void , delete_callback : duckdb_delete_callback_t) ; } extern "C" { # [doc = "Sets the replacement function name. If this function is called in the replacement callback,\nthe replacement scan is performed. If it is not called, the replacement callback is not performed.\n\n info: The info object\n function_name: The function name to substitute."] pub fn duckdb_replacement_scan_set_function_name (info : duckdb_replacement_scan_info , function_name : * const :: std :: os :: raw :: c_char) ; } extern "C" { # [doc = "Adds a parameter to the replacement scan function.\n\n info: The info object\n parameter: The parameter to add."] pub fn duckdb_replacement_scan_add_parameter (info : duckdb_replacement_scan_info , parameter : duckdb_value) ; } extern "C" { # [doc = "Report that an error has occurred while executing the replacement scan.\n\n info: The info object\n error: The error message"] pub fn duckdb_replacement_scan_set_error (info : duckdb_replacement_scan_info , error : * const :: std :: os :: raw :: c_char) ; } extern "C" { # [doc = "Creates an appender object.\n\nNote that the object must be destroyed with `duckdb_appender_destroy`.\n\n connection: The connection context to create the appender in.\n schema: The schema of the table to append to, or `nullptr` for the default schema.\n table: The table name to append to.\n out_appender: The resulting appender object.\n returns: `DuckDBSuccess` on success or `DuckDBError` on failure."] pub fn duckdb_appender_create (connection : duckdb_connection , schema : * const :: std :: os :: raw :: c_char , table : * const :: std :: os :: raw :: c_char , out_appender : * mut duckdb_appender) -> duckdb_state ; } extern "C" { # [doc = "Returns the number of columns in the table that belongs to the appender.\n\n appender The appender to get the column count from.\n returns: The number of columns in the table."] pub fn duckdb_appender_column_count (appender : duckdb_appender) -> idx_t ; } extern "C" { # [doc = "Returns the type of the column at the specified index.\n\nNote: The resulting type should be destroyed with `duckdb_destroy_logical_type`.\n\n appender The appender to get the column type from.\n col_idx The index of the column to get the type of.\n returns: The duckdb_logical_type of the column."] pub fn duckdb_appender_column_type (appender : duckdb_appender , col_idx : idx_t) -> duckdb_logical_type ; } extern "C" { # [doc = "Returns the error message associated with the given appender.\nIf the appender has no error message, this returns `nullptr` instead.\n\nThe error message should not be freed. It will be de-allocated when `duckdb_appender_destroy` is called.\n\n appender: The appender to get the error from.\n returns: The error message, or `nullptr` if there is none."] pub fn duckdb_appender_error (appender : duckdb_appender) -> * const :: std :: os :: raw :: c_char ; } extern "C" { # [doc = "Flush the appender to the table, forcing the cache of the appender to be cleared. If flushing the data triggers a\nconstraint violation or any other error, then all data is invalidated, and this function returns DuckDBError.\nIt is not possible to append more values. Call duckdb_appender_error to obtain the error message followed by\nduckdb_appender_destroy to destroy the invalidated appender.\n\n appender: The appender to flush.\n returns: `DuckDBSuccess` on success or `DuckDBError` on failure."] pub fn duckdb_appender_flush (appender : duckdb_appender) -> duckdb_state ; } extern "C" { # [doc = "Closes the appender by flushing all intermediate states and closing it for further appends. If flushing the data\ntriggers a constraint violation or any other error, then all data is invalidated, and this function returns DuckDBError.\nCall duckdb_appender_error to obtain the error message followed by duckdb_appender_destroy to destroy the invalidated\nappender.\n\n appender: The appender to flush and close.\n returns: `DuckDBSuccess` on success or `DuckDBError` on failure."] pub fn duckdb_appender_close (appender : duckdb_appender) -> duckdb_state ; } extern "C" { # [doc = "Closes the appender by flushing all intermediate states to the table and destroying it. By destroying it, this function\nde-allocates all memory associated with the appender. If flushing the data triggers a constraint violation,\nthen all data is invalidated, and this function returns DuckDBError. Due to the destruction of the appender, it is no\nlonger possible to obtain the specific error message with duckdb_appender_error. Therefore, call duckdb_appender_close\nbefore destroying the appender, if you need insights into the specific error.\n\n appender: The appender to flush, close and destroy.\n returns: `DuckDBSuccess` on success or `DuckDBError` on failure."] pub fn duckdb_appender_destroy (appender : * mut duckdb_appender) -> duckdb_state ; } extern "C" { # [doc = "A nop function, provided for backwards compatibility reasons. Does nothing. Only `duckdb_appender_end_row` is required."] pub fn duckdb_appender_begin_row (appender : duckdb_appender) -> duckdb_state ; } extern "C" { # [doc = "Finish the current row of appends. After end_row is called, the next row can be appended.\n\n appender: The appender.\n returns: `DuckDBSuccess` on success or `DuckDBError` on failure."] pub fn duckdb_appender_end_row (appender : duckdb_appender) -> duckdb_state ; } extern "C" { # [doc = "Append a bool value to the appender."] pub fn duckdb_append_bool (appender : duckdb_appender , value : bool) -> duckdb_state ; } extern "C" { # [doc = "Append an int8_t value to the appender."] pub fn duckdb_append_int8 (appender : duckdb_appender , value : i8) -> duckdb_state ; } extern "C" { # [doc = "Append an int16_t value to the appender."] pub fn duckdb_append_int16 (appender : duckdb_appender , value : i16) -> duckdb_state ; } extern "C" { # [doc = "Append an int32_t value to the appender."] pub fn duckdb_append_int32 (appender : duckdb_appender , value : i32) -> duckdb_state ; } extern "C" { # [doc = "Append an int64_t value to the appender."] pub fn duckdb_append_int64 (appender : duckdb_appender , value : i64) -> duckdb_state ; } extern "C" { # [doc = "Append a duckdb_hugeint value to the appender."] pub fn duckdb_append_hugeint (appender : duckdb_appender , value : duckdb_hugeint) -> duckdb_state ; } extern "C" { # [doc = "Append a uint8_t value to the appender."] pub fn duckdb_append_uint8 (appender : duckdb_appender , value : u8) -> duckdb_state ; } extern "C" { # [doc = "Append a uint16_t value to the appender."] pub fn duckdb_append_uint16 (appender : duckdb_appender , value : u16) -> duckdb_state ; } extern "C" { # [doc = "Append a uint32_t value to the appender."] pub fn duckdb_append_uint32 (appender : duckdb_appender , value : u32) -> duckdb_state ; } extern "C" { # [doc = "Append a uint64_t value to the appender."] pub fn duckdb_append_uint64 (appender : duckdb_appender , value : u64) -> duckdb_state ; } extern "C" { # [doc = "Append a duckdb_uhugeint value to the appender."] pub fn duckdb_append_uhugeint (appender : duckdb_appender , value : duckdb_uhugeint) -> duckdb_state ; } extern "C" { # [doc = "Append a float value to the appender."] pub fn duckdb_append_float (appender : duckdb_appender , value : f32) -> duckdb_state ; } extern "C" { # [doc = "Append a double value to the appender."] pub fn duckdb_append_double (appender : duckdb_appender , value : f64) -> duckdb_state ; } extern "C" { # [doc = "Append a duckdb_date value to the appender."] pub fn duckdb_append_date (appender : duckdb_appender , value : duckdb_date) -> duckdb_state ; } extern "C" { # [doc = "Append a duckdb_time value to the appender."] pub fn duckdb_append_time (appender : duckdb_appender , value : duckdb_time) -> duckdb_state ; } extern "C" { # [doc = "Append a duckdb_timestamp value to the appender."] pub fn duckdb_append_timestamp (appender : duckdb_appender , value : duckdb_timestamp) -> duckdb_state ; } extern "C" { # [doc = "Append a duckdb_interval value to the appender."] pub fn duckdb_append_interval (appender : duckdb_appender , value : duckdb_interval) -> duckdb_state ; } extern "C" { # [doc = "Append a varchar value to the appender."] pub fn duckdb_append_varchar (appender : duckdb_appender , val : * const :: std :: os :: raw :: c_char) -> duckdb_state ; } extern "C" { # [doc = "Append a varchar value to the appender."] pub fn duckdb_append_varchar_length (appender : duckdb_appender , val : * const :: std :: os :: raw :: c_char , length : idx_t) -> duckdb_state ; } extern "C" { # [doc = "Append a blob value to the appender."] pub fn duckdb_append_blob (appender : duckdb_appender , data : * const :: std :: os :: raw :: c_void , length : idx_t) -> duckdb_state ; } extern "C" { # [doc = "Append a NULL value to the appender (of any type)."] pub fn duckdb_append_null (appender : duckdb_appender) -> duckdb_state ; } extern "C" { # [doc = "Appends a pre-filled data chunk to the specified appender.\n\nThe types of the data chunk must exactly match the types of the table, no casting is performed.\nIf the types do not match or the appender is in an invalid state, DuckDBError is returned.\nIf the append is successful, DuckDBSuccess is returned.\n\n appender: The appender to append to.\n chunk: The data chunk to append.\n returns: The return state."] pub fn duckdb_append_data_chunk (appender : duckdb_appender , chunk : duckdb_data_chunk) -> duckdb_state ; } extern "C" { # [doc = "DEPRECATION NOTICE**: This method is scheduled for removal in a future release.\n\nExecutes a SQL query within a connection and stores the full (materialized) result in an arrow structure.\nIf the query fails to execute, DuckDBError is returned and the error message can be retrieved by calling\n`duckdb_query_arrow_error`.\n\nNote that after running `duckdb_query_arrow`, `duckdb_destroy_arrow` must be called on the result object even if the\nquery fails, otherwise the error stored within the result will not be freed correctly.\n\n connection: The connection to perform the query in.\n query: The SQL query to run.\n out_result: The query result.\n returns: `DuckDBSuccess` on success or `DuckDBError` on failure."] pub fn duckdb_query_arrow (connection : duckdb_connection , query : * const :: std :: os :: raw :: c_char , out_result : * mut duckdb_arrow) -> duckdb_state ; } extern "C" { # [doc = "DEPRECATION NOTICE**: This method is scheduled for removal in a future release.\n\nFetch the internal arrow schema from the arrow result. Remember to call release on the respective\nArrowSchema object.\n\n result: The result to fetch the schema from.\n out_schema: The output schema.\n returns: `DuckDBSuccess` on success or `DuckDBError` on failure."] pub fn duckdb_query_arrow_schema (result : duckdb_arrow , out_schema : * mut duckdb_arrow_schema) -> duckdb_state ; } extern "C" { # [doc = "DEPRECATION NOTICE**: This method is scheduled for removal in a future release.\n\nFetch the internal arrow schema from the prepared statement. Remember to call release on the respective\nArrowSchema object.\n\n result: The prepared statement to fetch the schema from.\n out_schema: The output schema.\n returns: `DuckDBSuccess` on success or `DuckDBError` on failure."] pub fn duckdb_prepared_arrow_schema (prepared : duckdb_prepared_statement , out_schema : * mut duckdb_arrow_schema) -> duckdb_state ; } extern "C" { # [doc = "DEPRECATION NOTICE**: This method is scheduled for removal in a future release.\n\nConvert a data chunk into an arrow struct array. Remember to call release on the respective\nArrowArray object.\n\n result: The result object the data chunk have been fetched from.\n chunk: The data chunk to convert.\n out_array: The output array."] pub fn duckdb_result_arrow_array (result : duckdb_result , chunk : duckdb_data_chunk , out_array : * mut duckdb_arrow_array) ; } extern "C" { # [doc = "DEPRECATION NOTICE**: This method is scheduled for removal in a future release.\n\nFetch an internal arrow struct array from the arrow result. Remember to call release on the respective\nArrowArray object.\n\nThis function can be called multiple time to get next chunks, which will free the previous out_array.\nSo consume the out_array before calling this function again.\n\n result: The result to fetch the array from.\n out_array: The output array.\n returns: `DuckDBSuccess` on success or `DuckDBError` on failure."] pub fn duckdb_query_arrow_array (result : duckdb_arrow , out_array : * mut duckdb_arrow_array) -> duckdb_state ; } extern "C" { # [doc = "DEPRECATION NOTICE**: This method is scheduled for removal in a future release.\n\nReturns the number of columns present in the arrow result object.\n\n result: The result object.\n returns: The number of columns present in the result object."] pub fn duckdb_arrow_column_count (result : duckdb_arrow) -> idx_t ; } extern "C" { # [doc = "DEPRECATION NOTICE**: This method is scheduled for removal in a future release.\n\nReturns the number of rows present in the arrow result object.\n\n result: The result object.\n returns: The number of rows present in the result object."] pub fn duckdb_arrow_row_count (result : duckdb_arrow) -> idx_t ; } extern "C" { # [doc = "DEPRECATION NOTICE**: This method is scheduled for removal in a future release.\n\nReturns the number of rows changed by the query stored in the arrow result. This is relevant only for\nINSERT/UPDATE/DELETE queries. For other queries the rows_changed will be 0.\n\n result: The result object.\n returns: The number of rows changed."] pub fn duckdb_arrow_rows_changed (result : duckdb_arrow) -> idx_t ; } extern "C" { # [doc = "DEPRECATION NOTICE**: This method is scheduled for removal in a future release.\n\nReturns the error message contained within the result. The error is only set if `duckdb_query_arrow` returns\n`DuckDBError`.\n\nThe error message should not be freed. It will be de-allocated when `duckdb_destroy_arrow` is called.\n\n result: The result object to fetch the error from.\n returns: The error of the result."] pub fn duckdb_query_arrow_error (result : duckdb_arrow) -> * const :: std :: os :: raw :: c_char ; } extern "C" { # [doc = "DEPRECATION NOTICE**: This method is scheduled for removal in a future release.\n\nCloses the result and de-allocates all memory allocated for the arrow result.\n\n result: The result to destroy."] pub fn duckdb_destroy_arrow (result : * mut duckdb_arrow) ; } extern "C" { # [doc = "DEPRECATION NOTICE**: This method is scheduled for removal in a future release.\n\nReleases the arrow array stream and de-allocates its memory.\n\n stream: The arrow array stream to destroy."] pub fn duckdb_destroy_arrow_stream (stream_p : * mut duckdb_arrow_stream) ; } extern "C" { # [doc = "DEPRECATION NOTICE**: This method is scheduled for removal in a future release.\n\nExecutes the prepared statement with the given bound parameters, and returns an arrow query result.\nNote that after running `duckdb_execute_prepared_arrow`, `duckdb_destroy_arrow` must be called on the result object.\n\n prepared_statement: The prepared statement to execute.\n out_result: The query result.\n returns: `DuckDBSuccess` on success or `DuckDBError` on failure."] pub fn duckdb_execute_prepared_arrow (prepared_statement : duckdb_prepared_statement , out_result : * mut duckdb_arrow) -> duckdb_state ; } extern "C" { # [doc = "DEPRECATION NOTICE**: This method is scheduled for removal in a future release.\n\nScans the Arrow stream and creates a view with the given name.\n\n connection: The connection on which to execute the scan.\n table_name: Name of the temporary view to create.\n arrow: Arrow stream wrapper.\n returns: `DuckDBSuccess` on success or `DuckDBError` on failure."] pub fn duckdb_arrow_scan (connection : duckdb_connection , table_name : * const :: std :: os :: raw :: c_char , arrow : duckdb_arrow_stream) -> duckdb_state ; } extern "C" { # [doc = "DEPRECATION NOTICE**: This method is scheduled for removal in a future release.\n\nScans the Arrow array and creates a view with the given name.\nNote that after running `duckdb_arrow_array_scan`, `duckdb_destroy_arrow_stream` must be called on the out stream.\n\n connection: The connection on which to execute the scan.\n table_name: Name of the temporary view to create.\n arrow_schema: Arrow schema wrapper.\n arrow_array: Arrow array wrapper.\n out_stream: Output array stream that wraps around the passed schema, for releasing/deleting once done.\n returns: `DuckDBSuccess` on success or `DuckDBError` on failure."] pub fn duckdb_arrow_array_scan (connection : duckdb_connection , table_name : * const :: std :: os :: raw :: c_char , arrow_schema : duckdb_arrow_schema , arrow_array : duckdb_arrow_array , out_stream : * mut duckdb_arrow_stream) -> duckdb_state ; } extern "C" { # [doc = "Execute DuckDB tasks on this thread.\n\nWill return after `max_tasks` have been executed, or if there are no more tasks present.\n\n database: The database object to execute tasks for\n max_tasks: The maximum amount of tasks to execute"] pub fn duckdb_execute_tasks (database : duckdb_database , max_tasks : idx_t) ; } extern "C" { # [doc = "Creates a task state that can be used with duckdb_execute_tasks_state to execute tasks until\n`duckdb_finish_execution` is called on the state.\n\n`duckdb_destroy_state` must be called on the result.\n\n database: The database object to create the task state for\n returns: The task state that can be used with duckdb_execute_tasks_state."] pub fn duckdb_create_task_state (database : duckdb_database) -> duckdb_task_state ; } extern "C" { # [doc = "Execute DuckDB tasks on this thread.\n\nThe thread will keep on executing tasks forever, until duckdb_finish_execution is called on the state.\nMultiple threads can share the same duckdb_task_state.\n\n state: The task state of the executor"] pub fn duckdb_execute_tasks_state (state : duckdb_task_state) ; } extern "C" { # [doc = "Execute DuckDB tasks on this thread.\n\nThe thread will keep on executing tasks until either duckdb_finish_execution is called on the state,\nmax_tasks tasks have been executed or there are no more tasks to be executed.\n\nMultiple threads can share the same duckdb_task_state.\n\n state: The task state of the executor\n max_tasks: The maximum amount of tasks to execute\n returns: The amount of tasks that have actually been executed"] pub fn duckdb_execute_n_tasks_state (state : duckdb_task_state , max_tasks : idx_t) -> idx_t ; } extern "C" { # [doc = "Finish execution on a specific task.\n\n state: The task state to finish execution"] pub fn duckdb_finish_execution (state : duckdb_task_state) ; } extern "C" { # [doc = "Check if the provided duckdb_task_state has finished execution\n\n state: The task state to inspect\n returns: Whether or not duckdb_finish_execution has been called on the task state"] pub fn duckdb_task_state_is_finished (state : duckdb_task_state) -> bool ; } extern "C" { # [doc = "Destroys the task state returned from duckdb_create_task_state.\n\nNote that this should not be called while there is an active duckdb_execute_tasks_state running\non the task state.\n\n state: The task state to clean up"] pub fn duckdb_destroy_task_state (state : duckdb_task_state) ; } extern "C" { # [doc = "Returns true if the execution of the current query is finished.\n\n con: The connection on which to check"] pub fn duckdb_execution_is_finished (con : duckdb_connection) -> bool ; } extern "C" { # [doc = "DEPRECATION NOTICE**: This method is scheduled for removal in a future release.\n\nFetches a data chunk from the (streaming) duckdb_result. This function should be called repeatedly until the result is\nexhausted.\n\nThe result must be destroyed with `duckdb_destroy_data_chunk`.\n\nThis function can only be used on duckdb_results created with 'duckdb_pending_prepared_streaming'\n\nIf this function is used, none of the other result functions can be used and vice versa (i.e. this function cannot be\nmixed with the legacy result functions or the materialized result functions).\n\nIt is not known beforehand how many chunks will be returned by this result.\n\n result: The result object to fetch the data chunk from.\n returns: The resulting data chunk. Returns `NULL` if the result has an error."] pub fn duckdb_stream_fetch_chunk (result : duckdb_result) -> duckdb_data_chunk ; } extern "C" { # [doc = "Fetches a data chunk from a duckdb_result. This function should be called repeatedly until the result is exhausted.\n\nThe result must be destroyed with `duckdb_destroy_data_chunk`.\n\nIt is not known beforehand how many chunks will be returned by this result.\n\n result: The result object to fetch the data chunk from.\n returns: The resulting data chunk. Returns `NULL` if the result has an error."] pub fn duckdb_fetch_chunk (result : duckdb_result) -> duckdb_data_chunk ; } \ No newline at end of file diff --git a/libduckdb-sys/src/error.rs b/crates/libduckdb-sys/src/error.rs similarity index 100% rename from libduckdb-sys/src/error.rs rename to crates/libduckdb-sys/src/error.rs diff --git a/libduckdb-sys/src/lib.rs b/crates/libduckdb-sys/src/lib.rs similarity index 93% rename from libduckdb-sys/src/lib.rs rename to crates/libduckdb-sys/src/lib.rs index d7547535..5f683bd7 100644 --- a/libduckdb-sys/src/lib.rs +++ b/crates/libduckdb-sys/src/lib.rs @@ -11,6 +11,9 @@ mod bindings { #[allow(clippy::all)] pub use bindings::*; +mod string; +pub use string::*; + pub const DuckDBError: duckdb_state = duckdb_state_DuckDBError; pub const DuckDBSuccess: duckdb_state = duckdb_state_DuckDBSuccess; @@ -33,18 +36,15 @@ mod tests { ffi::{from_ffi, FFI_ArrowArray, FFI_ArrowSchema}, }; - unsafe fn print_int_result(mut result: duckdb_result) { - for i in 0..duckdb_column_count(&mut result) { - print!( - "{} ", - CStr::from_ptr(duckdb_column_name(&mut result, i)).to_string_lossy() - ); + unsafe fn print_int_result(result: &mut duckdb_result) { + for i in 0..duckdb_column_count(result) { + print!("{} ", CStr::from_ptr(duckdb_column_name(result, i)).to_string_lossy()); } println!(); // print the data of the result - for row_idx in 0..duckdb_row_count(&mut result) { - for col_idx in 0..duckdb_column_count(&mut result) { - let val = duckdb_value_int32(&mut result, col_idx, row_idx); + for row_idx in 0..duckdb_row_count(result) { + for col_idx in 0..duckdb_column_count(result) { + let val = duckdb_value_int32(result, col_idx, row_idx); print!("{val} "); } println!(); @@ -162,7 +162,7 @@ mod tests { } assert_eq!(duckdb_row_count(&mut result), 3); assert_eq!(duckdb_column_count(&mut result), 2); - print_int_result(result); + print_int_result(&mut result); duckdb_destroy_result(&mut result); // test prepare @@ -179,7 +179,7 @@ mod tests { } assert_eq!(duckdb_row_count(&mut result), 2); assert_eq!(duckdb_column_count(&mut result), 2); - print_int_result(result); + print_int_result(&mut result); duckdb_destroy_result(&mut result); // test bind params again @@ -191,7 +191,7 @@ mod tests { } assert_eq!(duckdb_row_count(&mut result), 1); assert_eq!(duckdb_column_count(&mut result), 2); - print_int_result(result); + print_int_result(&mut result); duckdb_destroy_result(&mut result); duckdb_destroy_prepare(&mut stmt); diff --git a/libduckdb-sys/src/raw_statement.rs b/crates/libduckdb-sys/src/raw_statement.rs similarity index 100% rename from libduckdb-sys/src/raw_statement.rs rename to crates/libduckdb-sys/src/raw_statement.rs diff --git a/crates/libduckdb-sys/src/string.rs b/crates/libduckdb-sys/src/string.rs new file mode 100644 index 00000000..d2f3515c --- /dev/null +++ b/crates/libduckdb-sys/src/string.rs @@ -0,0 +1,60 @@ +use std::{ + ffi::{c_char, CStr}, + ops::Deref, +}; + +use crate::duckdb_free; + +pub struct DuckDbString { + // Invariant: ptr[0..len+1] is valid C string, i.e. ptr[len] is NUL byte. + ptr: core::ptr::NonNull, + len: usize, +} + +impl DuckDbString { + /// Creates a `DuckDbString` from a raw pointer to a C string. + /// + /// # Safety + /// + /// The caller must ensure that the pointer is valid and points to a null-terminated C string. + /// The memory must remain valid for the lifetime of the returned `DuckDbString`. + pub unsafe fn from_ptr(ptr: *const c_char) -> Self { + let len = unsafe { CStr::from_ptr(ptr) }.to_bytes().len(); + unsafe { Self::from_raw_parts(ptr, len) } + } + + /// Creates a `DuckDbString` from raw parts. + /// + /// # Safety + /// + /// The caller must ensure that: + /// - `ptr` is a valid pointer to a null-terminated C string. + /// - `len` accurately represents the length of the string (excluding the null terminator). + /// - The memory referenced by `ptr` remains valid for the lifetime of the returned `DuckDbString`. + /// - The string data is not mutated for the lifetime of the returned `DuckDbString`. + pub unsafe fn from_raw_parts(ptr: *const c_char, len: usize) -> Self { + let ptr = unsafe { core::ptr::NonNull::new_unchecked(ptr as *mut c_char) }; + Self { ptr, len } + } + + fn to_bytes_with_nul(&self) -> &[u8] { + let ptr = self.ptr.as_ptr() as *const u8; + unsafe { core::slice::from_raw_parts(ptr, self.len + 1) } + } +} + +impl Deref for DuckDbString { + type Target = std::ffi::CStr; + + fn deref(&self) -> &Self::Target { + let bytes = self.to_bytes_with_nul(); + unsafe { CStr::from_bytes_with_nul_unchecked(bytes) } + } +} + +impl Drop for DuckDbString { + fn drop(&mut self) { + let ptr = self.ptr.as_ptr() as *mut core::ffi::c_void; + unsafe { duckdb_free(ptr) }; + } +} diff --git a/libduckdb-sys/update_sources.py b/crates/libduckdb-sys/update_sources.py similarity index 89% rename from libduckdb-sys/update_sources.py rename to crates/libduckdb-sys/update_sources.py index ffbc7295..95f9a8f3 100755 --- a/libduckdb-sys/update_sources.py +++ b/crates/libduckdb-sys/update_sources.py @@ -16,7 +16,7 @@ # List of extensions' sources to grab. Technically, these sources will be compiled # but not included in the final build unless they're explicitly enabled. -EXTENSIONS = ["parquet", "json", "httpfs"] +EXTENSIONS = ["parquet", "json"] # Clear the duckdb directory try: @@ -75,7 +75,7 @@ def get_sources(extensions): ) subprocess.check_call( - 'find "' + SCRIPT_DIR + '/../target" -type f -name bindgen.rs -exec rm {} \;', + 'find "' + SCRIPT_DIR + '/../../target" -type f -name bindgen.rs -exec rm {} \;', shell=True, ) @@ -87,14 +87,14 @@ def get_sources(extensions): print( 'find "' + SCRIPT_DIR - + '/../target" -type f -name "bindgen.rs" -exec cp {} "' + + '/../../target" -type f -name "bindgen.rs" -exec cp {} "' + SRC_DIR + '/bindgen_bundled_version.rs" \;' ) subprocess.check_call( 'find "' + SCRIPT_DIR - + '/../target" -type f -name "bindgen.rs" -exec cp {} "' + + '/../../target" -type f -name "bindgen.rs" -exec cp {} "' + SRC_DIR + '/bindgen_bundled_version.rs" \;', shell=True, diff --git a/libduckdb-sys/upgrade.sh b/crates/libduckdb-sys/upgrade.sh similarity index 78% rename from libduckdb-sys/upgrade.sh rename to crates/libduckdb-sys/upgrade.sh index dd9846f6..54d42535 100755 --- a/libduckdb-sys/upgrade.sh +++ b/crates/libduckdb-sys/upgrade.sh @@ -5,12 +5,12 @@ CUR_DIR=$(pwd -P) echo "$SCRIPT_DIR" cd "$SCRIPT_DIR" || { echo "fatal error" >&2; exit 1; } cargo clean -mkdir -p "$SCRIPT_DIR/../target" "$SCRIPT_DIR/duckdb" +mkdir -p "$SCRIPT_DIR/../../target" "$SCRIPT_DIR/duckdb" export DUCKDB_LIB_DIR="$SCRIPT_DIR/duckdb" export DU_INCLUDE_DIR="$DUCKDB_LIB_DIR" # Download and extract amalgamation -DUCKDB_VERSION=v0.10.2 +DUCKDB_VERSION=v1.0.0 git submodule update --init --checkout cd "$SCRIPT_DIR/duckdb-sources" || { echo "fatal error" >&2; exit 1; } git fetch @@ -22,9 +22,9 @@ python3 "$SCRIPT_DIR/update_sources.py" rm -f "$SCRIPT_DIR/src/bindgen_bundled_version.rs" cargo update # Just to make sure there is only one bindgen.rs file in target dir -find "$SCRIPT_DIR/../target" -type f -name bindgen.rs -exec rm {} \; +find "$SCRIPT_DIR/../../target" -type f -name bindgen.rs -exec rm {} \; env LIBDUCKDB_SYS_BUNDLING=1 cargo test --features "extensions-full buildtime_bindgen" -find "$SCRIPT_DIR/../target" -type f -name bindgen.rs -exec cp {} "$SCRIPT_DIR/src/bindgen_bundled_version.rs" \; +find "$SCRIPT_DIR/../../target" -type f -name bindgen.rs -exec cp {} "$SCRIPT_DIR/src/bindgen_bundled_version.rs" \; # Sanity checks cd "$SCRIPT_DIR/.." || { echo "fatal error" >&2; exit 1; } diff --git a/libduckdb-sys/wrapper.h b/crates/libduckdb-sys/wrapper.h similarity index 100% rename from libduckdb-sys/wrapper.h rename to crates/libduckdb-sys/wrapper.h diff --git a/duckdb-loadable-macros/Cargo.toml b/duckdb-loadable-macros/Cargo.toml deleted file mode 100644 index 30c40ab2..00000000 --- a/duckdb-loadable-macros/Cargo.toml +++ /dev/null @@ -1,22 +0,0 @@ -[package] -name = "duckdb-loadable-macros" -version = "0.1.1" -authors = ["wangfenjin "] -edition = "2021" -license = "MIT" -repository = "https://github.com/wangfenjin/duckdb-rs" -homepage = "https://github.com/wangfenjin/duckdb-rs" -keywords = ["duckdb", "ffi", "database"] -readme = "README.md" -categories = ["external-ffi-bindings", "database"] -description = "Native bindings to the libduckdb library, C API; build loadable extensions" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] -proc-macro2 = { version = "1.0.56" } -quote = { version = "1.0.21" } -syn = { version = "2.0.15", features = [ "extra-traits", "full", "fold", "parsing" ] } - -[lib] -proc-macro = true diff --git a/duckdb-loadable-macros/LICENSE b/duckdb-loadable-macros/LICENSE deleted file mode 120000 index ea5b6064..00000000 --- a/duckdb-loadable-macros/LICENSE +++ /dev/null @@ -1 +0,0 @@ -../LICENSE \ No newline at end of file diff --git a/duckdb-loadable-macros/README.md b/duckdb-loadable-macros/README.md deleted file mode 120000 index 32d46ee8..00000000 --- a/duckdb-loadable-macros/README.md +++ /dev/null @@ -1 +0,0 @@ -../README.md \ No newline at end of file diff --git a/libduckdb-sys/Cargo.toml b/libduckdb-sys/Cargo.toml deleted file mode 100644 index 7465f90f..00000000 --- a/libduckdb-sys/Cargo.toml +++ /dev/null @@ -1,42 +0,0 @@ -[package] -name = "libduckdb-sys" -version = "0.10.2" -authors = ["wangfenjin "] -edition = "2021" -build = "build.rs" -license = "MIT" -repository = "https://github.com/wangfenjin/duckdb-rs" -homepage = "https://github.com/wangfenjin/duckdb-rs" -keywords = ["duckdb", "ffi", "database"] -readme = "README.md" -categories = ["external-ffi-bindings", "database"] -description = "Native bindings to the libduckdb library, C API" -exclude = ["duckdb-sources"] - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[features] -default = ["vcpkg", "pkg-config"] -bundled = ["cc"] -buildtime_bindgen = ["bindgen", "pkg-config", "vcpkg"] - -httpfs = ["bundled"] -json = ["bundled"] -parquet = ["bundled"] -extensions-full = ["httpfs", "json", "parquet"] - -[dependencies] - -[build-dependencies] -autocfg = "1.0" -bindgen = { version = "0.69", optional = true, default-features = false, features = ["runtime"] } -flate2 = "1.0" -pkg-config = { version = "0.3.24", optional = true } -cc = { version = "1.0", features = ["parallel"], optional = true } -vcpkg = { version = "0.2", optional = true } -serde = { version = "1.0", features = ["derive"] } -serde_json = { version = "1.0" } -tar = "0.4.38" - -[dev-dependencies] -arrow = { version = "51", default-features = false, features = ["ffi"] } diff --git a/libduckdb-sys/LICENSE b/libduckdb-sys/LICENSE deleted file mode 120000 index ea5b6064..00000000 --- a/libduckdb-sys/LICENSE +++ /dev/null @@ -1 +0,0 @@ -../LICENSE \ No newline at end of file diff --git a/libduckdb-sys/README.md b/libduckdb-sys/README.md deleted file mode 120000 index 32d46ee8..00000000 --- a/libduckdb-sys/README.md +++ /dev/null @@ -1 +0,0 @@ -../README.md \ No newline at end of file diff --git a/libduckdb-sys/duckdb-sources b/libduckdb-sys/duckdb-sources deleted file mode 160000 index 1601d94f..00000000 --- a/libduckdb-sys/duckdb-sources +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 1601d94f94a7e0d2eb805a94803eb1e3afbbe4ed diff --git a/libduckdb-sys/duckdb.tar.gz b/libduckdb-sys/duckdb.tar.gz deleted file mode 100644 index 8fa472ac..00000000 Binary files a/libduckdb-sys/duckdb.tar.gz and /dev/null differ diff --git a/libduckdb-sys/src/bindgen_bundled_version.rs b/libduckdb-sys/src/bindgen_bundled_version.rs deleted file mode 100644 index a319c828..00000000 --- a/libduckdb-sys/src/bindgen_bundled_version.rs +++ /dev/null @@ -1,3108 +0,0 @@ -/* automatically generated by rust-bindgen 0.69.4 */ - -pub const DUCKDB_API_0_3_1: u32 = 1; -pub const DUCKDB_API_0_3_2: u32 = 2; -pub const DUCKDB_API_LATEST: u32 = 2; -pub const DUCKDB_API_VERSION: u32 = 2; -pub const true_: u32 = 1; -pub const false_: u32 = 0; -pub const __bool_true_false_are_defined: u32 = 1; -pub const _STDINT_H: u32 = 1; -pub const _FEATURES_H: u32 = 1; -pub const _DEFAULT_SOURCE: u32 = 1; -pub const __GLIBC_USE_ISOC2X: u32 = 0; -pub const __USE_ISOC11: u32 = 1; -pub const __USE_ISOC99: u32 = 1; -pub const __USE_ISOC95: u32 = 1; -pub const __USE_POSIX_IMPLICITLY: u32 = 1; -pub const _POSIX_SOURCE: u32 = 1; -pub const _POSIX_C_SOURCE: u32 = 200809; -pub const __USE_POSIX: u32 = 1; -pub const __USE_POSIX2: u32 = 1; -pub const __USE_POSIX199309: u32 = 1; -pub const __USE_POSIX199506: u32 = 1; -pub const __USE_XOPEN2K: u32 = 1; -pub const __USE_XOPEN2K8: u32 = 1; -pub const _ATFILE_SOURCE: u32 = 1; -pub const __WORDSIZE: u32 = 64; -pub const __WORDSIZE_TIME64_COMPAT32: u32 = 1; -pub const __SYSCALL_WORDSIZE: u32 = 64; -pub const __TIMESIZE: u32 = 64; -pub const __USE_MISC: u32 = 1; -pub const __USE_ATFILE: u32 = 1; -pub const __USE_FORTIFY_LEVEL: u32 = 0; -pub const __GLIBC_USE_DEPRECATED_GETS: u32 = 0; -pub const __GLIBC_USE_DEPRECATED_SCANF: u32 = 0; -pub const _STDC_PREDEF_H: u32 = 1; -pub const __STDC_IEC_559__: u32 = 1; -pub const __STDC_IEC_60559_BFP__: u32 = 201404; -pub const __STDC_IEC_559_COMPLEX__: u32 = 1; -pub const __STDC_IEC_60559_COMPLEX__: u32 = 201404; -pub const __STDC_ISO_10646__: u32 = 201706; -pub const __GNU_LIBRARY__: u32 = 6; -pub const __GLIBC__: u32 = 2; -pub const __GLIBC_MINOR__: u32 = 35; -pub const _SYS_CDEFS_H: u32 = 1; -pub const __glibc_c99_flexarr_available: u32 = 1; -pub const __LDOUBLE_REDIRECTS_TO_FLOAT128_ABI: u32 = 0; -pub const __HAVE_GENERIC_SELECTION: u32 = 1; -pub const __GLIBC_USE_LIB_EXT2: u32 = 0; -pub const __GLIBC_USE_IEC_60559_BFP_EXT: u32 = 0; -pub const __GLIBC_USE_IEC_60559_BFP_EXT_C2X: u32 = 0; -pub const __GLIBC_USE_IEC_60559_EXT: u32 = 0; -pub const __GLIBC_USE_IEC_60559_FUNCS_EXT: u32 = 0; -pub const __GLIBC_USE_IEC_60559_FUNCS_EXT_C2X: u32 = 0; -pub const __GLIBC_USE_IEC_60559_TYPES_EXT: u32 = 0; -pub const _BITS_TYPES_H: u32 = 1; -pub const _BITS_TYPESIZES_H: u32 = 1; -pub const __OFF_T_MATCHES_OFF64_T: u32 = 1; -pub const __INO_T_MATCHES_INO64_T: u32 = 1; -pub const __RLIM_T_MATCHES_RLIM64_T: u32 = 1; -pub const __STATFS_MATCHES_STATFS64: u32 = 1; -pub const __KERNEL_OLD_TIMEVAL_MATCHES_TIMEVAL64: u32 = 1; -pub const __FD_SETSIZE: u32 = 1024; -pub const _BITS_TIME64_H: u32 = 1; -pub const _BITS_WCHAR_H: u32 = 1; -pub const _BITS_STDINT_INTN_H: u32 = 1; -pub const _BITS_STDINT_UINTN_H: u32 = 1; -pub const INT8_MIN: i32 = -128; -pub const INT16_MIN: i32 = -32768; -pub const INT32_MIN: i32 = -2147483648; -pub const INT8_MAX: u32 = 127; -pub const INT16_MAX: u32 = 32767; -pub const INT32_MAX: u32 = 2147483647; -pub const UINT8_MAX: u32 = 255; -pub const UINT16_MAX: u32 = 65535; -pub const UINT32_MAX: u32 = 4294967295; -pub const INT_LEAST8_MIN: i32 = -128; -pub const INT_LEAST16_MIN: i32 = -32768; -pub const INT_LEAST32_MIN: i32 = -2147483648; -pub const INT_LEAST8_MAX: u32 = 127; -pub const INT_LEAST16_MAX: u32 = 32767; -pub const INT_LEAST32_MAX: u32 = 2147483647; -pub const UINT_LEAST8_MAX: u32 = 255; -pub const UINT_LEAST16_MAX: u32 = 65535; -pub const UINT_LEAST32_MAX: u32 = 4294967295; -pub const INT_FAST8_MIN: i32 = -128; -pub const INT_FAST16_MIN: i64 = -9223372036854775808; -pub const INT_FAST32_MIN: i64 = -9223372036854775808; -pub const INT_FAST8_MAX: u32 = 127; -pub const INT_FAST16_MAX: u64 = 9223372036854775807; -pub const INT_FAST32_MAX: u64 = 9223372036854775807; -pub const UINT_FAST8_MAX: u32 = 255; -pub const UINT_FAST16_MAX: i32 = -1; -pub const UINT_FAST32_MAX: i32 = -1; -pub const INTPTR_MIN: i64 = -9223372036854775808; -pub const INTPTR_MAX: u64 = 9223372036854775807; -pub const UINTPTR_MAX: i32 = -1; -pub const PTRDIFF_MIN: i64 = -9223372036854775808; -pub const PTRDIFF_MAX: u64 = 9223372036854775807; -pub const SIG_ATOMIC_MIN: i32 = -2147483648; -pub const SIG_ATOMIC_MAX: u32 = 2147483647; -pub const SIZE_MAX: i32 = -1; -pub const WINT_MIN: u32 = 0; -pub const WINT_MAX: u32 = 4294967295; -pub type __u_char = ::std::os::raw::c_uchar; -pub type __u_short = ::std::os::raw::c_ushort; -pub type __u_int = ::std::os::raw::c_uint; -pub type __u_long = ::std::os::raw::c_ulong; -pub type __int8_t = ::std::os::raw::c_schar; -pub type __uint8_t = ::std::os::raw::c_uchar; -pub type __int16_t = ::std::os::raw::c_short; -pub type __uint16_t = ::std::os::raw::c_ushort; -pub type __int32_t = ::std::os::raw::c_int; -pub type __uint32_t = ::std::os::raw::c_uint; -pub type __int64_t = ::std::os::raw::c_long; -pub type __uint64_t = ::std::os::raw::c_ulong; -pub type __int_least8_t = __int8_t; -pub type __uint_least8_t = __uint8_t; -pub type __int_least16_t = __int16_t; -pub type __uint_least16_t = __uint16_t; -pub type __int_least32_t = __int32_t; -pub type __uint_least32_t = __uint32_t; -pub type __int_least64_t = __int64_t; -pub type __uint_least64_t = __uint64_t; -pub type __quad_t = ::std::os::raw::c_long; -pub type __u_quad_t = ::std::os::raw::c_ulong; -pub type __intmax_t = ::std::os::raw::c_long; -pub type __uintmax_t = ::std::os::raw::c_ulong; -pub type __dev_t = ::std::os::raw::c_ulong; -pub type __uid_t = ::std::os::raw::c_uint; -pub type __gid_t = ::std::os::raw::c_uint; -pub type __ino_t = ::std::os::raw::c_ulong; -pub type __ino64_t = ::std::os::raw::c_ulong; -pub type __mode_t = ::std::os::raw::c_uint; -pub type __nlink_t = ::std::os::raw::c_ulong; -pub type __off_t = ::std::os::raw::c_long; -pub type __off64_t = ::std::os::raw::c_long; -pub type __pid_t = ::std::os::raw::c_int; -#[repr(C)] -#[derive(Debug, Copy, Clone)] -pub struct __fsid_t { - pub __val: [::std::os::raw::c_int; 2usize], -} -#[test] -fn bindgen_test_layout___fsid_t() { - const UNINIT: ::std::mem::MaybeUninit<__fsid_t> = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::<__fsid_t>(), - 8usize, - concat!("Size of: ", stringify!(__fsid_t)) - ); - assert_eq!( - ::std::mem::align_of::<__fsid_t>(), - 4usize, - concat!("Alignment of ", stringify!(__fsid_t)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).__val) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(__fsid_t), "::", stringify!(__val)) - ); -} -pub type __clock_t = ::std::os::raw::c_long; -pub type __rlim_t = ::std::os::raw::c_ulong; -pub type __rlim64_t = ::std::os::raw::c_ulong; -pub type __id_t = ::std::os::raw::c_uint; -pub type __time_t = ::std::os::raw::c_long; -pub type __useconds_t = ::std::os::raw::c_uint; -pub type __suseconds_t = ::std::os::raw::c_long; -pub type __suseconds64_t = ::std::os::raw::c_long; -pub type __daddr_t = ::std::os::raw::c_int; -pub type __key_t = ::std::os::raw::c_int; -pub type __clockid_t = ::std::os::raw::c_int; -pub type __timer_t = *mut ::std::os::raw::c_void; -pub type __blksize_t = ::std::os::raw::c_long; -pub type __blkcnt_t = ::std::os::raw::c_long; -pub type __blkcnt64_t = ::std::os::raw::c_long; -pub type __fsblkcnt_t = ::std::os::raw::c_ulong; -pub type __fsblkcnt64_t = ::std::os::raw::c_ulong; -pub type __fsfilcnt_t = ::std::os::raw::c_ulong; -pub type __fsfilcnt64_t = ::std::os::raw::c_ulong; -pub type __fsword_t = ::std::os::raw::c_long; -pub type __ssize_t = ::std::os::raw::c_long; -pub type __syscall_slong_t = ::std::os::raw::c_long; -pub type __syscall_ulong_t = ::std::os::raw::c_ulong; -pub type __loff_t = __off64_t; -pub type __caddr_t = *mut ::std::os::raw::c_char; -pub type __intptr_t = ::std::os::raw::c_long; -pub type __socklen_t = ::std::os::raw::c_uint; -pub type __sig_atomic_t = ::std::os::raw::c_int; -pub type int_least8_t = __int_least8_t; -pub type int_least16_t = __int_least16_t; -pub type int_least32_t = __int_least32_t; -pub type int_least64_t = __int_least64_t; -pub type uint_least8_t = __uint_least8_t; -pub type uint_least16_t = __uint_least16_t; -pub type uint_least32_t = __uint_least32_t; -pub type uint_least64_t = __uint_least64_t; -pub type int_fast8_t = ::std::os::raw::c_schar; -pub type int_fast16_t = ::std::os::raw::c_long; -pub type int_fast32_t = ::std::os::raw::c_long; -pub type int_fast64_t = ::std::os::raw::c_long; -pub type uint_fast8_t = ::std::os::raw::c_uchar; -pub type uint_fast16_t = ::std::os::raw::c_ulong; -pub type uint_fast32_t = ::std::os::raw::c_ulong; -pub type uint_fast64_t = ::std::os::raw::c_ulong; -pub type intmax_t = __intmax_t; -pub type uintmax_t = __uintmax_t; -pub type wchar_t = ::std::os::raw::c_int; -#[repr(C)] -#[repr(align(16))] -#[derive(Debug, Copy, Clone)] -pub struct max_align_t { - pub __clang_max_align_nonce1: ::std::os::raw::c_longlong, - pub __bindgen_padding_0: u64, - pub __clang_max_align_nonce2: u128, -} -#[test] -fn bindgen_test_layout_max_align_t() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 32usize, - concat!("Size of: ", stringify!(max_align_t)) - ); - assert_eq!( - ::std::mem::align_of::(), - 16usize, - concat!("Alignment of ", stringify!(max_align_t)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).__clang_max_align_nonce1) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(max_align_t), - "::", - stringify!(__clang_max_align_nonce1) - ) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).__clang_max_align_nonce2) as usize - ptr as usize }, - 16usize, - concat!( - "Offset of field: ", - stringify!(max_align_t), - "::", - stringify!(__clang_max_align_nonce2) - ) - ); -} -pub const DUCKDB_TYPE_DUCKDB_TYPE_INVALID: DUCKDB_TYPE = 0; -pub const DUCKDB_TYPE_DUCKDB_TYPE_BOOLEAN: DUCKDB_TYPE = 1; -pub const DUCKDB_TYPE_DUCKDB_TYPE_TINYINT: DUCKDB_TYPE = 2; -pub const DUCKDB_TYPE_DUCKDB_TYPE_SMALLINT: DUCKDB_TYPE = 3; -pub const DUCKDB_TYPE_DUCKDB_TYPE_INTEGER: DUCKDB_TYPE = 4; -pub const DUCKDB_TYPE_DUCKDB_TYPE_BIGINT: DUCKDB_TYPE = 5; -pub const DUCKDB_TYPE_DUCKDB_TYPE_UTINYINT: DUCKDB_TYPE = 6; -pub const DUCKDB_TYPE_DUCKDB_TYPE_USMALLINT: DUCKDB_TYPE = 7; -pub const DUCKDB_TYPE_DUCKDB_TYPE_UINTEGER: DUCKDB_TYPE = 8; -pub const DUCKDB_TYPE_DUCKDB_TYPE_UBIGINT: DUCKDB_TYPE = 9; -pub const DUCKDB_TYPE_DUCKDB_TYPE_FLOAT: DUCKDB_TYPE = 10; -pub const DUCKDB_TYPE_DUCKDB_TYPE_DOUBLE: DUCKDB_TYPE = 11; -pub const DUCKDB_TYPE_DUCKDB_TYPE_TIMESTAMP: DUCKDB_TYPE = 12; -pub const DUCKDB_TYPE_DUCKDB_TYPE_DATE: DUCKDB_TYPE = 13; -pub const DUCKDB_TYPE_DUCKDB_TYPE_TIME: DUCKDB_TYPE = 14; -pub const DUCKDB_TYPE_DUCKDB_TYPE_INTERVAL: DUCKDB_TYPE = 15; -pub const DUCKDB_TYPE_DUCKDB_TYPE_HUGEINT: DUCKDB_TYPE = 16; -pub const DUCKDB_TYPE_DUCKDB_TYPE_UHUGEINT: DUCKDB_TYPE = 32; -pub const DUCKDB_TYPE_DUCKDB_TYPE_VARCHAR: DUCKDB_TYPE = 17; -pub const DUCKDB_TYPE_DUCKDB_TYPE_BLOB: DUCKDB_TYPE = 18; -pub const DUCKDB_TYPE_DUCKDB_TYPE_DECIMAL: DUCKDB_TYPE = 19; -pub const DUCKDB_TYPE_DUCKDB_TYPE_TIMESTAMP_S: DUCKDB_TYPE = 20; -pub const DUCKDB_TYPE_DUCKDB_TYPE_TIMESTAMP_MS: DUCKDB_TYPE = 21; -pub const DUCKDB_TYPE_DUCKDB_TYPE_TIMESTAMP_NS: DUCKDB_TYPE = 22; -pub const DUCKDB_TYPE_DUCKDB_TYPE_ENUM: DUCKDB_TYPE = 23; -pub const DUCKDB_TYPE_DUCKDB_TYPE_LIST: DUCKDB_TYPE = 24; -pub const DUCKDB_TYPE_DUCKDB_TYPE_STRUCT: DUCKDB_TYPE = 25; -pub const DUCKDB_TYPE_DUCKDB_TYPE_MAP: DUCKDB_TYPE = 26; -pub const DUCKDB_TYPE_DUCKDB_TYPE_ARRAY: DUCKDB_TYPE = 33; -pub const DUCKDB_TYPE_DUCKDB_TYPE_UUID: DUCKDB_TYPE = 27; -pub const DUCKDB_TYPE_DUCKDB_TYPE_UNION: DUCKDB_TYPE = 28; -pub const DUCKDB_TYPE_DUCKDB_TYPE_BIT: DUCKDB_TYPE = 29; -pub const DUCKDB_TYPE_DUCKDB_TYPE_TIME_TZ: DUCKDB_TYPE = 30; -pub const DUCKDB_TYPE_DUCKDB_TYPE_TIMESTAMP_TZ: DUCKDB_TYPE = 31; -#[doc = "! An enum over DuckDB's internal types."] -pub type DUCKDB_TYPE = ::std::os::raw::c_uint; -#[doc = "! An enum over DuckDB's internal types."] -pub use self::DUCKDB_TYPE as duckdb_type; -pub const duckdb_state_DuckDBSuccess: duckdb_state = 0; -pub const duckdb_state_DuckDBError: duckdb_state = 1; -#[doc = "! An enum over the returned state of different functions."] -pub type duckdb_state = ::std::os::raw::c_uint; -pub const duckdb_pending_state_DUCKDB_PENDING_RESULT_READY: duckdb_pending_state = 0; -pub const duckdb_pending_state_DUCKDB_PENDING_RESULT_NOT_READY: duckdb_pending_state = 1; -pub const duckdb_pending_state_DUCKDB_PENDING_ERROR: duckdb_pending_state = 2; -pub const duckdb_pending_state_DUCKDB_PENDING_NO_TASKS_AVAILABLE: duckdb_pending_state = 3; -#[doc = "! An enum over the pending state of a pending query result."] -pub type duckdb_pending_state = ::std::os::raw::c_uint; -pub const duckdb_result_type_DUCKDB_RESULT_TYPE_INVALID: duckdb_result_type = 0; -pub const duckdb_result_type_DUCKDB_RESULT_TYPE_CHANGED_ROWS: duckdb_result_type = 1; -pub const duckdb_result_type_DUCKDB_RESULT_TYPE_NOTHING: duckdb_result_type = 2; -pub const duckdb_result_type_DUCKDB_RESULT_TYPE_QUERY_RESULT: duckdb_result_type = 3; -#[doc = "! An enum over DuckDB's different result types."] -pub type duckdb_result_type = ::std::os::raw::c_uint; -pub const duckdb_statement_type_DUCKDB_STATEMENT_TYPE_INVALID: duckdb_statement_type = 0; -pub const duckdb_statement_type_DUCKDB_STATEMENT_TYPE_SELECT: duckdb_statement_type = 1; -pub const duckdb_statement_type_DUCKDB_STATEMENT_TYPE_INSERT: duckdb_statement_type = 2; -pub const duckdb_statement_type_DUCKDB_STATEMENT_TYPE_UPDATE: duckdb_statement_type = 3; -pub const duckdb_statement_type_DUCKDB_STATEMENT_TYPE_EXPLAIN: duckdb_statement_type = 4; -pub const duckdb_statement_type_DUCKDB_STATEMENT_TYPE_DELETE: duckdb_statement_type = 5; -pub const duckdb_statement_type_DUCKDB_STATEMENT_TYPE_PREPARE: duckdb_statement_type = 6; -pub const duckdb_statement_type_DUCKDB_STATEMENT_TYPE_CREATE: duckdb_statement_type = 7; -pub const duckdb_statement_type_DUCKDB_STATEMENT_TYPE_EXECUTE: duckdb_statement_type = 8; -pub const duckdb_statement_type_DUCKDB_STATEMENT_TYPE_ALTER: duckdb_statement_type = 9; -pub const duckdb_statement_type_DUCKDB_STATEMENT_TYPE_TRANSACTION: duckdb_statement_type = 10; -pub const duckdb_statement_type_DUCKDB_STATEMENT_TYPE_COPY: duckdb_statement_type = 11; -pub const duckdb_statement_type_DUCKDB_STATEMENT_TYPE_ANALYZE: duckdb_statement_type = 12; -pub const duckdb_statement_type_DUCKDB_STATEMENT_TYPE_VARIABLE_SET: duckdb_statement_type = 13; -pub const duckdb_statement_type_DUCKDB_STATEMENT_TYPE_CREATE_FUNC: duckdb_statement_type = 14; -pub const duckdb_statement_type_DUCKDB_STATEMENT_TYPE_DROP: duckdb_statement_type = 15; -pub const duckdb_statement_type_DUCKDB_STATEMENT_TYPE_EXPORT: duckdb_statement_type = 16; -pub const duckdb_statement_type_DUCKDB_STATEMENT_TYPE_PRAGMA: duckdb_statement_type = 17; -pub const duckdb_statement_type_DUCKDB_STATEMENT_TYPE_VACUUM: duckdb_statement_type = 18; -pub const duckdb_statement_type_DUCKDB_STATEMENT_TYPE_CALL: duckdb_statement_type = 19; -pub const duckdb_statement_type_DUCKDB_STATEMENT_TYPE_SET: duckdb_statement_type = 20; -pub const duckdb_statement_type_DUCKDB_STATEMENT_TYPE_LOAD: duckdb_statement_type = 21; -pub const duckdb_statement_type_DUCKDB_STATEMENT_TYPE_RELATION: duckdb_statement_type = 22; -pub const duckdb_statement_type_DUCKDB_STATEMENT_TYPE_EXTENSION: duckdb_statement_type = 23; -pub const duckdb_statement_type_DUCKDB_STATEMENT_TYPE_LOGICAL_PLAN: duckdb_statement_type = 24; -pub const duckdb_statement_type_DUCKDB_STATEMENT_TYPE_ATTACH: duckdb_statement_type = 25; -pub const duckdb_statement_type_DUCKDB_STATEMENT_TYPE_DETACH: duckdb_statement_type = 26; -pub const duckdb_statement_type_DUCKDB_STATEMENT_TYPE_MULTI: duckdb_statement_type = 27; -#[doc = "! An enum over DuckDB's different statement types."] -pub type duckdb_statement_type = ::std::os::raw::c_uint; -#[doc = "! DuckDB's index type."] -pub type idx_t = u64; -#[doc = "! The callback that will be called to destroy data, e.g.,\n! bind data (if any), init data (if any), extra data for replacement scans (if any)"] -pub type duckdb_delete_callback_t = ::std::option::Option; -#[doc = "! Used for threading, contains a task state. Must be destroyed with `duckdb_destroy_state`."] -pub type duckdb_task_state = *mut ::std::os::raw::c_void; -#[doc = "! Days are stored as days since 1970-01-01\n! Use the duckdb_from_date/duckdb_to_date function to extract individual information"] -#[repr(C)] -#[derive(Debug, Copy, Clone)] -pub struct duckdb_date { - pub days: i32, -} -#[test] -fn bindgen_test_layout_duckdb_date() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(duckdb_date)) - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(duckdb_date)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).days) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(duckdb_date), "::", stringify!(days)) - ); -} -#[repr(C)] -#[derive(Debug, Copy, Clone)] -pub struct duckdb_date_struct { - pub year: i32, - pub month: i8, - pub day: i8, -} -#[test] -fn bindgen_test_layout_duckdb_date_struct() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(duckdb_date_struct)) - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(duckdb_date_struct)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).year) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(duckdb_date_struct), - "::", - stringify!(year) - ) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).month) as usize - ptr as usize }, - 4usize, - concat!( - "Offset of field: ", - stringify!(duckdb_date_struct), - "::", - stringify!(month) - ) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).day) as usize - ptr as usize }, - 5usize, - concat!( - "Offset of field: ", - stringify!(duckdb_date_struct), - "::", - stringify!(day) - ) - ); -} -#[doc = "! Time is stored as microseconds since 00:00:00\n! Use the duckdb_from_time/duckdb_to_time function to extract individual information"] -#[repr(C)] -#[derive(Debug, Copy, Clone)] -pub struct duckdb_time { - pub micros: i64, -} -#[test] -fn bindgen_test_layout_duckdb_time() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(duckdb_time)) - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(duckdb_time)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).micros) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(duckdb_time), "::", stringify!(micros)) - ); -} -#[repr(C)] -#[derive(Debug, Copy, Clone)] -pub struct duckdb_time_struct { - pub hour: i8, - pub min: i8, - pub sec: i8, - pub micros: i32, -} -#[test] -fn bindgen_test_layout_duckdb_time_struct() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(duckdb_time_struct)) - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(duckdb_time_struct)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).hour) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(duckdb_time_struct), - "::", - stringify!(hour) - ) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).min) as usize - ptr as usize }, - 1usize, - concat!( - "Offset of field: ", - stringify!(duckdb_time_struct), - "::", - stringify!(min) - ) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).sec) as usize - ptr as usize }, - 2usize, - concat!( - "Offset of field: ", - stringify!(duckdb_time_struct), - "::", - stringify!(sec) - ) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).micros) as usize - ptr as usize }, - 4usize, - concat!( - "Offset of field: ", - stringify!(duckdb_time_struct), - "::", - stringify!(micros) - ) - ); -} -#[doc = "! TIME_TZ is stored as 40 bits for int64_t micros, and 24 bits for int32_t offset"] -#[repr(C)] -#[derive(Debug, Copy, Clone)] -pub struct duckdb_time_tz { - pub bits: u64, -} -#[test] -fn bindgen_test_layout_duckdb_time_tz() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(duckdb_time_tz)) - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(duckdb_time_tz)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).bits) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(duckdb_time_tz), "::", stringify!(bits)) - ); -} -#[repr(C)] -#[derive(Debug, Copy, Clone)] -pub struct duckdb_time_tz_struct { - pub time: duckdb_time_struct, - pub offset: i32, -} -#[test] -fn bindgen_test_layout_duckdb_time_tz_struct() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 12usize, - concat!("Size of: ", stringify!(duckdb_time_tz_struct)) - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(duckdb_time_tz_struct)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).time) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(duckdb_time_tz_struct), - "::", - stringify!(time) - ) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).offset) as usize - ptr as usize }, - 8usize, - concat!( - "Offset of field: ", - stringify!(duckdb_time_tz_struct), - "::", - stringify!(offset) - ) - ); -} -#[doc = "! Timestamps are stored as microseconds since 1970-01-01\n! Use the duckdb_from_timestamp/duckdb_to_timestamp function to extract individual information"] -#[repr(C)] -#[derive(Debug, Copy, Clone)] -pub struct duckdb_timestamp { - pub micros: i64, -} -#[test] -fn bindgen_test_layout_duckdb_timestamp() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(duckdb_timestamp)) - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(duckdb_timestamp)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).micros) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(duckdb_timestamp), - "::", - stringify!(micros) - ) - ); -} -#[repr(C)] -#[derive(Debug, Copy, Clone)] -pub struct duckdb_timestamp_struct { - pub date: duckdb_date_struct, - pub time: duckdb_time_struct, -} -#[test] -fn bindgen_test_layout_duckdb_timestamp_struct() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 16usize, - concat!("Size of: ", stringify!(duckdb_timestamp_struct)) - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(duckdb_timestamp_struct)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).date) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(duckdb_timestamp_struct), - "::", - stringify!(date) - ) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).time) as usize - ptr as usize }, - 8usize, - concat!( - "Offset of field: ", - stringify!(duckdb_timestamp_struct), - "::", - stringify!(time) - ) - ); -} -#[repr(C)] -#[derive(Debug, Copy, Clone)] -pub struct duckdb_interval { - pub months: i32, - pub days: i32, - pub micros: i64, -} -#[test] -fn bindgen_test_layout_duckdb_interval() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 16usize, - concat!("Size of: ", stringify!(duckdb_interval)) - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(duckdb_interval)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).months) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(duckdb_interval), - "::", - stringify!(months) - ) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).days) as usize - ptr as usize }, - 4usize, - concat!("Offset of field: ", stringify!(duckdb_interval), "::", stringify!(days)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).micros) as usize - ptr as usize }, - 8usize, - concat!( - "Offset of field: ", - stringify!(duckdb_interval), - "::", - stringify!(micros) - ) - ); -} -#[doc = "! Hugeints are composed of a (lower, upper) component\n! The value of the hugeint is upper * 2^64 + lower\n! For easy usage, the functions duckdb_hugeint_to_double/duckdb_double_to_hugeint are recommended"] -#[repr(C)] -#[derive(Debug, Copy, Clone)] -pub struct duckdb_hugeint { - pub lower: u64, - pub upper: i64, -} -#[test] -fn bindgen_test_layout_duckdb_hugeint() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 16usize, - concat!("Size of: ", stringify!(duckdb_hugeint)) - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(duckdb_hugeint)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).lower) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(duckdb_hugeint), "::", stringify!(lower)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).upper) as usize - ptr as usize }, - 8usize, - concat!("Offset of field: ", stringify!(duckdb_hugeint), "::", stringify!(upper)) - ); -} -#[repr(C)] -#[derive(Debug, Copy, Clone)] -pub struct duckdb_uhugeint { - pub lower: u64, - pub upper: u64, -} -#[test] -fn bindgen_test_layout_duckdb_uhugeint() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 16usize, - concat!("Size of: ", stringify!(duckdb_uhugeint)) - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(duckdb_uhugeint)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).lower) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(duckdb_uhugeint), - "::", - stringify!(lower) - ) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).upper) as usize - ptr as usize }, - 8usize, - concat!( - "Offset of field: ", - stringify!(duckdb_uhugeint), - "::", - stringify!(upper) - ) - ); -} -#[doc = "! Decimals are composed of a width and a scale, and are stored in a hugeint"] -#[repr(C)] -#[derive(Debug, Copy, Clone)] -pub struct duckdb_decimal { - pub width: u8, - pub scale: u8, - pub value: duckdb_hugeint, -} -#[test] -fn bindgen_test_layout_duckdb_decimal() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 24usize, - concat!("Size of: ", stringify!(duckdb_decimal)) - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(duckdb_decimal)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).width) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(duckdb_decimal), "::", stringify!(width)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).scale) as usize - ptr as usize }, - 1usize, - concat!("Offset of field: ", stringify!(duckdb_decimal), "::", stringify!(scale)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).value) as usize - ptr as usize }, - 8usize, - concat!("Offset of field: ", stringify!(duckdb_decimal), "::", stringify!(value)) - ); -} -#[doc = "! A type holding information about the query execution progress"] -#[repr(C)] -#[derive(Debug, Copy, Clone)] -pub struct duckdb_query_progress_type { - pub percentage: f64, - pub rows_processed: u64, - pub total_rows_to_process: u64, -} -#[test] -fn bindgen_test_layout_duckdb_query_progress_type() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 24usize, - concat!("Size of: ", stringify!(duckdb_query_progress_type)) - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(duckdb_query_progress_type)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).percentage) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(duckdb_query_progress_type), - "::", - stringify!(percentage) - ) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).rows_processed) as usize - ptr as usize }, - 8usize, - concat!( - "Offset of field: ", - stringify!(duckdb_query_progress_type), - "::", - stringify!(rows_processed) - ) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).total_rows_to_process) as usize - ptr as usize }, - 16usize, - concat!( - "Offset of field: ", - stringify!(duckdb_query_progress_type), - "::", - stringify!(total_rows_to_process) - ) - ); -} -#[doc = "! The internal representation of a VARCHAR (string_t). If the VARCHAR does not\n! exceed 12 characters, then we inline it. Otherwise, we inline a prefix for faster\n! string comparisons and store a pointer to the remaining characters. This is a non-\n! owning structure, i.e., it does not have to be freed."] -#[repr(C)] -#[derive(Copy, Clone)] -pub struct duckdb_string_t { - pub value: duckdb_string_t__bindgen_ty_1, -} -#[repr(C)] -#[derive(Copy, Clone)] -pub union duckdb_string_t__bindgen_ty_1 { - pub pointer: duckdb_string_t__bindgen_ty_1__bindgen_ty_1, - pub inlined: duckdb_string_t__bindgen_ty_1__bindgen_ty_2, -} -#[repr(C)] -#[derive(Debug, Copy, Clone)] -pub struct duckdb_string_t__bindgen_ty_1__bindgen_ty_1 { - pub length: u32, - pub prefix: [::std::os::raw::c_char; 4usize], - pub ptr: *mut ::std::os::raw::c_char, -} -#[test] -fn bindgen_test_layout_duckdb_string_t__bindgen_ty_1__bindgen_ty_1() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 16usize, - concat!("Size of: ", stringify!(duckdb_string_t__bindgen_ty_1__bindgen_ty_1)) - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(duckdb_string_t__bindgen_ty_1__bindgen_ty_1)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).length) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(duckdb_string_t__bindgen_ty_1__bindgen_ty_1), - "::", - stringify!(length) - ) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).prefix) as usize - ptr as usize }, - 4usize, - concat!( - "Offset of field: ", - stringify!(duckdb_string_t__bindgen_ty_1__bindgen_ty_1), - "::", - stringify!(prefix) - ) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).ptr) as usize - ptr as usize }, - 8usize, - concat!( - "Offset of field: ", - stringify!(duckdb_string_t__bindgen_ty_1__bindgen_ty_1), - "::", - stringify!(ptr) - ) - ); -} -#[repr(C)] -#[derive(Debug, Copy, Clone)] -pub struct duckdb_string_t__bindgen_ty_1__bindgen_ty_2 { - pub length: u32, - pub inlined: [::std::os::raw::c_char; 12usize], -} -#[test] -fn bindgen_test_layout_duckdb_string_t__bindgen_ty_1__bindgen_ty_2() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 16usize, - concat!("Size of: ", stringify!(duckdb_string_t__bindgen_ty_1__bindgen_ty_2)) - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(duckdb_string_t__bindgen_ty_1__bindgen_ty_2)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).length) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(duckdb_string_t__bindgen_ty_1__bindgen_ty_2), - "::", - stringify!(length) - ) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).inlined) as usize - ptr as usize }, - 4usize, - concat!( - "Offset of field: ", - stringify!(duckdb_string_t__bindgen_ty_1__bindgen_ty_2), - "::", - stringify!(inlined) - ) - ); -} -#[test] -fn bindgen_test_layout_duckdb_string_t__bindgen_ty_1() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 16usize, - concat!("Size of: ", stringify!(duckdb_string_t__bindgen_ty_1)) - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(duckdb_string_t__bindgen_ty_1)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).pointer) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(duckdb_string_t__bindgen_ty_1), - "::", - stringify!(pointer) - ) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).inlined) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(duckdb_string_t__bindgen_ty_1), - "::", - stringify!(inlined) - ) - ); -} -#[test] -fn bindgen_test_layout_duckdb_string_t() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 16usize, - concat!("Size of: ", stringify!(duckdb_string_t)) - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(duckdb_string_t)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).value) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(duckdb_string_t), - "::", - stringify!(value) - ) - ); -} -#[doc = "! The internal representation of a list metadata entry contains the list's offset in\n! the child vector, and its length. The parent vector holds these metadata entries,\n! whereas the child vector holds the data"] -#[repr(C)] -#[derive(Debug, Copy, Clone)] -pub struct duckdb_list_entry { - pub offset: u64, - pub length: u64, -} -#[test] -fn bindgen_test_layout_duckdb_list_entry() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 16usize, - concat!("Size of: ", stringify!(duckdb_list_entry)) - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(duckdb_list_entry)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).offset) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(duckdb_list_entry), - "::", - stringify!(offset) - ) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).length) as usize - ptr as usize }, - 8usize, - concat!( - "Offset of field: ", - stringify!(duckdb_list_entry), - "::", - stringify!(length) - ) - ); -} -#[doc = "! A column consists of a pointer to its internal data. Don't operate on this type directly.\n! Instead, use functions such as duckdb_column_data, duckdb_nullmask_data,\n! duckdb_column_type, and duckdb_column_name, which take the result and the column index\n! as their parameters"] -#[repr(C)] -#[derive(Debug, Copy, Clone)] -pub struct duckdb_column { - pub __deprecated_data: *mut ::std::os::raw::c_void, - pub __deprecated_nullmask: *mut bool, - pub __deprecated_type: duckdb_type, - pub __deprecated_name: *mut ::std::os::raw::c_char, - pub internal_data: *mut ::std::os::raw::c_void, -} -#[test] -fn bindgen_test_layout_duckdb_column() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 40usize, - concat!("Size of: ", stringify!(duckdb_column)) - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(duckdb_column)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).__deprecated_data) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(duckdb_column), - "::", - stringify!(__deprecated_data) - ) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).__deprecated_nullmask) as usize - ptr as usize }, - 8usize, - concat!( - "Offset of field: ", - stringify!(duckdb_column), - "::", - stringify!(__deprecated_nullmask) - ) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).__deprecated_type) as usize - ptr as usize }, - 16usize, - concat!( - "Offset of field: ", - stringify!(duckdb_column), - "::", - stringify!(__deprecated_type) - ) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).__deprecated_name) as usize - ptr as usize }, - 24usize, - concat!( - "Offset of field: ", - stringify!(duckdb_column), - "::", - stringify!(__deprecated_name) - ) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).internal_data) as usize - ptr as usize }, - 32usize, - concat!( - "Offset of field: ", - stringify!(duckdb_column), - "::", - stringify!(internal_data) - ) - ); -} -#[doc = "! A vector to a specified column in a data chunk. Lives as long as the\n! data chunk lives, i.e., must not be destroyed."] -#[repr(C)] -#[derive(Debug, Copy, Clone)] -pub struct _duckdb_vector { - pub __vctr: *mut ::std::os::raw::c_void, -} -#[test] -fn bindgen_test_layout__duckdb_vector() { - const UNINIT: ::std::mem::MaybeUninit<_duckdb_vector> = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::<_duckdb_vector>(), - 8usize, - concat!("Size of: ", stringify!(_duckdb_vector)) - ); - assert_eq!( - ::std::mem::align_of::<_duckdb_vector>(), - 8usize, - concat!("Alignment of ", stringify!(_duckdb_vector)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).__vctr) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(_duckdb_vector), - "::", - stringify!(__vctr) - ) - ); -} -#[doc = "! A vector to a specified column in a data chunk. Lives as long as the\n! data chunk lives, i.e., must not be destroyed."] -pub type duckdb_vector = *mut _duckdb_vector; -#[doc = "! Strings are composed of a char pointer and a size. You must free string.data\n! with `duckdb_free`."] -#[repr(C)] -#[derive(Debug, Copy, Clone)] -pub struct duckdb_string { - pub data: *mut ::std::os::raw::c_char, - pub size: idx_t, -} -#[test] -fn bindgen_test_layout_duckdb_string() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 16usize, - concat!("Size of: ", stringify!(duckdb_string)) - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(duckdb_string)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).data) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(duckdb_string), "::", stringify!(data)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).size) as usize - ptr as usize }, - 8usize, - concat!("Offset of field: ", stringify!(duckdb_string), "::", stringify!(size)) - ); -} -#[doc = "! BLOBs are composed of a byte pointer and a size. You must free blob.data\n! with `duckdb_free`."] -#[repr(C)] -#[derive(Debug, Copy, Clone)] -pub struct duckdb_blob { - pub data: *mut ::std::os::raw::c_void, - pub size: idx_t, -} -#[test] -fn bindgen_test_layout_duckdb_blob() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 16usize, - concat!("Size of: ", stringify!(duckdb_blob)) - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(duckdb_blob)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).data) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(duckdb_blob), "::", stringify!(data)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).size) as usize - ptr as usize }, - 8usize, - concat!("Offset of field: ", stringify!(duckdb_blob), "::", stringify!(size)) - ); -} -#[doc = "! A query result consists of a pointer to its internal data.\n! Must be freed with 'duckdb_destroy_result'."] -#[repr(C)] -#[derive(Debug, Copy, Clone)] -pub struct duckdb_result { - pub __deprecated_column_count: idx_t, - pub __deprecated_row_count: idx_t, - pub __deprecated_rows_changed: idx_t, - pub __deprecated_columns: *mut duckdb_column, - pub __deprecated_error_message: *mut ::std::os::raw::c_char, - pub internal_data: *mut ::std::os::raw::c_void, -} -#[test] -fn bindgen_test_layout_duckdb_result() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 48usize, - concat!("Size of: ", stringify!(duckdb_result)) - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(duckdb_result)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).__deprecated_column_count) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(duckdb_result), - "::", - stringify!(__deprecated_column_count) - ) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).__deprecated_row_count) as usize - ptr as usize }, - 8usize, - concat!( - "Offset of field: ", - stringify!(duckdb_result), - "::", - stringify!(__deprecated_row_count) - ) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).__deprecated_rows_changed) as usize - ptr as usize }, - 16usize, - concat!( - "Offset of field: ", - stringify!(duckdb_result), - "::", - stringify!(__deprecated_rows_changed) - ) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).__deprecated_columns) as usize - ptr as usize }, - 24usize, - concat!( - "Offset of field: ", - stringify!(duckdb_result), - "::", - stringify!(__deprecated_columns) - ) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).__deprecated_error_message) as usize - ptr as usize }, - 32usize, - concat!( - "Offset of field: ", - stringify!(duckdb_result), - "::", - stringify!(__deprecated_error_message) - ) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).internal_data) as usize - ptr as usize }, - 40usize, - concat!( - "Offset of field: ", - stringify!(duckdb_result), - "::", - stringify!(internal_data) - ) - ); -} -#[doc = "! A database object. Should be closed with `duckdb_close`."] -#[repr(C)] -#[derive(Debug, Copy, Clone)] -pub struct _duckdb_database { - pub __db: *mut ::std::os::raw::c_void, -} -#[test] -fn bindgen_test_layout__duckdb_database() { - const UNINIT: ::std::mem::MaybeUninit<_duckdb_database> = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::<_duckdb_database>(), - 8usize, - concat!("Size of: ", stringify!(_duckdb_database)) - ); - assert_eq!( - ::std::mem::align_of::<_duckdb_database>(), - 8usize, - concat!("Alignment of ", stringify!(_duckdb_database)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).__db) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(_duckdb_database), - "::", - stringify!(__db) - ) - ); -} -#[doc = "! A database object. Should be closed with `duckdb_close`."] -pub type duckdb_database = *mut _duckdb_database; -#[doc = "! A connection to a duckdb database. Must be closed with `duckdb_disconnect`."] -#[repr(C)] -#[derive(Debug, Copy, Clone)] -pub struct _duckdb_connection { - pub __conn: *mut ::std::os::raw::c_void, -} -#[test] -fn bindgen_test_layout__duckdb_connection() { - const UNINIT: ::std::mem::MaybeUninit<_duckdb_connection> = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::<_duckdb_connection>(), - 8usize, - concat!("Size of: ", stringify!(_duckdb_connection)) - ); - assert_eq!( - ::std::mem::align_of::<_duckdb_connection>(), - 8usize, - concat!("Alignment of ", stringify!(_duckdb_connection)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).__conn) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(_duckdb_connection), - "::", - stringify!(__conn) - ) - ); -} -#[doc = "! A connection to a duckdb database. Must be closed with `duckdb_disconnect`."] -pub type duckdb_connection = *mut _duckdb_connection; -#[doc = "! A prepared statement is a parameterized query that allows you to bind parameters to it.\n! Must be destroyed with `duckdb_destroy_prepare`."] -#[repr(C)] -#[derive(Debug, Copy, Clone)] -pub struct _duckdb_prepared_statement { - pub __prep: *mut ::std::os::raw::c_void, -} -#[test] -fn bindgen_test_layout__duckdb_prepared_statement() { - const UNINIT: ::std::mem::MaybeUninit<_duckdb_prepared_statement> = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::<_duckdb_prepared_statement>(), - 8usize, - concat!("Size of: ", stringify!(_duckdb_prepared_statement)) - ); - assert_eq!( - ::std::mem::align_of::<_duckdb_prepared_statement>(), - 8usize, - concat!("Alignment of ", stringify!(_duckdb_prepared_statement)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).__prep) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(_duckdb_prepared_statement), - "::", - stringify!(__prep) - ) - ); -} -#[doc = "! A prepared statement is a parameterized query that allows you to bind parameters to it.\n! Must be destroyed with `duckdb_destroy_prepare`."] -pub type duckdb_prepared_statement = *mut _duckdb_prepared_statement; -#[doc = "! Extracted statements. Must be destroyed with `duckdb_destroy_extracted`."] -#[repr(C)] -#[derive(Debug, Copy, Clone)] -pub struct _duckdb_extracted_statements { - pub __extrac: *mut ::std::os::raw::c_void, -} -#[test] -fn bindgen_test_layout__duckdb_extracted_statements() { - const UNINIT: ::std::mem::MaybeUninit<_duckdb_extracted_statements> = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::<_duckdb_extracted_statements>(), - 8usize, - concat!("Size of: ", stringify!(_duckdb_extracted_statements)) - ); - assert_eq!( - ::std::mem::align_of::<_duckdb_extracted_statements>(), - 8usize, - concat!("Alignment of ", stringify!(_duckdb_extracted_statements)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).__extrac) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(_duckdb_extracted_statements), - "::", - stringify!(__extrac) - ) - ); -} -#[doc = "! Extracted statements. Must be destroyed with `duckdb_destroy_extracted`."] -pub type duckdb_extracted_statements = *mut _duckdb_extracted_statements; -#[doc = "! The pending result represents an intermediate structure for a query that is not yet fully executed.\n! Must be destroyed with `duckdb_destroy_pending`."] -#[repr(C)] -#[derive(Debug, Copy, Clone)] -pub struct _duckdb_pending_result { - pub __pend: *mut ::std::os::raw::c_void, -} -#[test] -fn bindgen_test_layout__duckdb_pending_result() { - const UNINIT: ::std::mem::MaybeUninit<_duckdb_pending_result> = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::<_duckdb_pending_result>(), - 8usize, - concat!("Size of: ", stringify!(_duckdb_pending_result)) - ); - assert_eq!( - ::std::mem::align_of::<_duckdb_pending_result>(), - 8usize, - concat!("Alignment of ", stringify!(_duckdb_pending_result)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).__pend) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(_duckdb_pending_result), - "::", - stringify!(__pend) - ) - ); -} -#[doc = "! The pending result represents an intermediate structure for a query that is not yet fully executed.\n! Must be destroyed with `duckdb_destroy_pending`."] -pub type duckdb_pending_result = *mut _duckdb_pending_result; -#[doc = "! The appender enables fast data loading into DuckDB.\n! Must be destroyed with `duckdb_appender_destroy`."] -#[repr(C)] -#[derive(Debug, Copy, Clone)] -pub struct _duckdb_appender { - pub __appn: *mut ::std::os::raw::c_void, -} -#[test] -fn bindgen_test_layout__duckdb_appender() { - const UNINIT: ::std::mem::MaybeUninit<_duckdb_appender> = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::<_duckdb_appender>(), - 8usize, - concat!("Size of: ", stringify!(_duckdb_appender)) - ); - assert_eq!( - ::std::mem::align_of::<_duckdb_appender>(), - 8usize, - concat!("Alignment of ", stringify!(_duckdb_appender)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).__appn) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(_duckdb_appender), - "::", - stringify!(__appn) - ) - ); -} -#[doc = "! The appender enables fast data loading into DuckDB.\n! Must be destroyed with `duckdb_appender_destroy`."] -pub type duckdb_appender = *mut _duckdb_appender; -#[doc = "! Can be used to provide start-up options for the DuckDB instance.\n! Must be destroyed with `duckdb_destroy_config`."] -#[repr(C)] -#[derive(Debug, Copy, Clone)] -pub struct _duckdb_config { - pub __cnfg: *mut ::std::os::raw::c_void, -} -#[test] -fn bindgen_test_layout__duckdb_config() { - const UNINIT: ::std::mem::MaybeUninit<_duckdb_config> = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::<_duckdb_config>(), - 8usize, - concat!("Size of: ", stringify!(_duckdb_config)) - ); - assert_eq!( - ::std::mem::align_of::<_duckdb_config>(), - 8usize, - concat!("Alignment of ", stringify!(_duckdb_config)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).__cnfg) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(_duckdb_config), - "::", - stringify!(__cnfg) - ) - ); -} -#[doc = "! Can be used to provide start-up options for the DuckDB instance.\n! Must be destroyed with `duckdb_destroy_config`."] -pub type duckdb_config = *mut _duckdb_config; -#[doc = "! Holds an internal logical type.\n! Must be destroyed with `duckdb_destroy_logical_type`."] -#[repr(C)] -#[derive(Debug, Copy, Clone)] -pub struct _duckdb_logical_type { - pub __lglt: *mut ::std::os::raw::c_void, -} -#[test] -fn bindgen_test_layout__duckdb_logical_type() { - const UNINIT: ::std::mem::MaybeUninit<_duckdb_logical_type> = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::<_duckdb_logical_type>(), - 8usize, - concat!("Size of: ", stringify!(_duckdb_logical_type)) - ); - assert_eq!( - ::std::mem::align_of::<_duckdb_logical_type>(), - 8usize, - concat!("Alignment of ", stringify!(_duckdb_logical_type)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).__lglt) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(_duckdb_logical_type), - "::", - stringify!(__lglt) - ) - ); -} -#[doc = "! Holds an internal logical type.\n! Must be destroyed with `duckdb_destroy_logical_type`."] -pub type duckdb_logical_type = *mut _duckdb_logical_type; -#[doc = "! Contains a data chunk from a duckdb_result.\n! Must be destroyed with `duckdb_destroy_data_chunk`."] -#[repr(C)] -#[derive(Debug, Copy, Clone)] -pub struct _duckdb_data_chunk { - pub __dtck: *mut ::std::os::raw::c_void, -} -#[test] -fn bindgen_test_layout__duckdb_data_chunk() { - const UNINIT: ::std::mem::MaybeUninit<_duckdb_data_chunk> = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::<_duckdb_data_chunk>(), - 8usize, - concat!("Size of: ", stringify!(_duckdb_data_chunk)) - ); - assert_eq!( - ::std::mem::align_of::<_duckdb_data_chunk>(), - 8usize, - concat!("Alignment of ", stringify!(_duckdb_data_chunk)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).__dtck) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(_duckdb_data_chunk), - "::", - stringify!(__dtck) - ) - ); -} -#[doc = "! Contains a data chunk from a duckdb_result.\n! Must be destroyed with `duckdb_destroy_data_chunk`."] -pub type duckdb_data_chunk = *mut _duckdb_data_chunk; -#[doc = "! Holds a DuckDB value, which wraps a type.\n! Must be destroyed with `duckdb_destroy_value`."] -#[repr(C)] -#[derive(Debug, Copy, Clone)] -pub struct _duckdb_value { - pub __val: *mut ::std::os::raw::c_void, -} -#[test] -fn bindgen_test_layout__duckdb_value() { - const UNINIT: ::std::mem::MaybeUninit<_duckdb_value> = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::<_duckdb_value>(), - 8usize, - concat!("Size of: ", stringify!(_duckdb_value)) - ); - assert_eq!( - ::std::mem::align_of::<_duckdb_value>(), - 8usize, - concat!("Alignment of ", stringify!(_duckdb_value)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).__val) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(_duckdb_value), "::", stringify!(__val)) - ); -} -#[doc = "! Holds a DuckDB value, which wraps a type.\n! Must be destroyed with `duckdb_destroy_value`."] -pub type duckdb_value = *mut _duckdb_value; -#[doc = "! A table function. Must be destroyed with `duckdb_destroy_table_function`."] -pub type duckdb_table_function = *mut ::std::os::raw::c_void; -#[doc = "! The bind info of the function. When setting this info, it is necessary to pass a destroy-callback function."] -pub type duckdb_bind_info = *mut ::std::os::raw::c_void; -#[doc = "! Additional function init info. When setting this info, it is necessary to pass a destroy-callback function."] -pub type duckdb_init_info = *mut ::std::os::raw::c_void; -#[doc = "! Additional function info. When setting this info, it is necessary to pass a destroy-callback function."] -pub type duckdb_function_info = *mut ::std::os::raw::c_void; -#[doc = "! The bind function of the table function."] -pub type duckdb_table_function_bind_t = ::std::option::Option; -#[doc = "! The (possibly thread-local) init function of the table function."] -pub type duckdb_table_function_init_t = ::std::option::Option; -#[doc = "! The main function of the table function."] -pub type duckdb_table_function_t = - ::std::option::Option; -#[doc = "! Additional replacement scan info. When setting this info, it is necessary to pass a destroy-callback function."] -pub type duckdb_replacement_scan_info = *mut ::std::os::raw::c_void; -#[doc = "! A replacement scan function that can be added to a database."] -pub type duckdb_replacement_callback_t = ::std::option::Option< - unsafe extern "C" fn( - info: duckdb_replacement_scan_info, - table_name: *const ::std::os::raw::c_char, - data: *mut ::std::os::raw::c_void, - ), ->; -#[doc = "! Holds an arrow query result. Must be destroyed with `duckdb_destroy_arrow`."] -#[repr(C)] -#[derive(Debug, Copy, Clone)] -pub struct _duckdb_arrow { - pub __arrw: *mut ::std::os::raw::c_void, -} -#[test] -fn bindgen_test_layout__duckdb_arrow() { - const UNINIT: ::std::mem::MaybeUninit<_duckdb_arrow> = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::<_duckdb_arrow>(), - 8usize, - concat!("Size of: ", stringify!(_duckdb_arrow)) - ); - assert_eq!( - ::std::mem::align_of::<_duckdb_arrow>(), - 8usize, - concat!("Alignment of ", stringify!(_duckdb_arrow)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).__arrw) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(_duckdb_arrow), "::", stringify!(__arrw)) - ); -} -#[doc = "! Holds an arrow query result. Must be destroyed with `duckdb_destroy_arrow`."] -pub type duckdb_arrow = *mut _duckdb_arrow; -#[doc = "! Holds an arrow array stream. Must be destroyed with `duckdb_destroy_arrow_stream`."] -#[repr(C)] -#[derive(Debug, Copy, Clone)] -pub struct _duckdb_arrow_stream { - pub __arrwstr: *mut ::std::os::raw::c_void, -} -#[test] -fn bindgen_test_layout__duckdb_arrow_stream() { - const UNINIT: ::std::mem::MaybeUninit<_duckdb_arrow_stream> = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::<_duckdb_arrow_stream>(), - 8usize, - concat!("Size of: ", stringify!(_duckdb_arrow_stream)) - ); - assert_eq!( - ::std::mem::align_of::<_duckdb_arrow_stream>(), - 8usize, - concat!("Alignment of ", stringify!(_duckdb_arrow_stream)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).__arrwstr) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(_duckdb_arrow_stream), - "::", - stringify!(__arrwstr) - ) - ); -} -#[doc = "! Holds an arrow array stream. Must be destroyed with `duckdb_destroy_arrow_stream`."] -pub type duckdb_arrow_stream = *mut _duckdb_arrow_stream; -#[doc = "! Holds an arrow schema. Remember to release the respective ArrowSchema object."] -#[repr(C)] -#[derive(Debug, Copy, Clone)] -pub struct _duckdb_arrow_schema { - pub __arrs: *mut ::std::os::raw::c_void, -} -#[test] -fn bindgen_test_layout__duckdb_arrow_schema() { - const UNINIT: ::std::mem::MaybeUninit<_duckdb_arrow_schema> = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::<_duckdb_arrow_schema>(), - 8usize, - concat!("Size of: ", stringify!(_duckdb_arrow_schema)) - ); - assert_eq!( - ::std::mem::align_of::<_duckdb_arrow_schema>(), - 8usize, - concat!("Alignment of ", stringify!(_duckdb_arrow_schema)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).__arrs) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(_duckdb_arrow_schema), - "::", - stringify!(__arrs) - ) - ); -} -#[doc = "! Holds an arrow schema. Remember to release the respective ArrowSchema object."] -pub type duckdb_arrow_schema = *mut _duckdb_arrow_schema; -#[doc = "! Holds an arrow array. Remember to release the respective ArrowArray object."] -#[repr(C)] -#[derive(Debug, Copy, Clone)] -pub struct _duckdb_arrow_array { - pub __arra: *mut ::std::os::raw::c_void, -} -#[test] -fn bindgen_test_layout__duckdb_arrow_array() { - const UNINIT: ::std::mem::MaybeUninit<_duckdb_arrow_array> = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::<_duckdb_arrow_array>(), - 8usize, - concat!("Size of: ", stringify!(_duckdb_arrow_array)) - ); - assert_eq!( - ::std::mem::align_of::<_duckdb_arrow_array>(), - 8usize, - concat!("Alignment of ", stringify!(_duckdb_arrow_array)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).__arra) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(_duckdb_arrow_array), - "::", - stringify!(__arra) - ) - ); -} -#[doc = "! Holds an arrow array. Remember to release the respective ArrowArray object."] -pub type duckdb_arrow_array = *mut _duckdb_arrow_array; -extern "C" { - #[doc = "Creates a new database or opens an existing database file stored at the given path.\nIf no path is given a new in-memory database is created instead.\nThe instantiated database should be closed with 'duckdb_close'.\n\n path: Path to the database file on disk, or `nullptr` or `:memory:` to open an in-memory database.\n out_database: The result database object.\n returns: `DuckDBSuccess` on success or `DuckDBError` on failure."] - pub fn duckdb_open(path: *const ::std::os::raw::c_char, out_database: *mut duckdb_database) -> duckdb_state; -} -extern "C" { - #[doc = "Extended version of duckdb_open. Creates a new database or opens an existing database file stored at the given path.\nThe instantiated database should be closed with 'duckdb_close'.\n\n path: Path to the database file on disk, or `nullptr` or `:memory:` to open an in-memory database.\n out_database: The result database object.\n config: (Optional) configuration used to start up the database system.\n out_error: If set and the function returns DuckDBError, this will contain the reason why the start-up failed.\nNote that the error must be freed using `duckdb_free`.\n returns: `DuckDBSuccess` on success or `DuckDBError` on failure."] - pub fn duckdb_open_ext( - path: *const ::std::os::raw::c_char, - out_database: *mut duckdb_database, - config: duckdb_config, - out_error: *mut *mut ::std::os::raw::c_char, - ) -> duckdb_state; -} -extern "C" { - #[doc = "Closes the specified database and de-allocates all memory allocated for that database.\nThis should be called after you are done with any database allocated through `duckdb_open` or `duckdb_open_ext`.\nNote that failing to call `duckdb_close` (in case of e.g. a program crash) will not cause data corruption.\nStill, it is recommended to always correctly close a database object after you are done with it.\n\n database: The database object to shut down."] - pub fn duckdb_close(database: *mut duckdb_database); -} -extern "C" { - #[doc = "Opens a connection to a database. Connections are required to query the database, and store transactional state\nassociated with the connection.\nThe instantiated connection should be closed using 'duckdb_disconnect'.\n\n database: The database file to connect to.\n out_connection: The result connection object.\n returns: `DuckDBSuccess` on success or `DuckDBError` on failure."] - pub fn duckdb_connect(database: duckdb_database, out_connection: *mut duckdb_connection) -> duckdb_state; -} -extern "C" { - #[doc = "Interrupt running query\n\n connection: The connection to interrupt"] - pub fn duckdb_interrupt(connection: duckdb_connection); -} -extern "C" { - #[doc = "Get progress of the running query\n\n connection: The working connection\n returns: -1 if no progress or a percentage of the progress"] - pub fn duckdb_query_progress(connection: duckdb_connection) -> duckdb_query_progress_type; -} -extern "C" { - #[doc = "Closes the specified connection and de-allocates all memory allocated for that connection.\n\n connection: The connection to close."] - pub fn duckdb_disconnect(connection: *mut duckdb_connection); -} -extern "C" { - #[doc = "Returns the version of the linked DuckDB, with a version postfix for dev versions\n\nUsually used for developing C extensions that must return this for a compatibility check."] - pub fn duckdb_library_version() -> *const ::std::os::raw::c_char; -} -extern "C" { - #[doc = "Initializes an empty configuration object that can be used to provide start-up options for the DuckDB instance\nthrough `duckdb_open_ext`.\nThe duckdb_config must be destroyed using 'duckdb_destroy_config'\n\nThis will always succeed unless there is a malloc failure.\n\n out_config: The result configuration object.\n returns: `DuckDBSuccess` on success or `DuckDBError` on failure."] - pub fn duckdb_create_config(out_config: *mut duckdb_config) -> duckdb_state; -} -extern "C" { - #[doc = "This returns the total amount of configuration options available for usage with `duckdb_get_config_flag`.\n\nThis should not be called in a loop as it internally loops over all the options.\n\n returns: The amount of config options available."] - pub fn duckdb_config_count() -> usize; -} -extern "C" { - #[doc = "Obtains a human-readable name and description of a specific configuration option. This can be used to e.g.\ndisplay configuration options. This will succeed unless `index` is out of range (i.e. `>= duckdb_config_count`).\n\nThe result name or description MUST NOT be freed.\n\n index: The index of the configuration option (between 0 and `duckdb_config_count`)\n out_name: A name of the configuration flag.\n out_description: A description of the configuration flag.\n returns: `DuckDBSuccess` on success or `DuckDBError` on failure."] - pub fn duckdb_get_config_flag( - index: usize, - out_name: *mut *const ::std::os::raw::c_char, - out_description: *mut *const ::std::os::raw::c_char, - ) -> duckdb_state; -} -extern "C" { - #[doc = "Sets the specified option for the specified configuration. The configuration option is indicated by name.\nTo obtain a list of config options, see `duckdb_get_config_flag`.\n\nIn the source code, configuration options are defined in `config.cpp`.\n\nThis can fail if either the name is invalid, or if the value provided for the option is invalid.\n\n duckdb_config: The configuration object to set the option on.\n name: The name of the configuration flag to set.\n option: The value to set the configuration flag to.\n returns: `DuckDBSuccess` on success or `DuckDBError` on failure."] - pub fn duckdb_set_config( - config: duckdb_config, - name: *const ::std::os::raw::c_char, - option: *const ::std::os::raw::c_char, - ) -> duckdb_state; -} -extern "C" { - #[doc = "Destroys the specified configuration object and de-allocates all memory allocated for the object.\n\n config: The configuration object to destroy."] - pub fn duckdb_destroy_config(config: *mut duckdb_config); -} -extern "C" { - #[doc = "Executes a SQL query within a connection and stores the full (materialized) result in the out_result pointer.\nIf the query fails to execute, DuckDBError is returned and the error message can be retrieved by calling\n`duckdb_result_error`.\n\nNote that after running `duckdb_query`, `duckdb_destroy_result` must be called on the result object even if the\nquery fails, otherwise the error stored within the result will not be freed correctly.\n\n connection: The connection to perform the query in.\n query: The SQL query to run.\n out_result: The query result.\n returns: `DuckDBSuccess` on success or `DuckDBError` on failure."] - pub fn duckdb_query( - connection: duckdb_connection, - query: *const ::std::os::raw::c_char, - out_result: *mut duckdb_result, - ) -> duckdb_state; -} -extern "C" { - #[doc = "Closes the result and de-allocates all memory allocated for that connection.\n\n result: The result to destroy."] - pub fn duckdb_destroy_result(result: *mut duckdb_result); -} -extern "C" { - #[doc = "Returns the column name of the specified column. The result should not need to be freed; the column names will\nautomatically be destroyed when the result is destroyed.\n\nReturns `NULL` if the column is out of range.\n\n result: The result object to fetch the column name from.\n col: The column index.\n returns: The column name of the specified column."] - pub fn duckdb_column_name(result: *mut duckdb_result, col: idx_t) -> *const ::std::os::raw::c_char; -} -extern "C" { - #[doc = "Returns the column type of the specified column.\n\nReturns `DUCKDB_TYPE_INVALID` if the column is out of range.\n\n result: The result object to fetch the column type from.\n col: The column index.\n returns: The column type of the specified column."] - pub fn duckdb_column_type(result: *mut duckdb_result, col: idx_t) -> duckdb_type; -} -extern "C" { - #[doc = "Returns the statement type of the statement that was executed\n\n result: The result object to fetch the statement type from.\n returns: duckdb_statement_type value or DUCKDB_STATEMENT_TYPE_INVALID"] - pub fn duckdb_result_statement_type(result: duckdb_result) -> duckdb_statement_type; -} -extern "C" { - #[doc = "Returns the logical column type of the specified column.\n\nThe return type of this call should be destroyed with `duckdb_destroy_logical_type`.\n\nReturns `NULL` if the column is out of range.\n\n result: The result object to fetch the column type from.\n col: The column index.\n returns: The logical column type of the specified column."] - pub fn duckdb_column_logical_type(result: *mut duckdb_result, col: idx_t) -> duckdb_logical_type; -} -extern "C" { - #[doc = "Returns the number of columns present in a the result object.\n\n result: The result object.\n returns: The number of columns present in the result object."] - pub fn duckdb_column_count(result: *mut duckdb_result) -> idx_t; -} -extern "C" { - #[doc = "Returns the number of rows present in the result object.\n\n result: The result object.\n returns: The number of rows present in the result object."] - pub fn duckdb_row_count(result: *mut duckdb_result) -> idx_t; -} -extern "C" { - #[doc = "Returns the number of rows changed by the query stored in the result. This is relevant only for INSERT/UPDATE/DELETE\nqueries. For other queries the rows_changed will be 0.\n\n result: The result object.\n returns: The number of rows changed."] - pub fn duckdb_rows_changed(result: *mut duckdb_result) -> idx_t; -} -extern "C" { - #[doc = "DEPRECATED**: Prefer using `duckdb_result_get_chunk` instead.\n\nReturns the data of a specific column of a result in columnar format.\n\nThe function returns a dense array which contains the result data. The exact type stored in the array depends on the\ncorresponding duckdb_type (as provided by `duckdb_column_type`). For the exact type by which the data should be\naccessed, see the comments in [the types section](types) or the `DUCKDB_TYPE` enum.\n\nFor example, for a column of type `DUCKDB_TYPE_INTEGER`, rows can be accessed in the following manner:\n```c\nint32_t *data = (int32_t *) duckdb_column_data(&result, 0);\nprintf(\"Data for row %d: %d\\n\", row, data[row]);\n```\n\n result: The result object to fetch the column data from.\n col: The column index.\n returns: The column data of the specified column."] - pub fn duckdb_column_data(result: *mut duckdb_result, col: idx_t) -> *mut ::std::os::raw::c_void; -} -extern "C" { - #[doc = "DEPRECATED**: Prefer using `duckdb_result_get_chunk` instead.\n\nReturns the nullmask of a specific column of a result in columnar format. The nullmask indicates for every row\nwhether or not the corresponding row is `NULL`. If a row is `NULL`, the values present in the array provided\nby `duckdb_column_data` are undefined.\n\n```c\nint32_t *data = (int32_t *) duckdb_column_data(&result, 0);\nbool *nullmask = duckdb_nullmask_data(&result, 0);\nif (nullmask[row]) {\nprintf(\"Data for row %d: NULL\\n\", row);\n} else {\nprintf(\"Data for row %d: %d\\n\", row, data[row]);\n}\n```\n\n result: The result object to fetch the nullmask from.\n col: The column index.\n returns: The nullmask of the specified column."] - pub fn duckdb_nullmask_data(result: *mut duckdb_result, col: idx_t) -> *mut bool; -} -extern "C" { - #[doc = "Returns the error message contained within the result. The error is only set if `duckdb_query` returns `DuckDBError`.\n\nThe result of this function must not be freed. It will be cleaned up when `duckdb_destroy_result` is called.\n\n result: The result object to fetch the error from.\n returns: The error of the result."] - pub fn duckdb_result_error(result: *mut duckdb_result) -> *const ::std::os::raw::c_char; -} -extern "C" { - #[doc = "Fetches a data chunk from the duckdb_result. This function should be called repeatedly until the result is exhausted.\n\nThe result must be destroyed with `duckdb_destroy_data_chunk`.\n\nThis function supersedes all `duckdb_value` functions, as well as the `duckdb_column_data` and `duckdb_nullmask_data`\nfunctions. It results in significantly better performance, and should be preferred in newer code-bases.\n\nIf this function is used, none of the other result functions can be used and vice versa (i.e. this function cannot be\nmixed with the legacy result functions).\n\nUse `duckdb_result_chunk_count` to figure out how many chunks there are in the result.\n\n result: The result object to fetch the data chunk from.\n chunk_index: The chunk index to fetch from.\n returns: The resulting data chunk. Returns `NULL` if the chunk index is out of bounds."] - pub fn duckdb_result_get_chunk(result: duckdb_result, chunk_index: idx_t) -> duckdb_data_chunk; -} -extern "C" { - #[doc = "Checks if the type of the internal result is StreamQueryResult.\n\n result: The result object to check.\n returns: Whether or not the result object is of the type StreamQueryResult"] - pub fn duckdb_result_is_streaming(result: duckdb_result) -> bool; -} -extern "C" { - #[doc = "Returns the number of data chunks present in the result.\n\n result: The result object\n returns: Number of data chunks present in the result."] - pub fn duckdb_result_chunk_count(result: duckdb_result) -> idx_t; -} -extern "C" { - #[doc = "Returns the return_type of the given result, or DUCKDB_RETURN_TYPE_INVALID on error\n\n result: The result object\n returns: The return_type"] - pub fn duckdb_result_return_type(result: duckdb_result) -> duckdb_result_type; -} -extern "C" { - #[doc = " returns: The boolean value at the specified location, or false if the value cannot be converted."] - pub fn duckdb_value_boolean(result: *mut duckdb_result, col: idx_t, row: idx_t) -> bool; -} -extern "C" { - #[doc = " returns: The int8_t value at the specified location, or 0 if the value cannot be converted."] - pub fn duckdb_value_int8(result: *mut duckdb_result, col: idx_t, row: idx_t) -> i8; -} -extern "C" { - #[doc = " returns: The int16_t value at the specified location, or 0 if the value cannot be converted."] - pub fn duckdb_value_int16(result: *mut duckdb_result, col: idx_t, row: idx_t) -> i16; -} -extern "C" { - #[doc = " returns: The int32_t value at the specified location, or 0 if the value cannot be converted."] - pub fn duckdb_value_int32(result: *mut duckdb_result, col: idx_t, row: idx_t) -> i32; -} -extern "C" { - #[doc = " returns: The int64_t value at the specified location, or 0 if the value cannot be converted."] - pub fn duckdb_value_int64(result: *mut duckdb_result, col: idx_t, row: idx_t) -> i64; -} -extern "C" { - #[doc = " returns: The duckdb_hugeint value at the specified location, or 0 if the value cannot be converted."] - pub fn duckdb_value_hugeint(result: *mut duckdb_result, col: idx_t, row: idx_t) -> duckdb_hugeint; -} -extern "C" { - #[doc = " returns: The duckdb_uhugeint value at the specified location, or 0 if the value cannot be converted."] - pub fn duckdb_value_uhugeint(result: *mut duckdb_result, col: idx_t, row: idx_t) -> duckdb_uhugeint; -} -extern "C" { - #[doc = " returns: The duckdb_decimal value at the specified location, or 0 if the value cannot be converted."] - pub fn duckdb_value_decimal(result: *mut duckdb_result, col: idx_t, row: idx_t) -> duckdb_decimal; -} -extern "C" { - #[doc = " returns: The uint8_t value at the specified location, or 0 if the value cannot be converted."] - pub fn duckdb_value_uint8(result: *mut duckdb_result, col: idx_t, row: idx_t) -> u8; -} -extern "C" { - #[doc = " returns: The uint16_t value at the specified location, or 0 if the value cannot be converted."] - pub fn duckdb_value_uint16(result: *mut duckdb_result, col: idx_t, row: idx_t) -> u16; -} -extern "C" { - #[doc = " returns: The uint32_t value at the specified location, or 0 if the value cannot be converted."] - pub fn duckdb_value_uint32(result: *mut duckdb_result, col: idx_t, row: idx_t) -> u32; -} -extern "C" { - #[doc = " returns: The uint64_t value at the specified location, or 0 if the value cannot be converted."] - pub fn duckdb_value_uint64(result: *mut duckdb_result, col: idx_t, row: idx_t) -> u64; -} -extern "C" { - #[doc = " returns: The float value at the specified location, or 0 if the value cannot be converted."] - pub fn duckdb_value_float(result: *mut duckdb_result, col: idx_t, row: idx_t) -> f32; -} -extern "C" { - #[doc = " returns: The double value at the specified location, or 0 if the value cannot be converted."] - pub fn duckdb_value_double(result: *mut duckdb_result, col: idx_t, row: idx_t) -> f64; -} -extern "C" { - #[doc = " returns: The duckdb_date value at the specified location, or 0 if the value cannot be converted."] - pub fn duckdb_value_date(result: *mut duckdb_result, col: idx_t, row: idx_t) -> duckdb_date; -} -extern "C" { - #[doc = " returns: The duckdb_time value at the specified location, or 0 if the value cannot be converted."] - pub fn duckdb_value_time(result: *mut duckdb_result, col: idx_t, row: idx_t) -> duckdb_time; -} -extern "C" { - #[doc = " returns: The duckdb_timestamp value at the specified location, or 0 if the value cannot be converted."] - pub fn duckdb_value_timestamp(result: *mut duckdb_result, col: idx_t, row: idx_t) -> duckdb_timestamp; -} -extern "C" { - #[doc = " returns: The duckdb_interval value at the specified location, or 0 if the value cannot be converted."] - pub fn duckdb_value_interval(result: *mut duckdb_result, col: idx_t, row: idx_t) -> duckdb_interval; -} -extern "C" { - #[doc = " DEPRECATED: use duckdb_value_string instead. This function does not work correctly if the string contains null bytes.\n returns: The text value at the specified location as a null-terminated string, or nullptr if the value cannot be\nconverted. The result must be freed with `duckdb_free`."] - pub fn duckdb_value_varchar(result: *mut duckdb_result, col: idx_t, row: idx_t) -> *mut ::std::os::raw::c_char; -} -extern "C" { - #[doc = " returns: The string value at the specified location.\n The resulting field \"string.data\" must be freed with `duckdb_free.`"] - pub fn duckdb_value_string(result: *mut duckdb_result, col: idx_t, row: idx_t) -> duckdb_string; -} -extern "C" { - #[doc = " DEPRECATED: use duckdb_value_string_internal instead. This function does not work correctly if the string contains\nnull bytes.\n returns: The char* value at the specified location. ONLY works on VARCHAR columns and does not auto-cast.\nIf the column is NOT a VARCHAR column this function will return NULL.\n\nThe result must NOT be freed."] - pub fn duckdb_value_varchar_internal( - result: *mut duckdb_result, - col: idx_t, - row: idx_t, - ) -> *mut ::std::os::raw::c_char; -} -extern "C" { - #[doc = " DEPRECATED: use duckdb_value_string_internal instead. This function does not work correctly if the string contains\nnull bytes.\n returns: The char* value at the specified location. ONLY works on VARCHAR columns and does not auto-cast.\nIf the column is NOT a VARCHAR column this function will return NULL.\n\nThe result must NOT be freed."] - pub fn duckdb_value_string_internal(result: *mut duckdb_result, col: idx_t, row: idx_t) -> duckdb_string; -} -extern "C" { - #[doc = " returns: The duckdb_blob value at the specified location. Returns a blob with blob.data set to nullptr if the\nvalue cannot be converted. The resulting field \"blob.data\" must be freed with `duckdb_free.`"] - pub fn duckdb_value_blob(result: *mut duckdb_result, col: idx_t, row: idx_t) -> duckdb_blob; -} -extern "C" { - #[doc = " returns: Returns true if the value at the specified index is NULL, and false otherwise."] - pub fn duckdb_value_is_null(result: *mut duckdb_result, col: idx_t, row: idx_t) -> bool; -} -extern "C" { - #[doc = "Allocate `size` bytes of memory using the duckdb internal malloc function. Any memory allocated in this manner\nshould be freed using `duckdb_free`.\n\n size: The number of bytes to allocate.\n returns: A pointer to the allocated memory region."] - pub fn duckdb_malloc(size: usize) -> *mut ::std::os::raw::c_void; -} -extern "C" { - #[doc = "Free a value returned from `duckdb_malloc`, `duckdb_value_varchar`, `duckdb_value_blob`, or\n`duckdb_value_string`.\n\n ptr: The memory region to de-allocate."] - pub fn duckdb_free(ptr: *mut ::std::os::raw::c_void); -} -extern "C" { - #[doc = "The internal vector size used by DuckDB.\nThis is the amount of tuples that will fit into a data chunk created by `duckdb_create_data_chunk`.\n\n returns: The vector size."] - pub fn duckdb_vector_size() -> idx_t; -} -extern "C" { - #[doc = "Whether or not the duckdb_string_t value is inlined.\nThis means that the data of the string does not have a separate allocation."] - pub fn duckdb_string_is_inlined(string: duckdb_string_t) -> bool; -} -extern "C" { - #[doc = "Decompose a `duckdb_date` object into year, month and date (stored as `duckdb_date_struct`).\n\n date: The date object, as obtained from a `DUCKDB_TYPE_DATE` column.\n returns: The `duckdb_date_struct` with the decomposed elements."] - pub fn duckdb_from_date(date: duckdb_date) -> duckdb_date_struct; -} -extern "C" { - #[doc = "Re-compose a `duckdb_date` from year, month and date (`duckdb_date_struct`).\n\n date: The year, month and date stored in a `duckdb_date_struct`.\n returns: The `duckdb_date` element."] - pub fn duckdb_to_date(date: duckdb_date_struct) -> duckdb_date; -} -extern "C" { - #[doc = "Test a `duckdb_date` to see if it is a finite value.\n\n date: The date object, as obtained from a `DUCKDB_TYPE_DATE` column.\n returns: True if the date is finite, false if it is ±infinity."] - pub fn duckdb_is_finite_date(date: duckdb_date) -> bool; -} -extern "C" { - #[doc = "Decompose a `duckdb_time` object into hour, minute, second and microsecond (stored as `duckdb_time_struct`).\n\n time: The time object, as obtained from a `DUCKDB_TYPE_TIME` column.\n returns: The `duckdb_time_struct` with the decomposed elements."] - pub fn duckdb_from_time(time: duckdb_time) -> duckdb_time_struct; -} -extern "C" { - #[doc = "Create a `duckdb_time_tz` object from micros and a timezone offset.\n\n micros: The microsecond component of the time.\n offset: The timezone offset component of the time.\n returns: The `duckdb_time_tz` element."] - pub fn duckdb_create_time_tz(micros: i64, offset: i32) -> duckdb_time_tz; -} -extern "C" { - #[doc = "Decompose a TIME_TZ objects into micros and a timezone offset.\n\nUse `duckdb_from_time` to further decompose the micros into hour, minute, second and microsecond.\n\n micros: The time object, as obtained from a `DUCKDB_TYPE_TIME_TZ` column.\n out_micros: The microsecond component of the time.\n out_offset: The timezone offset component of the time."] - pub fn duckdb_from_time_tz(micros: duckdb_time_tz) -> duckdb_time_tz_struct; -} -extern "C" { - #[doc = "Re-compose a `duckdb_time` from hour, minute, second and microsecond (`duckdb_time_struct`).\n\n time: The hour, minute, second and microsecond in a `duckdb_time_struct`.\n returns: The `duckdb_time` element."] - pub fn duckdb_to_time(time: duckdb_time_struct) -> duckdb_time; -} -extern "C" { - #[doc = "Decompose a `duckdb_timestamp` object into a `duckdb_timestamp_struct`.\n\n ts: The ts object, as obtained from a `DUCKDB_TYPE_TIMESTAMP` column.\n returns: The `duckdb_timestamp_struct` with the decomposed elements."] - pub fn duckdb_from_timestamp(ts: duckdb_timestamp) -> duckdb_timestamp_struct; -} -extern "C" { - #[doc = "Re-compose a `duckdb_timestamp` from a duckdb_timestamp_struct.\n\n ts: The de-composed elements in a `duckdb_timestamp_struct`.\n returns: The `duckdb_timestamp` element."] - pub fn duckdb_to_timestamp(ts: duckdb_timestamp_struct) -> duckdb_timestamp; -} -extern "C" { - #[doc = "Test a `duckdb_timestamp` to see if it is a finite value.\n\n ts: The timestamp object, as obtained from a `DUCKDB_TYPE_TIMESTAMP` column.\n returns: True if the timestamp is finite, false if it is ±infinity."] - pub fn duckdb_is_finite_timestamp(ts: duckdb_timestamp) -> bool; -} -extern "C" { - #[doc = "Converts a duckdb_hugeint object (as obtained from a `DUCKDB_TYPE_HUGEINT` column) into a double.\n\n val: The hugeint value.\n returns: The converted `double` element."] - pub fn duckdb_hugeint_to_double(val: duckdb_hugeint) -> f64; -} -extern "C" { - #[doc = "Converts a double value to a duckdb_hugeint object.\n\nIf the conversion fails because the double value is too big the result will be 0.\n\n val: The double value.\n returns: The converted `duckdb_hugeint` element."] - pub fn duckdb_double_to_hugeint(val: f64) -> duckdb_hugeint; -} -extern "C" { - #[doc = "Converts a duckdb_uhugeint object (as obtained from a `DUCKDB_TYPE_UHUGEINT` column) into a double.\n\n val: The uhugeint value.\n returns: The converted `double` element."] - pub fn duckdb_uhugeint_to_double(val: duckdb_uhugeint) -> f64; -} -extern "C" { - #[doc = "Converts a double value to a duckdb_uhugeint object.\n\nIf the conversion fails because the double value is too big the result will be 0.\n\n val: The double value.\n returns: The converted `duckdb_uhugeint` element."] - pub fn duckdb_double_to_uhugeint(val: f64) -> duckdb_uhugeint; -} -extern "C" { - #[doc = "Converts a double value to a duckdb_decimal object.\n\nIf the conversion fails because the double value is too big, or the width/scale are invalid the result will be 0.\n\n val: The double value.\n returns: The converted `duckdb_decimal` element."] - pub fn duckdb_double_to_decimal(val: f64, width: u8, scale: u8) -> duckdb_decimal; -} -extern "C" { - #[doc = "Converts a duckdb_decimal object (as obtained from a `DUCKDB_TYPE_DECIMAL` column) into a double.\n\n val: The decimal value.\n returns: The converted `double` element."] - pub fn duckdb_decimal_to_double(val: duckdb_decimal) -> f64; -} -extern "C" { - #[doc = "Create a prepared statement object from a query.\n\nNote that after calling `duckdb_prepare`, the prepared statement should always be destroyed using\n`duckdb_destroy_prepare`, even if the prepare fails.\n\nIf the prepare fails, `duckdb_prepare_error` can be called to obtain the reason why the prepare failed.\n\n connection: The connection object\n query: The SQL query to prepare\n out_prepared_statement: The resulting prepared statement object\n returns: `DuckDBSuccess` on success or `DuckDBError` on failure."] - pub fn duckdb_prepare( - connection: duckdb_connection, - query: *const ::std::os::raw::c_char, - out_prepared_statement: *mut duckdb_prepared_statement, - ) -> duckdb_state; -} -extern "C" { - #[doc = "Closes the prepared statement and de-allocates all memory allocated for the statement.\n\n prepared_statement: The prepared statement to destroy."] - pub fn duckdb_destroy_prepare(prepared_statement: *mut duckdb_prepared_statement); -} -extern "C" { - #[doc = "Returns the error message associated with the given prepared statement.\nIf the prepared statement has no error message, this returns `nullptr` instead.\n\nThe error message should not be freed. It will be de-allocated when `duckdb_destroy_prepare` is called.\n\n prepared_statement: The prepared statement to obtain the error from.\n returns: The error message, or `nullptr` if there is none."] - pub fn duckdb_prepare_error(prepared_statement: duckdb_prepared_statement) -> *const ::std::os::raw::c_char; -} -extern "C" { - #[doc = "Returns the number of parameters that can be provided to the given prepared statement.\n\nReturns 0 if the query was not successfully prepared.\n\n prepared_statement: The prepared statement to obtain the number of parameters for."] - pub fn duckdb_nparams(prepared_statement: duckdb_prepared_statement) -> idx_t; -} -extern "C" { - #[doc = "Returns the name used to identify the parameter\nThe returned string should be freed using `duckdb_free`.\n\nReturns NULL if the index is out of range for the provided prepared statement.\n\n prepared_statement: The prepared statement for which to get the parameter name from."] - pub fn duckdb_parameter_name( - prepared_statement: duckdb_prepared_statement, - index: idx_t, - ) -> *const ::std::os::raw::c_char; -} -extern "C" { - #[doc = "Returns the parameter type for the parameter at the given index.\n\nReturns `DUCKDB_TYPE_INVALID` if the parameter index is out of range or the statement was not successfully prepared.\n\n prepared_statement: The prepared statement.\n param_idx: The parameter index.\n returns: The parameter type"] - pub fn duckdb_param_type(prepared_statement: duckdb_prepared_statement, param_idx: idx_t) -> duckdb_type; -} -extern "C" { - #[doc = "Clear the params bind to the prepared statement."] - pub fn duckdb_clear_bindings(prepared_statement: duckdb_prepared_statement) -> duckdb_state; -} -extern "C" { - #[doc = "Returns the statement type of the statement to be executed\n\n statement: The prepared statement.\n returns: duckdb_statement_type value or DUCKDB_STATEMENT_TYPE_INVALID"] - pub fn duckdb_prepared_statement_type(statement: duckdb_prepared_statement) -> duckdb_statement_type; -} -extern "C" { - #[doc = "Binds a value to the prepared statement at the specified index."] - pub fn duckdb_bind_value( - prepared_statement: duckdb_prepared_statement, - param_idx: idx_t, - val: duckdb_value, - ) -> duckdb_state; -} -extern "C" { - #[doc = "Retrieve the index of the parameter for the prepared statement, identified by name"] - pub fn duckdb_bind_parameter_index( - prepared_statement: duckdb_prepared_statement, - param_idx_out: *mut idx_t, - name: *const ::std::os::raw::c_char, - ) -> duckdb_state; -} -extern "C" { - #[doc = "Binds a bool value to the prepared statement at the specified index."] - pub fn duckdb_bind_boolean( - prepared_statement: duckdb_prepared_statement, - param_idx: idx_t, - val: bool, - ) -> duckdb_state; -} -extern "C" { - #[doc = "Binds an int8_t value to the prepared statement at the specified index."] - pub fn duckdb_bind_int8(prepared_statement: duckdb_prepared_statement, param_idx: idx_t, val: i8) -> duckdb_state; -} -extern "C" { - #[doc = "Binds an int16_t value to the prepared statement at the specified index."] - pub fn duckdb_bind_int16(prepared_statement: duckdb_prepared_statement, param_idx: idx_t, val: i16) - -> duckdb_state; -} -extern "C" { - #[doc = "Binds an int32_t value to the prepared statement at the specified index."] - pub fn duckdb_bind_int32(prepared_statement: duckdb_prepared_statement, param_idx: idx_t, val: i32) - -> duckdb_state; -} -extern "C" { - #[doc = "Binds an int64_t value to the prepared statement at the specified index."] - pub fn duckdb_bind_int64(prepared_statement: duckdb_prepared_statement, param_idx: idx_t, val: i64) - -> duckdb_state; -} -extern "C" { - #[doc = "Binds a duckdb_hugeint value to the prepared statement at the specified index."] - pub fn duckdb_bind_hugeint( - prepared_statement: duckdb_prepared_statement, - param_idx: idx_t, - val: duckdb_hugeint, - ) -> duckdb_state; -} -extern "C" { - #[doc = "Binds an duckdb_uhugeint value to the prepared statement at the specified index."] - pub fn duckdb_bind_uhugeint( - prepared_statement: duckdb_prepared_statement, - param_idx: idx_t, - val: duckdb_uhugeint, - ) -> duckdb_state; -} -extern "C" { - #[doc = "Binds a duckdb_decimal value to the prepared statement at the specified index."] - pub fn duckdb_bind_decimal( - prepared_statement: duckdb_prepared_statement, - param_idx: idx_t, - val: duckdb_decimal, - ) -> duckdb_state; -} -extern "C" { - #[doc = "Binds an uint8_t value to the prepared statement at the specified index."] - pub fn duckdb_bind_uint8(prepared_statement: duckdb_prepared_statement, param_idx: idx_t, val: u8) -> duckdb_state; -} -extern "C" { - #[doc = "Binds an uint16_t value to the prepared statement at the specified index."] - pub fn duckdb_bind_uint16( - prepared_statement: duckdb_prepared_statement, - param_idx: idx_t, - val: u16, - ) -> duckdb_state; -} -extern "C" { - #[doc = "Binds an uint32_t value to the prepared statement at the specified index."] - pub fn duckdb_bind_uint32( - prepared_statement: duckdb_prepared_statement, - param_idx: idx_t, - val: u32, - ) -> duckdb_state; -} -extern "C" { - #[doc = "Binds an uint64_t value to the prepared statement at the specified index."] - pub fn duckdb_bind_uint64( - prepared_statement: duckdb_prepared_statement, - param_idx: idx_t, - val: u64, - ) -> duckdb_state; -} -extern "C" { - #[doc = "Binds a float value to the prepared statement at the specified index."] - pub fn duckdb_bind_float(prepared_statement: duckdb_prepared_statement, param_idx: idx_t, val: f32) - -> duckdb_state; -} -extern "C" { - #[doc = "Binds a double value to the prepared statement at the specified index."] - pub fn duckdb_bind_double( - prepared_statement: duckdb_prepared_statement, - param_idx: idx_t, - val: f64, - ) -> duckdb_state; -} -extern "C" { - #[doc = "Binds a duckdb_date value to the prepared statement at the specified index."] - pub fn duckdb_bind_date( - prepared_statement: duckdb_prepared_statement, - param_idx: idx_t, - val: duckdb_date, - ) -> duckdb_state; -} -extern "C" { - #[doc = "Binds a duckdb_time value to the prepared statement at the specified index."] - pub fn duckdb_bind_time( - prepared_statement: duckdb_prepared_statement, - param_idx: idx_t, - val: duckdb_time, - ) -> duckdb_state; -} -extern "C" { - #[doc = "Binds a duckdb_timestamp value to the prepared statement at the specified index."] - pub fn duckdb_bind_timestamp( - prepared_statement: duckdb_prepared_statement, - param_idx: idx_t, - val: duckdb_timestamp, - ) -> duckdb_state; -} -extern "C" { - #[doc = "Binds a duckdb_interval value to the prepared statement at the specified index."] - pub fn duckdb_bind_interval( - prepared_statement: duckdb_prepared_statement, - param_idx: idx_t, - val: duckdb_interval, - ) -> duckdb_state; -} -extern "C" { - #[doc = "Binds a null-terminated varchar value to the prepared statement at the specified index."] - pub fn duckdb_bind_varchar( - prepared_statement: duckdb_prepared_statement, - param_idx: idx_t, - val: *const ::std::os::raw::c_char, - ) -> duckdb_state; -} -extern "C" { - #[doc = "Binds a varchar value to the prepared statement at the specified index."] - pub fn duckdb_bind_varchar_length( - prepared_statement: duckdb_prepared_statement, - param_idx: idx_t, - val: *const ::std::os::raw::c_char, - length: idx_t, - ) -> duckdb_state; -} -extern "C" { - #[doc = "Binds a blob value to the prepared statement at the specified index."] - pub fn duckdb_bind_blob( - prepared_statement: duckdb_prepared_statement, - param_idx: idx_t, - data: *const ::std::os::raw::c_void, - length: idx_t, - ) -> duckdb_state; -} -extern "C" { - #[doc = "Binds a NULL value to the prepared statement at the specified index."] - pub fn duckdb_bind_null(prepared_statement: duckdb_prepared_statement, param_idx: idx_t) -> duckdb_state; -} -extern "C" { - #[doc = "Executes the prepared statement with the given bound parameters, and returns a materialized query result.\n\nThis method can be called multiple times for each prepared statement, and the parameters can be modified\nbetween calls to this function.\n\nNote that the result must be freed with `duckdb_destroy_result`.\n\n prepared_statement: The prepared statement to execute.\n out_result: The query result.\n returns: `DuckDBSuccess` on success or `DuckDBError` on failure."] - pub fn duckdb_execute_prepared( - prepared_statement: duckdb_prepared_statement, - out_result: *mut duckdb_result, - ) -> duckdb_state; -} -extern "C" { - #[doc = "Executes the prepared statement with the given bound parameters, and returns an optionally-streaming query result.\nTo determine if the resulting query was in fact streamed, use `duckdb_result_is_streaming`\n\nThis method can be called multiple times for each prepared statement, and the parameters can be modified\nbetween calls to this function.\n\nNote that the result must be freed with `duckdb_destroy_result`.\n\n prepared_statement: The prepared statement to execute.\n out_result: The query result.\n returns: `DuckDBSuccess` on success or `DuckDBError` on failure."] - pub fn duckdb_execute_prepared_streaming( - prepared_statement: duckdb_prepared_statement, - out_result: *mut duckdb_result, - ) -> duckdb_state; -} -extern "C" { - #[doc = "Extract all statements from a query.\nNote that after calling `duckdb_extract_statements`, the extracted statements should always be destroyed using\n`duckdb_destroy_extracted`, even if no statements were extracted.\n\nIf the extract fails, `duckdb_extract_statements_error` can be called to obtain the reason why the extract failed.\n\n connection: The connection object\n query: The SQL query to extract\n out_extracted_statements: The resulting extracted statements object\n returns: The number of extracted statements or 0 on failure."] - pub fn duckdb_extract_statements( - connection: duckdb_connection, - query: *const ::std::os::raw::c_char, - out_extracted_statements: *mut duckdb_extracted_statements, - ) -> idx_t; -} -extern "C" { - #[doc = "Prepare an extracted statement.\nNote that after calling `duckdb_prepare_extracted_statement`, the prepared statement should always be destroyed using\n`duckdb_destroy_prepare`, even if the prepare fails.\n\nIf the prepare fails, `duckdb_prepare_error` can be called to obtain the reason why the prepare failed.\n\n connection: The connection object\n extracted_statements: The extracted statements object\n index: The index of the extracted statement to prepare\n out_prepared_statement: The resulting prepared statement object\n returns: `DuckDBSuccess` on success or `DuckDBError` on failure."] - pub fn duckdb_prepare_extracted_statement( - connection: duckdb_connection, - extracted_statements: duckdb_extracted_statements, - index: idx_t, - out_prepared_statement: *mut duckdb_prepared_statement, - ) -> duckdb_state; -} -extern "C" { - #[doc = "Returns the error message contained within the extracted statements.\nThe result of this function must not be freed. It will be cleaned up when `duckdb_destroy_extracted` is called.\n\n result: The extracted statements to fetch the error from.\n returns: The error of the extracted statements."] - pub fn duckdb_extract_statements_error( - extracted_statements: duckdb_extracted_statements, - ) -> *const ::std::os::raw::c_char; -} -extern "C" { - #[doc = "De-allocates all memory allocated for the extracted statements.\n extracted_statements: The extracted statements to destroy."] - pub fn duckdb_destroy_extracted(extracted_statements: *mut duckdb_extracted_statements); -} -extern "C" { - #[doc = "Executes the prepared statement with the given bound parameters, and returns a pending result.\nThe pending result represents an intermediate structure for a query that is not yet fully executed.\nThe pending result can be used to incrementally execute a query, returning control to the client between tasks.\n\nNote that after calling `duckdb_pending_prepared`, the pending result should always be destroyed using\n`duckdb_destroy_pending`, even if this function returns DuckDBError.\n\n prepared_statement: The prepared statement to execute.\n out_result: The pending query result.\n returns: `DuckDBSuccess` on success or `DuckDBError` on failure."] - pub fn duckdb_pending_prepared( - prepared_statement: duckdb_prepared_statement, - out_result: *mut duckdb_pending_result, - ) -> duckdb_state; -} -extern "C" { - #[doc = "Executes the prepared statement with the given bound parameters, and returns a pending result.\nThis pending result will create a streaming duckdb_result when executed.\nThe pending result represents an intermediate structure for a query that is not yet fully executed.\n\nNote that after calling `duckdb_pending_prepared_streaming`, the pending result should always be destroyed using\n`duckdb_destroy_pending`, even if this function returns DuckDBError.\n\n prepared_statement: The prepared statement to execute.\n out_result: The pending query result.\n returns: `DuckDBSuccess` on success or `DuckDBError` on failure."] - pub fn duckdb_pending_prepared_streaming( - prepared_statement: duckdb_prepared_statement, - out_result: *mut duckdb_pending_result, - ) -> duckdb_state; -} -extern "C" { - #[doc = "Closes the pending result and de-allocates all memory allocated for the result.\n\n pending_result: The pending result to destroy."] - pub fn duckdb_destroy_pending(pending_result: *mut duckdb_pending_result); -} -extern "C" { - #[doc = "Returns the error message contained within the pending result.\n\nThe result of this function must not be freed. It will be cleaned up when `duckdb_destroy_pending` is called.\n\n result: The pending result to fetch the error from.\n returns: The error of the pending result."] - pub fn duckdb_pending_error(pending_result: duckdb_pending_result) -> *const ::std::os::raw::c_char; -} -extern "C" { - #[doc = "Executes a single task within the query, returning whether or not the query is ready.\n\nIf this returns DUCKDB_PENDING_RESULT_READY, the duckdb_execute_pending function can be called to obtain the result.\nIf this returns DUCKDB_PENDING_RESULT_NOT_READY, the duckdb_pending_execute_task function should be called again.\nIf this returns DUCKDB_PENDING_ERROR, an error occurred during execution.\n\nThe error message can be obtained by calling duckdb_pending_error on the pending_result.\n\n pending_result: The pending result to execute a task within.\n returns: The state of the pending result after the execution."] - pub fn duckdb_pending_execute_task(pending_result: duckdb_pending_result) -> duckdb_pending_state; -} -extern "C" { - #[doc = "If this returns DUCKDB_PENDING_RESULT_READY, the duckdb_execute_pending function can be called to obtain the result.\nIf this returns DUCKDB_PENDING_RESULT_NOT_READY, the duckdb_pending_execute_check_state function should be called again.\nIf this returns DUCKDB_PENDING_ERROR, an error occurred during execution.\n\nThe error message can be obtained by calling duckdb_pending_error on the pending_result.\n\n pending_result: The pending result.\n returns: The state of the pending result."] - pub fn duckdb_pending_execute_check_state(pending_result: duckdb_pending_result) -> duckdb_pending_state; -} -extern "C" { - #[doc = "Fully execute a pending query result, returning the final query result.\n\nIf duckdb_pending_execute_task has been called until DUCKDB_PENDING_RESULT_READY was returned, this will return fast.\nOtherwise, all remaining tasks must be executed first.\n\nNote that the result must be freed with `duckdb_destroy_result`.\n\n pending_result: The pending result to execute.\n out_result: The result object.\n returns: `DuckDBSuccess` on success or `DuckDBError` on failure."] - pub fn duckdb_execute_pending( - pending_result: duckdb_pending_result, - out_result: *mut duckdb_result, - ) -> duckdb_state; -} -extern "C" { - #[doc = "Returns whether a duckdb_pending_state is finished executing. For example if `pending_state` is\nDUCKDB_PENDING_RESULT_READY, this function will return true.\n\n pending_state: The pending state on which to decide whether to finish execution.\n returns: Boolean indicating pending execution should be considered finished."] - pub fn duckdb_pending_execution_is_finished(pending_state: duckdb_pending_state) -> bool; -} -extern "C" { - #[doc = "Destroys the value and de-allocates all memory allocated for that type.\n\n value: The value to destroy."] - pub fn duckdb_destroy_value(value: *mut duckdb_value); -} -extern "C" { - #[doc = "Creates a value from a null-terminated string\n\n value: The null-terminated string\n returns: The value. This must be destroyed with `duckdb_destroy_value`."] - pub fn duckdb_create_varchar(text: *const ::std::os::raw::c_char) -> duckdb_value; -} -extern "C" { - #[doc = "Creates a value from a string\n\n value: The text\n length: The length of the text\n returns: The value. This must be destroyed with `duckdb_destroy_value`."] - pub fn duckdb_create_varchar_length(text: *const ::std::os::raw::c_char, length: idx_t) -> duckdb_value; -} -extern "C" { - #[doc = "Creates a value from an int64\n\n value: The bigint value\n returns: The value. This must be destroyed with `duckdb_destroy_value`."] - pub fn duckdb_create_int64(val: i64) -> duckdb_value; -} -extern "C" { - #[doc = "Creates a struct value from a type and an array of values\n\n type: The type of the struct\n values: The values for the struct fields\n returns: The value. This must be destroyed with `duckdb_destroy_value`."] - pub fn duckdb_create_struct_value(type_: duckdb_logical_type, values: *mut duckdb_value) -> duckdb_value; -} -extern "C" { - #[doc = "Creates a list value from a type and an array of values of length `value_count`\n\n type: The type of the list\n values: The values for the list\n value_count: The number of values in the list\n returns: The value. This must be destroyed with `duckdb_destroy_value`."] - pub fn duckdb_create_list_value( - type_: duckdb_logical_type, - values: *mut duckdb_value, - value_count: idx_t, - ) -> duckdb_value; -} -extern "C" { - #[doc = "Creates a array value from a type and an array of values of length `value_count`\n\n type: The type of the array\n values: The values for the array\n value_count: The number of values in the array\n returns: The value. This must be destroyed with `duckdb_destroy_value`."] - pub fn duckdb_create_array_value( - type_: duckdb_logical_type, - values: *mut duckdb_value, - value_count: idx_t, - ) -> duckdb_value; -} -extern "C" { - #[doc = "Obtains a string representation of the given value.\nThe result must be destroyed with `duckdb_free`.\n\n value: The value\n returns: The string value. This must be destroyed with `duckdb_free`."] - pub fn duckdb_get_varchar(value: duckdb_value) -> *mut ::std::os::raw::c_char; -} -extern "C" { - #[doc = "Obtains an int64 of the given value.\n\n value: The value\n returns: The int64 value, or 0 if no conversion is possible"] - pub fn duckdb_get_int64(value: duckdb_value) -> i64; -} -extern "C" { - #[doc = "Creates a `duckdb_logical_type` from a standard primitive type.\nThe resulting type should be destroyed with `duckdb_destroy_logical_type`.\n\nThis should not be used with `DUCKDB_TYPE_DECIMAL`.\n\n type: The primitive type to create.\n returns: The logical type."] - pub fn duckdb_create_logical_type(type_: duckdb_type) -> duckdb_logical_type; -} -extern "C" { - #[doc = "Returns the alias of a duckdb_logical_type, if one is set, else `NULL`.\nThe result must be destroyed with `duckdb_free`.\n\n type: The logical type to return the alias of\n returns: The alias or `NULL`"] - pub fn duckdb_logical_type_get_alias(type_: duckdb_logical_type) -> *mut ::std::os::raw::c_char; -} -extern "C" { - #[doc = "Creates a list type from its child type.\nThe resulting type should be destroyed with `duckdb_destroy_logical_type`.\n\n type: The child type of list type to create.\n returns: The logical type."] - pub fn duckdb_create_list_type(type_: duckdb_logical_type) -> duckdb_logical_type; -} -extern "C" { - #[doc = "Creates a array type from its child type.\nThe resulting type should be destroyed with `duckdb_destroy_logical_type`.\n\n type: The child type of array type to create.\n array_size: The number of elements in the array.\n returns: The logical type."] - pub fn duckdb_create_array_type(type_: duckdb_logical_type, array_size: idx_t) -> duckdb_logical_type; -} -extern "C" { - #[doc = "Creates a map type from its key type and value type.\nThe resulting type should be destroyed with `duckdb_destroy_logical_type`.\n\n type: The key type and value type of map type to create.\n returns: The logical type."] - pub fn duckdb_create_map_type( - key_type: duckdb_logical_type, - value_type: duckdb_logical_type, - ) -> duckdb_logical_type; -} -extern "C" { - #[doc = "Creates a UNION type from the passed types array.\nThe resulting type should be destroyed with `duckdb_destroy_logical_type`.\n\n types: The array of types that the union should consist of.\n type_amount: The size of the types array.\n returns: The logical type."] - pub fn duckdb_create_union_type( - member_types: *mut duckdb_logical_type, - member_names: *mut *const ::std::os::raw::c_char, - member_count: idx_t, - ) -> duckdb_logical_type; -} -extern "C" { - #[doc = "Creates a STRUCT type from the passed member name and type arrays.\nThe resulting type should be destroyed with `duckdb_destroy_logical_type`.\n\n member_types: The array of types that the struct should consist of.\n member_names: The array of names that the struct should consist of.\n member_count: The number of members that were specified for both arrays.\n returns: The logical type."] - pub fn duckdb_create_struct_type( - member_types: *mut duckdb_logical_type, - member_names: *mut *const ::std::os::raw::c_char, - member_count: idx_t, - ) -> duckdb_logical_type; -} -extern "C" { - #[doc = "Creates an ENUM type from the passed member name array.\nThe resulting type should be destroyed with `duckdb_destroy_logical_type`.\n\n enum_name: The name of the enum.\n member_names: The array of names that the enum should consist of.\n member_count: The number of elements that were specified in the array.\n returns: The logical type."] - pub fn duckdb_create_enum_type( - member_names: *mut *const ::std::os::raw::c_char, - member_count: idx_t, - ) -> duckdb_logical_type; -} -extern "C" { - #[doc = "Creates a `duckdb_logical_type` of type decimal with the specified width and scale.\nThe resulting type should be destroyed with `duckdb_destroy_logical_type`.\n\n width: The width of the decimal type\n scale: The scale of the decimal type\n returns: The logical type."] - pub fn duckdb_create_decimal_type(width: u8, scale: u8) -> duckdb_logical_type; -} -extern "C" { - #[doc = "Retrieves the enum type class of a `duckdb_logical_type`.\n\n type: The logical type object\n returns: The type id"] - pub fn duckdb_get_type_id(type_: duckdb_logical_type) -> duckdb_type; -} -extern "C" { - #[doc = "Retrieves the width of a decimal type.\n\n type: The logical type object\n returns: The width of the decimal type"] - pub fn duckdb_decimal_width(type_: duckdb_logical_type) -> u8; -} -extern "C" { - #[doc = "Retrieves the scale of a decimal type.\n\n type: The logical type object\n returns: The scale of the decimal type"] - pub fn duckdb_decimal_scale(type_: duckdb_logical_type) -> u8; -} -extern "C" { - #[doc = "Retrieves the internal storage type of a decimal type.\n\n type: The logical type object\n returns: The internal type of the decimal type"] - pub fn duckdb_decimal_internal_type(type_: duckdb_logical_type) -> duckdb_type; -} -extern "C" { - #[doc = "Retrieves the internal storage type of an enum type.\n\n type: The logical type object\n returns: The internal type of the enum type"] - pub fn duckdb_enum_internal_type(type_: duckdb_logical_type) -> duckdb_type; -} -extern "C" { - #[doc = "Retrieves the dictionary size of the enum type.\n\n type: The logical type object\n returns: The dictionary size of the enum type"] - pub fn duckdb_enum_dictionary_size(type_: duckdb_logical_type) -> u32; -} -extern "C" { - #[doc = "Retrieves the dictionary value at the specified position from the enum.\n\nThe result must be freed with `duckdb_free`.\n\n type: The logical type object\n index: The index in the dictionary\n returns: The string value of the enum type. Must be freed with `duckdb_free`."] - pub fn duckdb_enum_dictionary_value(type_: duckdb_logical_type, index: idx_t) -> *mut ::std::os::raw::c_char; -} -extern "C" { - #[doc = "Retrieves the child type of the given list type.\n\nThe result must be freed with `duckdb_destroy_logical_type`.\n\n type: The logical type object\n returns: The child type of the list type. Must be destroyed with `duckdb_destroy_logical_type`."] - pub fn duckdb_list_type_child_type(type_: duckdb_logical_type) -> duckdb_logical_type; -} -extern "C" { - #[doc = "Retrieves the child type of the given array type.\n\nThe result must be freed with `duckdb_destroy_logical_type`.\n\n type: The logical type object\n returns: The child type of the array type. Must be destroyed with `duckdb_destroy_logical_type`."] - pub fn duckdb_array_type_child_type(type_: duckdb_logical_type) -> duckdb_logical_type; -} -extern "C" { - #[doc = "Retrieves the array size of the given array type.\n\n type: The logical type object\n returns: The fixed number of elements the values of this array type can store."] - pub fn duckdb_array_type_array_size(type_: duckdb_logical_type) -> idx_t; -} -extern "C" { - #[doc = "Retrieves the key type of the given map type.\n\nThe result must be freed with `duckdb_destroy_logical_type`.\n\n type: The logical type object\n returns: The key type of the map type. Must be destroyed with `duckdb_destroy_logical_type`."] - pub fn duckdb_map_type_key_type(type_: duckdb_logical_type) -> duckdb_logical_type; -} -extern "C" { - #[doc = "Retrieves the value type of the given map type.\n\nThe result must be freed with `duckdb_destroy_logical_type`.\n\n type: The logical type object\n returns: The value type of the map type. Must be destroyed with `duckdb_destroy_logical_type`."] - pub fn duckdb_map_type_value_type(type_: duckdb_logical_type) -> duckdb_logical_type; -} -extern "C" { - #[doc = "Returns the number of children of a struct type.\n\n type: The logical type object\n returns: The number of children of a struct type."] - pub fn duckdb_struct_type_child_count(type_: duckdb_logical_type) -> idx_t; -} -extern "C" { - #[doc = "Retrieves the name of the struct child.\n\nThe result must be freed with `duckdb_free`.\n\n type: The logical type object\n index: The child index\n returns: The name of the struct type. Must be freed with `duckdb_free`."] - pub fn duckdb_struct_type_child_name(type_: duckdb_logical_type, index: idx_t) -> *mut ::std::os::raw::c_char; -} -extern "C" { - #[doc = "Retrieves the child type of the given struct type at the specified index.\n\nThe result must be freed with `duckdb_destroy_logical_type`.\n\n type: The logical type object\n index: The child index\n returns: The child type of the struct type. Must be destroyed with `duckdb_destroy_logical_type`."] - pub fn duckdb_struct_type_child_type(type_: duckdb_logical_type, index: idx_t) -> duckdb_logical_type; -} -extern "C" { - #[doc = "Returns the number of members that the union type has.\n\n type: The logical type (union) object\n returns: The number of members of a union type."] - pub fn duckdb_union_type_member_count(type_: duckdb_logical_type) -> idx_t; -} -extern "C" { - #[doc = "Retrieves the name of the union member.\n\nThe result must be freed with `duckdb_free`.\n\n type: The logical type object\n index: The child index\n returns: The name of the union member. Must be freed with `duckdb_free`."] - pub fn duckdb_union_type_member_name(type_: duckdb_logical_type, index: idx_t) -> *mut ::std::os::raw::c_char; -} -extern "C" { - #[doc = "Retrieves the child type of the given union member at the specified index.\n\nThe result must be freed with `duckdb_destroy_logical_type`.\n\n type: The logical type object\n index: The child index\n returns: The child type of the union member. Must be destroyed with `duckdb_destroy_logical_type`."] - pub fn duckdb_union_type_member_type(type_: duckdb_logical_type, index: idx_t) -> duckdb_logical_type; -} -extern "C" { - #[doc = "Destroys the logical type and de-allocates all memory allocated for that type.\n\n type: The logical type to destroy."] - pub fn duckdb_destroy_logical_type(type_: *mut duckdb_logical_type); -} -extern "C" { - #[doc = "Creates an empty DataChunk with the specified set of types.\n\nNote that the result must be destroyed with `duckdb_destroy_data_chunk`.\n\n types: An array of types of the data chunk.\n column_count: The number of columns.\n returns: The data chunk."] - pub fn duckdb_create_data_chunk(types: *mut duckdb_logical_type, column_count: idx_t) -> duckdb_data_chunk; -} -extern "C" { - #[doc = "Destroys the data chunk and de-allocates all memory allocated for that chunk.\n\n chunk: The data chunk to destroy."] - pub fn duckdb_destroy_data_chunk(chunk: *mut duckdb_data_chunk); -} -extern "C" { - #[doc = "Resets a data chunk, clearing the validity masks and setting the cardinality of the data chunk to 0.\n\n chunk: The data chunk to reset."] - pub fn duckdb_data_chunk_reset(chunk: duckdb_data_chunk); -} -extern "C" { - #[doc = "Retrieves the number of columns in a data chunk.\n\n chunk: The data chunk to get the data from\n returns: The number of columns in the data chunk"] - pub fn duckdb_data_chunk_get_column_count(chunk: duckdb_data_chunk) -> idx_t; -} -extern "C" { - #[doc = "Retrieves the vector at the specified column index in the data chunk.\n\nThe pointer to the vector is valid for as long as the chunk is alive.\nIt does NOT need to be destroyed.\n\n chunk: The data chunk to get the data from\n returns: The vector"] - pub fn duckdb_data_chunk_get_vector(chunk: duckdb_data_chunk, col_idx: idx_t) -> duckdb_vector; -} -extern "C" { - #[doc = "Retrieves the current number of tuples in a data chunk.\n\n chunk: The data chunk to get the data from\n returns: The number of tuples in the data chunk"] - pub fn duckdb_data_chunk_get_size(chunk: duckdb_data_chunk) -> idx_t; -} -extern "C" { - #[doc = "Sets the current number of tuples in a data chunk.\n\n chunk: The data chunk to set the size in\n size: The number of tuples in the data chunk"] - pub fn duckdb_data_chunk_set_size(chunk: duckdb_data_chunk, size: idx_t); -} -extern "C" { - #[doc = "Retrieves the column type of the specified vector.\n\nThe result must be destroyed with `duckdb_destroy_logical_type`.\n\n vector: The vector get the data from\n returns: The type of the vector"] - pub fn duckdb_vector_get_column_type(vector: duckdb_vector) -> duckdb_logical_type; -} -extern "C" { - #[doc = "Retrieves the data pointer of the vector.\n\nThe data pointer can be used to read or write values from the vector.\nHow to read or write values depends on the type of the vector.\n\n vector: The vector to get the data from\n returns: The data pointer"] - pub fn duckdb_vector_get_data(vector: duckdb_vector) -> *mut ::std::os::raw::c_void; -} -extern "C" { - #[doc = "Retrieves the validity mask pointer of the specified vector.\n\nIf all values are valid, this function MIGHT return NULL!\n\nThe validity mask is a bitset that signifies null-ness within the data chunk.\nIt is a series of uint64_t values, where each uint64_t value contains validity for 64 tuples.\nThe bit is set to 1 if the value is valid (i.e. not NULL) or 0 if the value is invalid (i.e. NULL).\n\nValidity of a specific value can be obtained like this:\n\nidx_t entry_idx = row_idx / 64;\nidx_t idx_in_entry = row_idx % 64;\nbool is_valid = validity_mask[entry_idx] & (1 << idx_in_entry);\n\nAlternatively, the (slower) duckdb_validity_row_is_valid function can be used.\n\n vector: The vector to get the data from\n returns: The pointer to the validity mask, or NULL if no validity mask is present"] - pub fn duckdb_vector_get_validity(vector: duckdb_vector) -> *mut u64; -} -extern "C" { - #[doc = "Ensures the validity mask is writable by allocating it.\n\nAfter this function is called, `duckdb_vector_get_validity` will ALWAYS return non-NULL.\nThis allows null values to be written to the vector, regardless of whether a validity mask was present before.\n\n vector: The vector to alter"] - pub fn duckdb_vector_ensure_validity_writable(vector: duckdb_vector); -} -extern "C" { - #[doc = "Assigns a string element in the vector at the specified location.\n\n vector: The vector to alter\n index: The row position in the vector to assign the string to\n str: The null-terminated string"] - pub fn duckdb_vector_assign_string_element( - vector: duckdb_vector, - index: idx_t, - str_: *const ::std::os::raw::c_char, - ); -} -extern "C" { - #[doc = "Assigns a string element in the vector at the specified location. You may also use this function to assign BLOBs.\n\n vector: The vector to alter\n index: The row position in the vector to assign the string to\n str: The string\n str_len: The length of the string (in bytes)"] - pub fn duckdb_vector_assign_string_element_len( - vector: duckdb_vector, - index: idx_t, - str_: *const ::std::os::raw::c_char, - str_len: idx_t, - ); -} -extern "C" { - #[doc = "Retrieves the child vector of a list vector.\n\nThe resulting vector is valid as long as the parent vector is valid.\n\n vector: The vector\n returns: The child vector"] - pub fn duckdb_list_vector_get_child(vector: duckdb_vector) -> duckdb_vector; -} -extern "C" { - #[doc = "Returns the size of the child vector of the list.\n\n vector: The vector\n returns: The size of the child list"] - pub fn duckdb_list_vector_get_size(vector: duckdb_vector) -> idx_t; -} -extern "C" { - #[doc = "Sets the total size of the underlying child-vector of a list vector.\n\n vector: The list vector.\n size: The size of the child list.\n returns: The duckdb state. Returns DuckDBError if the vector is nullptr."] - pub fn duckdb_list_vector_set_size(vector: duckdb_vector, size: idx_t) -> duckdb_state; -} -extern "C" { - #[doc = "Sets the total capacity of the underlying child-vector of a list.\n\n vector: The list vector.\n required_capacity: the total capacity to reserve.\n return: The duckdb state. Returns DuckDBError if the vector is nullptr."] - pub fn duckdb_list_vector_reserve(vector: duckdb_vector, required_capacity: idx_t) -> duckdb_state; -} -extern "C" { - #[doc = "Retrieves the child vector of a struct vector.\n\nThe resulting vector is valid as long as the parent vector is valid.\n\n vector: The vector\n index: The child index\n returns: The child vector"] - pub fn duckdb_struct_vector_get_child(vector: duckdb_vector, index: idx_t) -> duckdb_vector; -} -extern "C" { - #[doc = "Retrieves the child vector of a array vector.\n\nThe resulting vector is valid as long as the parent vector is valid.\nThe resulting vector has the size of the parent vector multiplied by the array size.\n\n vector: The vector\n returns: The child vector"] - pub fn duckdb_array_vector_get_child(vector: duckdb_vector) -> duckdb_vector; -} -extern "C" { - #[doc = "Returns whether or not a row is valid (i.e. not NULL) in the given validity mask.\n\n validity: The validity mask, as obtained through `duckdb_vector_get_validity`\n row: The row index\n returns: true if the row is valid, false otherwise"] - pub fn duckdb_validity_row_is_valid(validity: *mut u64, row: idx_t) -> bool; -} -extern "C" { - #[doc = "In a validity mask, sets a specific row to either valid or invalid.\n\nNote that `duckdb_vector_ensure_validity_writable` should be called before calling `duckdb_vector_get_validity`,\nto ensure that there is a validity mask to write to.\n\n validity: The validity mask, as obtained through `duckdb_vector_get_validity`.\n row: The row index\n valid: Whether or not to set the row to valid, or invalid"] - pub fn duckdb_validity_set_row_validity(validity: *mut u64, row: idx_t, valid: bool); -} -extern "C" { - #[doc = "In a validity mask, sets a specific row to invalid.\n\nEquivalent to `duckdb_validity_set_row_validity` with valid set to false.\n\n validity: The validity mask\n row: The row index"] - pub fn duckdb_validity_set_row_invalid(validity: *mut u64, row: idx_t); -} -extern "C" { - #[doc = "In a validity mask, sets a specific row to valid.\n\nEquivalent to `duckdb_validity_set_row_validity` with valid set to true.\n\n validity: The validity mask\n row: The row index"] - pub fn duckdb_validity_set_row_valid(validity: *mut u64, row: idx_t); -} -extern "C" { - #[doc = "Creates a new empty table function.\n\nThe return value should be destroyed with `duckdb_destroy_table_function`.\n\n returns: The table function object."] - pub fn duckdb_create_table_function() -> duckdb_table_function; -} -extern "C" { - #[doc = "Destroys the given table function object.\n\n table_function: The table function to destroy"] - pub fn duckdb_destroy_table_function(table_function: *mut duckdb_table_function); -} -extern "C" { - #[doc = "Sets the name of the given table function.\n\n table_function: The table function\n name: The name of the table function"] - pub fn duckdb_table_function_set_name(table_function: duckdb_table_function, name: *const ::std::os::raw::c_char); -} -extern "C" { - #[doc = "Adds a parameter to the table function.\n\n table_function: The table function\n type: The type of the parameter to add."] - pub fn duckdb_table_function_add_parameter(table_function: duckdb_table_function, type_: duckdb_logical_type); -} -extern "C" { - #[doc = "Adds a named parameter to the table function.\n\n table_function: The table function\n name: The name of the parameter\n type: The type of the parameter to add."] - pub fn duckdb_table_function_add_named_parameter( - table_function: duckdb_table_function, - name: *const ::std::os::raw::c_char, - type_: duckdb_logical_type, - ); -} -extern "C" { - #[doc = "Assigns extra information to the table function that can be fetched during binding, etc.\n\n table_function: The table function\n extra_info: The extra information\n destroy: The callback that will be called to destroy the bind data (if any)"] - pub fn duckdb_table_function_set_extra_info( - table_function: duckdb_table_function, - extra_info: *mut ::std::os::raw::c_void, - destroy: duckdb_delete_callback_t, - ); -} -extern "C" { - #[doc = "Sets the bind function of the table function.\n\n table_function: The table function\n bind: The bind function"] - pub fn duckdb_table_function_set_bind(table_function: duckdb_table_function, bind: duckdb_table_function_bind_t); -} -extern "C" { - #[doc = "Sets the init function of the table function.\n\n table_function: The table function\n init: The init function"] - pub fn duckdb_table_function_set_init(table_function: duckdb_table_function, init: duckdb_table_function_init_t); -} -extern "C" { - #[doc = "Sets the thread-local init function of the table function.\n\n table_function: The table function\n init: The init function"] - pub fn duckdb_table_function_set_local_init( - table_function: duckdb_table_function, - init: duckdb_table_function_init_t, - ); -} -extern "C" { - #[doc = "Sets the main function of the table function.\n\n table_function: The table function\n function: The function"] - pub fn duckdb_table_function_set_function(table_function: duckdb_table_function, function: duckdb_table_function_t); -} -extern "C" { - #[doc = "Sets whether or not the given table function supports projection pushdown.\n\nIf this is set to true, the system will provide a list of all required columns in the `init` stage through\nthe `duckdb_init_get_column_count` and `duckdb_init_get_column_index` functions.\nIf this is set to false (the default), the system will expect all columns to be projected.\n\n table_function: The table function\n pushdown: True if the table function supports projection pushdown, false otherwise."] - pub fn duckdb_table_function_supports_projection_pushdown(table_function: duckdb_table_function, pushdown: bool); -} -extern "C" { - #[doc = "Register the table function object within the given connection.\n\nThe function requires at least a name, a bind function, an init function and a main function.\n\nIf the function is incomplete or a function with this name already exists DuckDBError is returned.\n\n con: The connection to register it in.\n function: The function pointer\n returns: Whether or not the registration was successful."] - pub fn duckdb_register_table_function(con: duckdb_connection, function: duckdb_table_function) -> duckdb_state; -} -extern "C" { - #[doc = "Retrieves the extra info of the function as set in `duckdb_table_function_set_extra_info`.\n\n info: The info object\n returns: The extra info"] - pub fn duckdb_bind_get_extra_info(info: duckdb_bind_info) -> *mut ::std::os::raw::c_void; -} -extern "C" { - #[doc = "Adds a result column to the output of the table function.\n\n info: The info object\n name: The name of the column\n type: The logical type of the column"] - pub fn duckdb_bind_add_result_column( - info: duckdb_bind_info, - name: *const ::std::os::raw::c_char, - type_: duckdb_logical_type, - ); -} -extern "C" { - #[doc = "Retrieves the number of regular (non-named) parameters to the function.\n\n info: The info object\n returns: The number of parameters"] - pub fn duckdb_bind_get_parameter_count(info: duckdb_bind_info) -> idx_t; -} -extern "C" { - #[doc = "Retrieves the parameter at the given index.\n\nThe result must be destroyed with `duckdb_destroy_value`.\n\n info: The info object\n index: The index of the parameter to get\n returns: The value of the parameter. Must be destroyed with `duckdb_destroy_value`."] - pub fn duckdb_bind_get_parameter(info: duckdb_bind_info, index: idx_t) -> duckdb_value; -} -extern "C" { - #[doc = "Retrieves a named parameter with the given name.\n\nThe result must be destroyed with `duckdb_destroy_value`.\n\n info: The info object\n name: The name of the parameter\n returns: The value of the parameter. Must be destroyed with `duckdb_destroy_value`."] - pub fn duckdb_bind_get_named_parameter(info: duckdb_bind_info, name: *const ::std::os::raw::c_char) - -> duckdb_value; -} -extern "C" { - #[doc = "Sets the user-provided bind data in the bind object. This object can be retrieved again during execution.\n\n info: The info object\n extra_data: The bind data object.\n destroy: The callback that will be called to destroy the bind data (if any)"] - pub fn duckdb_bind_set_bind_data( - info: duckdb_bind_info, - bind_data: *mut ::std::os::raw::c_void, - destroy: duckdb_delete_callback_t, - ); -} -extern "C" { - #[doc = "Sets the cardinality estimate for the table function, used for optimization.\n\n info: The bind data object.\n is_exact: Whether or not the cardinality estimate is exact, or an approximation"] - pub fn duckdb_bind_set_cardinality(info: duckdb_bind_info, cardinality: idx_t, is_exact: bool); -} -extern "C" { - #[doc = "Report that an error has occurred while calling bind.\n\n info: The info object\n error: The error message"] - pub fn duckdb_bind_set_error(info: duckdb_bind_info, error: *const ::std::os::raw::c_char); -} -extern "C" { - #[doc = "Retrieves the extra info of the function as set in `duckdb_table_function_set_extra_info`.\n\n info: The info object\n returns: The extra info"] - pub fn duckdb_init_get_extra_info(info: duckdb_init_info) -> *mut ::std::os::raw::c_void; -} -extern "C" { - #[doc = "Gets the bind data set by `duckdb_bind_set_bind_data` during the bind.\n\nNote that the bind data should be considered as read-only.\nFor tracking state, use the init data instead.\n\n info: The info object\n returns: The bind data object"] - pub fn duckdb_init_get_bind_data(info: duckdb_init_info) -> *mut ::std::os::raw::c_void; -} -extern "C" { - #[doc = "Sets the user-provided init data in the init object. This object can be retrieved again during execution.\n\n info: The info object\n extra_data: The init data object.\n destroy: The callback that will be called to destroy the init data (if any)"] - pub fn duckdb_init_set_init_data( - info: duckdb_init_info, - init_data: *mut ::std::os::raw::c_void, - destroy: duckdb_delete_callback_t, - ); -} -extern "C" { - #[doc = "Returns the number of projected columns.\n\nThis function must be used if projection pushdown is enabled to figure out which columns to emit.\n\n info: The info object\n returns: The number of projected columns."] - pub fn duckdb_init_get_column_count(info: duckdb_init_info) -> idx_t; -} -extern "C" { - #[doc = "Returns the column index of the projected column at the specified position.\n\nThis function must be used if projection pushdown is enabled to figure out which columns to emit.\n\n info: The info object\n column_index: The index at which to get the projected column index, from 0..duckdb_init_get_column_count(info)\n returns: The column index of the projected column."] - pub fn duckdb_init_get_column_index(info: duckdb_init_info, column_index: idx_t) -> idx_t; -} -extern "C" { - #[doc = "Sets how many threads can process this table function in parallel (default: 1)\n\n info: The info object\n max_threads: The maximum amount of threads that can process this table function"] - pub fn duckdb_init_set_max_threads(info: duckdb_init_info, max_threads: idx_t); -} -extern "C" { - #[doc = "Report that an error has occurred while calling init.\n\n info: The info object\n error: The error message"] - pub fn duckdb_init_set_error(info: duckdb_init_info, error: *const ::std::os::raw::c_char); -} -extern "C" { - #[doc = "Retrieves the extra info of the function as set in `duckdb_table_function_set_extra_info`.\n\n info: The info object\n returns: The extra info"] - pub fn duckdb_function_get_extra_info(info: duckdb_function_info) -> *mut ::std::os::raw::c_void; -} -extern "C" { - #[doc = "Gets the bind data set by `duckdb_bind_set_bind_data` during the bind.\n\nNote that the bind data should be considered as read-only.\nFor tracking state, use the init data instead.\n\n info: The info object\n returns: The bind data object"] - pub fn duckdb_function_get_bind_data(info: duckdb_function_info) -> *mut ::std::os::raw::c_void; -} -extern "C" { - #[doc = "Gets the init data set by `duckdb_init_set_init_data` during the init.\n\n info: The info object\n returns: The init data object"] - pub fn duckdb_function_get_init_data(info: duckdb_function_info) -> *mut ::std::os::raw::c_void; -} -extern "C" { - #[doc = "Gets the thread-local init data set by `duckdb_init_set_init_data` during the local_init.\n\n info: The info object\n returns: The init data object"] - pub fn duckdb_function_get_local_init_data(info: duckdb_function_info) -> *mut ::std::os::raw::c_void; -} -extern "C" { - #[doc = "Report that an error has occurred while executing the function.\n\n info: The info object\n error: The error message"] - pub fn duckdb_function_set_error(info: duckdb_function_info, error: *const ::std::os::raw::c_char); -} -extern "C" { - #[doc = "Add a replacement scan definition to the specified database.\n\n db: The database object to add the replacement scan to\n replacement: The replacement scan callback\n extra_data: Extra data that is passed back into the specified callback\n delete_callback: The delete callback to call on the extra data, if any"] - pub fn duckdb_add_replacement_scan( - db: duckdb_database, - replacement: duckdb_replacement_callback_t, - extra_data: *mut ::std::os::raw::c_void, - delete_callback: duckdb_delete_callback_t, - ); -} -extern "C" { - #[doc = "Sets the replacement function name. If this function is called in the replacement callback,\nthe replacement scan is performed. If it is not called, the replacement callback is not performed.\n\n info: The info object\n function_name: The function name to substitute."] - pub fn duckdb_replacement_scan_set_function_name( - info: duckdb_replacement_scan_info, - function_name: *const ::std::os::raw::c_char, - ); -} -extern "C" { - #[doc = "Adds a parameter to the replacement scan function.\n\n info: The info object\n parameter: The parameter to add."] - pub fn duckdb_replacement_scan_add_parameter(info: duckdb_replacement_scan_info, parameter: duckdb_value); -} -extern "C" { - #[doc = "Report that an error has occurred while executing the replacement scan.\n\n info: The info object\n error: The error message"] - pub fn duckdb_replacement_scan_set_error(info: duckdb_replacement_scan_info, error: *const ::std::os::raw::c_char); -} -extern "C" { - #[doc = "Creates an appender object.\n\nNote that the object must be destroyed with `duckdb_appender_destroy`.\n\n connection: The connection context to create the appender in.\n schema: The schema of the table to append to, or `nullptr` for the default schema.\n table: The table name to append to.\n out_appender: The resulting appender object.\n returns: `DuckDBSuccess` on success or `DuckDBError` on failure."] - pub fn duckdb_appender_create( - connection: duckdb_connection, - schema: *const ::std::os::raw::c_char, - table: *const ::std::os::raw::c_char, - out_appender: *mut duckdb_appender, - ) -> duckdb_state; -} -extern "C" { - #[doc = "Returns the number of columns in the table that belongs to the appender.\n\n appender The appender to get the column count from.\n returns: The number of columns in the table."] - pub fn duckdb_appender_column_count(appender: duckdb_appender) -> idx_t; -} -extern "C" { - #[doc = "Returns the type of the column at the specified index.\n\nNote: The resulting type should be destroyed with `duckdb_destroy_logical_type`.\n\n appender The appender to get the column type from.\n col_idx The index of the column to get the type of.\n returns: The duckdb_logical_type of the column."] - pub fn duckdb_appender_column_type(appender: duckdb_appender, col_idx: idx_t) -> duckdb_logical_type; -} -extern "C" { - #[doc = "Returns the error message associated with the given appender.\nIf the appender has no error message, this returns `nullptr` instead.\n\nThe error message should not be freed. It will be de-allocated when `duckdb_appender_destroy` is called.\n\n appender: The appender to get the error from.\n returns: The error message, or `nullptr` if there is none."] - pub fn duckdb_appender_error(appender: duckdb_appender) -> *const ::std::os::raw::c_char; -} -extern "C" { - #[doc = "Flush the appender to the table, forcing the cache of the appender to be cleared and the data to be appended to the\nbase table.\n\nThis should generally not be used unless you know what you are doing. Instead, call `duckdb_appender_destroy` when you\nare done with the appender.\n\n appender: The appender to flush.\n returns: `DuckDBSuccess` on success or `DuckDBError` on failure."] - pub fn duckdb_appender_flush(appender: duckdb_appender) -> duckdb_state; -} -extern "C" { - #[doc = "Close the appender, flushing all intermediate state in the appender to the table and closing it for further appends.\n\nThis is generally not necessary. Call `duckdb_appender_destroy` instead.\n\n appender: The appender to flush and close.\n returns: `DuckDBSuccess` on success or `DuckDBError` on failure."] - pub fn duckdb_appender_close(appender: duckdb_appender) -> duckdb_state; -} -extern "C" { - #[doc = "Close the appender and destroy it. Flushing all intermediate state in the appender to the table, and de-allocating\nall memory associated with the appender.\n\n appender: The appender to flush, close and destroy.\n returns: `DuckDBSuccess` on success or `DuckDBError` on failure."] - pub fn duckdb_appender_destroy(appender: *mut duckdb_appender) -> duckdb_state; -} -extern "C" { - #[doc = "A nop function, provided for backwards compatibility reasons. Does nothing. Only `duckdb_appender_end_row` is required."] - pub fn duckdb_appender_begin_row(appender: duckdb_appender) -> duckdb_state; -} -extern "C" { - #[doc = "Finish the current row of appends. After end_row is called, the next row can be appended.\n\n appender: The appender.\n returns: `DuckDBSuccess` on success or `DuckDBError` on failure."] - pub fn duckdb_appender_end_row(appender: duckdb_appender) -> duckdb_state; -} -extern "C" { - #[doc = "Append a bool value to the appender."] - pub fn duckdb_append_bool(appender: duckdb_appender, value: bool) -> duckdb_state; -} -extern "C" { - #[doc = "Append an int8_t value to the appender."] - pub fn duckdb_append_int8(appender: duckdb_appender, value: i8) -> duckdb_state; -} -extern "C" { - #[doc = "Append an int16_t value to the appender."] - pub fn duckdb_append_int16(appender: duckdb_appender, value: i16) -> duckdb_state; -} -extern "C" { - #[doc = "Append an int32_t value to the appender."] - pub fn duckdb_append_int32(appender: duckdb_appender, value: i32) -> duckdb_state; -} -extern "C" { - #[doc = "Append an int64_t value to the appender."] - pub fn duckdb_append_int64(appender: duckdb_appender, value: i64) -> duckdb_state; -} -extern "C" { - #[doc = "Append a duckdb_hugeint value to the appender."] - pub fn duckdb_append_hugeint(appender: duckdb_appender, value: duckdb_hugeint) -> duckdb_state; -} -extern "C" { - #[doc = "Append a uint8_t value to the appender."] - pub fn duckdb_append_uint8(appender: duckdb_appender, value: u8) -> duckdb_state; -} -extern "C" { - #[doc = "Append a uint16_t value to the appender."] - pub fn duckdb_append_uint16(appender: duckdb_appender, value: u16) -> duckdb_state; -} -extern "C" { - #[doc = "Append a uint32_t value to the appender."] - pub fn duckdb_append_uint32(appender: duckdb_appender, value: u32) -> duckdb_state; -} -extern "C" { - #[doc = "Append a uint64_t value to the appender."] - pub fn duckdb_append_uint64(appender: duckdb_appender, value: u64) -> duckdb_state; -} -extern "C" { - #[doc = "Append a duckdb_uhugeint value to the appender."] - pub fn duckdb_append_uhugeint(appender: duckdb_appender, value: duckdb_uhugeint) -> duckdb_state; -} -extern "C" { - #[doc = "Append a float value to the appender."] - pub fn duckdb_append_float(appender: duckdb_appender, value: f32) -> duckdb_state; -} -extern "C" { - #[doc = "Append a double value to the appender."] - pub fn duckdb_append_double(appender: duckdb_appender, value: f64) -> duckdb_state; -} -extern "C" { - #[doc = "Append a duckdb_date value to the appender."] - pub fn duckdb_append_date(appender: duckdb_appender, value: duckdb_date) -> duckdb_state; -} -extern "C" { - #[doc = "Append a duckdb_time value to the appender."] - pub fn duckdb_append_time(appender: duckdb_appender, value: duckdb_time) -> duckdb_state; -} -extern "C" { - #[doc = "Append a duckdb_timestamp value to the appender."] - pub fn duckdb_append_timestamp(appender: duckdb_appender, value: duckdb_timestamp) -> duckdb_state; -} -extern "C" { - #[doc = "Append a duckdb_interval value to the appender."] - pub fn duckdb_append_interval(appender: duckdb_appender, value: duckdb_interval) -> duckdb_state; -} -extern "C" { - #[doc = "Append a varchar value to the appender."] - pub fn duckdb_append_varchar(appender: duckdb_appender, val: *const ::std::os::raw::c_char) -> duckdb_state; -} -extern "C" { - #[doc = "Append a varchar value to the appender."] - pub fn duckdb_append_varchar_length( - appender: duckdb_appender, - val: *const ::std::os::raw::c_char, - length: idx_t, - ) -> duckdb_state; -} -extern "C" { - #[doc = "Append a blob value to the appender."] - pub fn duckdb_append_blob( - appender: duckdb_appender, - data: *const ::std::os::raw::c_void, - length: idx_t, - ) -> duckdb_state; -} -extern "C" { - #[doc = "Append a NULL value to the appender (of any type)."] - pub fn duckdb_append_null(appender: duckdb_appender) -> duckdb_state; -} -extern "C" { - #[doc = "Appends a pre-filled data chunk to the specified appender.\n\nThe types of the data chunk must exactly match the types of the table, no casting is performed.\nIf the types do not match or the appender is in an invalid state, DuckDBError is returned.\nIf the append is successful, DuckDBSuccess is returned.\n\n appender: The appender to append to.\n chunk: The data chunk to append.\n returns: The return state."] - pub fn duckdb_append_data_chunk(appender: duckdb_appender, chunk: duckdb_data_chunk) -> duckdb_state; -} -extern "C" { - #[doc = "Executes a SQL query within a connection and stores the full (materialized) result in an arrow structure.\nIf the query fails to execute, DuckDBError is returned and the error message can be retrieved by calling\n`duckdb_query_arrow_error`.\n\nNote that after running `duckdb_query_arrow`, `duckdb_destroy_arrow` must be called on the result object even if the\nquery fails, otherwise the error stored within the result will not be freed correctly.\n\n connection: The connection to perform the query in.\n query: The SQL query to run.\n out_result: The query result.\n returns: `DuckDBSuccess` on success or `DuckDBError` on failure."] - pub fn duckdb_query_arrow( - connection: duckdb_connection, - query: *const ::std::os::raw::c_char, - out_result: *mut duckdb_arrow, - ) -> duckdb_state; -} -extern "C" { - #[doc = "Fetch the internal arrow schema from the arrow result. Remember to call release on the respective\nArrowSchema object.\n\n result: The result to fetch the schema from.\n out_schema: The output schema.\n returns: `DuckDBSuccess` on success or `DuckDBError` on failure."] - pub fn duckdb_query_arrow_schema(result: duckdb_arrow, out_schema: *mut duckdb_arrow_schema) -> duckdb_state; -} -extern "C" { - #[doc = "Fetch the internal arrow schema from the prepared statement. Remember to call release on the respective\nArrowSchema object.\n\n result: The prepared statement to fetch the schema from.\n out_schema: The output schema.\n returns: `DuckDBSuccess` on success or `DuckDBError` on failure."] - pub fn duckdb_prepared_arrow_schema( - prepared: duckdb_prepared_statement, - out_schema: *mut duckdb_arrow_schema, - ) -> duckdb_state; -} -extern "C" { - #[doc = "Convert a data chunk into an arrow struct array. Remember to call release on the respective\nArrowArray object.\n\n result: The result object the data chunk have been fetched from.\n chunk: The data chunk to convert.\n out_array: The output array."] - pub fn duckdb_result_arrow_array( - result: duckdb_result, - chunk: duckdb_data_chunk, - out_array: *mut duckdb_arrow_array, - ); -} -extern "C" { - #[doc = "Fetch an internal arrow struct array from the arrow result. Remember to call release on the respective\nArrowArray object.\n\nThis function can be called multiple time to get next chunks, which will free the previous out_array.\nSo consume the out_array before calling this function again.\n\n result: The result to fetch the array from.\n out_array: The output array.\n returns: `DuckDBSuccess` on success or `DuckDBError` on failure."] - pub fn duckdb_query_arrow_array(result: duckdb_arrow, out_array: *mut duckdb_arrow_array) -> duckdb_state; -} -extern "C" { - #[doc = "Returns the number of columns present in the arrow result object.\n\n result: The result object.\n returns: The number of columns present in the result object."] - pub fn duckdb_arrow_column_count(result: duckdb_arrow) -> idx_t; -} -extern "C" { - #[doc = "Returns the number of rows present in the arrow result object.\n\n result: The result object.\n returns: The number of rows present in the result object."] - pub fn duckdb_arrow_row_count(result: duckdb_arrow) -> idx_t; -} -extern "C" { - #[doc = "Returns the number of rows changed by the query stored in the arrow result. This is relevant only for\nINSERT/UPDATE/DELETE queries. For other queries the rows_changed will be 0.\n\n result: The result object.\n returns: The number of rows changed."] - pub fn duckdb_arrow_rows_changed(result: duckdb_arrow) -> idx_t; -} -extern "C" { - #[doc = "Returns the error message contained within the result. The error is only set if `duckdb_query_arrow` returns\n`DuckDBError`.\n\nThe error message should not be freed. It will be de-allocated when `duckdb_destroy_arrow` is called.\n\n result: The result object to fetch the error from.\n returns: The error of the result."] - pub fn duckdb_query_arrow_error(result: duckdb_arrow) -> *const ::std::os::raw::c_char; -} -extern "C" { - #[doc = "Closes the result and de-allocates all memory allocated for the arrow result.\n\n result: The result to destroy."] - pub fn duckdb_destroy_arrow(result: *mut duckdb_arrow); -} -extern "C" { - #[doc = "Releases the arrow array stream and de-allocates its memory.\n\n stream: The arrow array stream to destroy."] - pub fn duckdb_destroy_arrow_stream(stream_p: *mut duckdb_arrow_stream); -} -extern "C" { - #[doc = "Executes the prepared statement with the given bound parameters, and returns an arrow query result.\nNote that after running `duckdb_execute_prepared_arrow`, `duckdb_destroy_arrow` must be called on the result object.\n\n prepared_statement: The prepared statement to execute.\n out_result: The query result.\n returns: `DuckDBSuccess` on success or `DuckDBError` on failure."] - pub fn duckdb_execute_prepared_arrow( - prepared_statement: duckdb_prepared_statement, - out_result: *mut duckdb_arrow, - ) -> duckdb_state; -} -extern "C" { - #[doc = "Scans the Arrow stream and creates a view with the given name.\n\n connection: The connection on which to execute the scan.\n table_name: Name of the temporary view to create.\n arrow: Arrow stream wrapper.\n returns: `DuckDBSuccess` on success or `DuckDBError` on failure."] - pub fn duckdb_arrow_scan( - connection: duckdb_connection, - table_name: *const ::std::os::raw::c_char, - arrow: duckdb_arrow_stream, - ) -> duckdb_state; -} -extern "C" { - #[doc = "Scans the Arrow array and creates a view with the given name.\nNote that after running `duckdb_arrow_array_scan`, `duckdb_destroy_arrow_stream` must be called on the out stream.\n\n connection: The connection on which to execute the scan.\n table_name: Name of the temporary view to create.\n arrow_schema: Arrow schema wrapper.\n arrow_array: Arrow array wrapper.\n out_stream: Output array stream that wraps around the passed schema, for releasing/deleting once done.\n returns: `DuckDBSuccess` on success or `DuckDBError` on failure."] - pub fn duckdb_arrow_array_scan( - connection: duckdb_connection, - table_name: *const ::std::os::raw::c_char, - arrow_schema: duckdb_arrow_schema, - arrow_array: duckdb_arrow_array, - out_stream: *mut duckdb_arrow_stream, - ) -> duckdb_state; -} -extern "C" { - #[doc = "Execute DuckDB tasks on this thread.\n\nWill return after `max_tasks` have been executed, or if there are no more tasks present.\n\n database: The database object to execute tasks for\n max_tasks: The maximum amount of tasks to execute"] - pub fn duckdb_execute_tasks(database: duckdb_database, max_tasks: idx_t); -} -extern "C" { - #[doc = "Creates a task state that can be used with duckdb_execute_tasks_state to execute tasks until\n`duckdb_finish_execution` is called on the state.\n\n`duckdb_destroy_state` must be called on the result.\n\n database: The database object to create the task state for\n returns: The task state that can be used with duckdb_execute_tasks_state."] - pub fn duckdb_create_task_state(database: duckdb_database) -> duckdb_task_state; -} -extern "C" { - #[doc = "Execute DuckDB tasks on this thread.\n\nThe thread will keep on executing tasks forever, until duckdb_finish_execution is called on the state.\nMultiple threads can share the same duckdb_task_state.\n\n state: The task state of the executor"] - pub fn duckdb_execute_tasks_state(state: duckdb_task_state); -} -extern "C" { - #[doc = "Execute DuckDB tasks on this thread.\n\nThe thread will keep on executing tasks until either duckdb_finish_execution is called on the state,\nmax_tasks tasks have been executed or there are no more tasks to be executed.\n\nMultiple threads can share the same duckdb_task_state.\n\n state: The task state of the executor\n max_tasks: The maximum amount of tasks to execute\n returns: The amount of tasks that have actually been executed"] - pub fn duckdb_execute_n_tasks_state(state: duckdb_task_state, max_tasks: idx_t) -> idx_t; -} -extern "C" { - #[doc = "Finish execution on a specific task.\n\n state: The task state to finish execution"] - pub fn duckdb_finish_execution(state: duckdb_task_state); -} -extern "C" { - #[doc = "Check if the provided duckdb_task_state has finished execution\n\n state: The task state to inspect\n returns: Whether or not duckdb_finish_execution has been called on the task state"] - pub fn duckdb_task_state_is_finished(state: duckdb_task_state) -> bool; -} -extern "C" { - #[doc = "Destroys the task state returned from duckdb_create_task_state.\n\nNote that this should not be called while there is an active duckdb_execute_tasks_state running\non the task state.\n\n state: The task state to clean up"] - pub fn duckdb_destroy_task_state(state: duckdb_task_state); -} -extern "C" { - #[doc = "Returns true if the execution of the current query is finished.\n\n con: The connection on which to check"] - pub fn duckdb_execution_is_finished(con: duckdb_connection) -> bool; -} -extern "C" { - #[doc = "Fetches a data chunk from the (streaming) duckdb_result. This function should be called repeatedly until the result is\nexhausted.\n\nThe result must be destroyed with `duckdb_destroy_data_chunk`.\n\nThis function can only be used on duckdb_results created with 'duckdb_pending_prepared_streaming'\n\nIf this function is used, none of the other result functions can be used and vice versa (i.e. this function cannot be\nmixed with the legacy result functions or the materialized result functions).\n\nIt is not known beforehand how many chunks will be returned by this result.\n\n result: The result object to fetch the data chunk from.\n returns: The resulting data chunk. Returns `NULL` if the result has an error."] - pub fn duckdb_stream_fetch_chunk(result: duckdb_result) -> duckdb_data_chunk; -} diff --git a/upgrade.sh b/upgrade.sh index d4046929..3e32105d 100755 --- a/upgrade.sh +++ b/upgrade.sh @@ -22,5 +22,5 @@ fi echo "Start to upgrade from $duckdb_rs_version to $duckdb_version" -sed -i '' "s/$duckdb_rs_version/$duckdb_version/g" Cargo.toml libduckdb-sys/upgrade.sh libduckdb-sys/Cargo.toml .github/workflows/rust.yaml -./libduckdb-sys/upgrade.sh +sed -i '' "s/$duckdb_rs_version/$duckdb_version/g" Cargo.toml crates/libduckdb-sys/upgrade.sh crates/libduckdb-sys/Cargo.toml .github/workflows/rust.yaml +./crates/libduckdb-sys/upgrade.sh