From d16748ac9f7ae5d64d25ba7069d1c0d44ac1dae6 Mon Sep 17 00:00:00 2001 From: "Evgeniy A. Dushistov" Date: Mon, 1 Jun 2020 00:02:18 +0300 Subject: [PATCH] adding ability to work with sqlite compiled with -DSQLITE_OMIT_DECLTYPE fix #751 --- Cargo.toml | 4 +++- src/column.rs | 7 ++++++- src/raw_statement.rs | 1 + 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index eef2a27..bcc5687 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -59,6 +59,7 @@ in_gecko = ["modern_sqlite", "libsqlite3-sys/in_gecko"] bundled-windows = ["libsqlite3-sys/bundled-windows"] # Build bundled sqlite with -fsanitize=address with-asan = ["libsqlite3-sys/with-asan"] +column_decltype = [] # Helper feature for enabling both `bundled` and most non-build-related optional # features or dependencies. This is useful for running tests / clippy / etc. New @@ -71,6 +72,7 @@ bundled-full = [ "bundled", "chrono", "collation", + "column_decltype", "csvtab", "extra_check", "functions", @@ -134,7 +136,7 @@ name = "cache" harness = false [package.metadata.docs.rs] -features = [ "backup", "blob", "chrono", "collation", "functions", "limits", "load_extension", "serde_json", "trace", "url", "vtab", "window", "modern_sqlite" ] +features = [ "backup", "blob", "chrono", "collation", "functions", "limits", "load_extension", "serde_json", "trace", "url", "vtab", "window", "modern_sqlite", "column_decltype" ] all-features = false no-default-features = true default-target = "x86_64-unknown-linux-gnu" diff --git a/src/column.rs b/src/column.rs index cb6578b..4f6daac 100644 --- a/src/column.rs +++ b/src/column.rs @@ -86,6 +86,7 @@ impl Statement<'_> { } /// Returns a slice describing the columns of the result of the query. + #[cfg(feature = "column_decltype")] pub fn columns(&self) -> Vec { let n = self.column_count(); let mut cols = Vec::with_capacity(n as usize); @@ -123,6 +124,7 @@ impl<'stmt> Rows<'stmt> { } /// Returns a slice describing the columns of the Rows. + #[cfg(feature = "column_decltype")] pub fn columns(&self) -> Option> { self.stmt.map(Statement::columns) } @@ -150,6 +152,7 @@ impl<'stmt> Row<'stmt> { } /// Returns a slice describing the columns of the Row. + #[cfg(feature = "column_decltype")] pub fn columns(&self) -> Vec { self.stmt.columns() } @@ -157,11 +160,13 @@ impl<'stmt> Row<'stmt> { #[cfg(test)] mod test { - use super::Column; use crate::Connection; #[test] + #[cfg(feature = "column_decltype")] fn test_columns() { + use super::Column; + let db = Connection::open_in_memory().unwrap(); let query = db.prepare("SELECT * FROM sqlite_master").unwrap(); let columns = query.columns(); diff --git a/src/raw_statement.rs b/src/raw_statement.rs index 893ac8b..ce8c982 100644 --- a/src/raw_statement.rs +++ b/src/raw_statement.rs @@ -63,6 +63,7 @@ impl RawStatement { unsafe { ffi::sqlite3_column_type(self.ptr, idx as c_int) } } + #[cfg(feature = "column_decltype")] pub fn column_decltype(&self, idx: usize) -> Option<&CStr> { unsafe { let decltype = ffi::sqlite3_column_decltype(self.ptr, idx as c_int);