Change default minimal SQLite API version

From 3.6.8 to 3.14.0.
Use `old_sqlite` feature to keep 3.6.8 (or 3.7.16) as the minimal version.
Use `modern_sqlite` for SQLite API > 3.14.0.
Also remove old 3.6.23 and 3.7.7 bindings.
This commit is contained in:
gwenn 2022-08-21 11:20:04 +02:00 committed by Thom Chiovoloni
parent 5ea4c3b7d6
commit 6e740d0611
16 changed files with 71 additions and 4107 deletions

View File

@ -170,6 +170,8 @@ jobs:
- run: cargo clippy --all-targets --workspace --features bundled -- -D warnings
# Clippy with all non-conflicting features
- run: cargo clippy --all-targets --workspace --features 'bundled-full session buildtime_bindgen' -- -D warnings
# Clippy with SQLite 3.6.8
- run: cargo clippy --all-targets --workspace --no-default-features --features 'old_sqlite' -- -D warnings
# Ensure patch is formatted.
fmt:

View File

@ -35,14 +35,14 @@ members = ["libsqlite3-sys"]
[features]
load_extension = []
# hot-backup interface: 3.6.11 (2009-02-18)
backup = ["libsqlite3-sys/min_sqlite_version_3_6_23"]
backup = ["libsqlite3-sys/min_sqlite_version_3_7_16"]
# sqlite3_blob_reopen: 3.7.4
blob = ["libsqlite3-sys/min_sqlite_version_3_7_7"]
blob = ["libsqlite3-sys/min_sqlite_version_3_7_16"]
collation = []
# sqlite3_create_function_v2: 3.7.3 (2010-10-08)
functions = ["libsqlite3-sys/min_sqlite_version_3_7_7"]
functions = ["libsqlite3-sys/min_sqlite_version_3_7_16"]
# sqlite3_log: 3.6.23 (2010-03-09)
trace = ["libsqlite3-sys/min_sqlite_version_3_6_23"]
trace = ["libsqlite3-sys/min_sqlite_version_3_7_16"]
# sqlite3_db_release_memory: 3.7.10 (2012-01-16)
release_memory = ["libsqlite3-sys/min_sqlite_version_3_7_16"]
bundled = ["libsqlite3-sys/bundled", "modern_sqlite"]
@ -55,7 +55,7 @@ i128_blob = []
sqlcipher = ["libsqlite3-sys/sqlcipher"]
unlock_notify = ["libsqlite3-sys/unlock_notify"]
# xSavepoint, xRelease and xRollbackTo: 3.7.7 (2011-06-23)
vtab = ["libsqlite3-sys/min_sqlite_version_3_7_7"]
vtab = ["libsqlite3-sys/min_sqlite_version_3_7_16"]
csvtab = ["csv", "vtab"]
# pointer passing interfaces: 3.20.0
array = ["vtab"]
@ -67,7 +67,10 @@ window = ["functions"]
series = ["vtab"]
# check for invalid query.
extra_check = []
# ]3.14.0, last]
modern_sqlite = ["libsqlite3-sys/bundled_bindings"]
# [3.6.8, 3.14.0[
old_sqlite = ["libsqlite3-sys/min_sqlite_version_3_6_8"]
in_gecko = ["modern_sqlite", "libsqlite3-sys/in_gecko"]
bundled-windows = ["libsqlite3-sys/bundled-windows"]
# Build bundled sqlite with -fsanitize=address

View File

@ -191,9 +191,9 @@ minimum SQLite version that supports your chosen features. If you are using
`libsqlite3-sys` directly, you can use the same features to choose which
pregenerated bindings are chosen:
* `min_sqlite_version_3_6_8` - SQLite 3.6.8 bindings (this is the default)
* `min_sqlite_version_3_6_23` - SQLite 3.6.23 bindings
* `min_sqlite_version_3_7_7` - SQLite 3.7.7 bindings
* `min_sqlite_version_3_6_8` - SQLite 3.6.8 bindings
* `min_sqlite_version_3_7_16` - SQLite 3.7.16 bindings
* `min_sqlite_version_3_14_0` - SQLite 3.14.0 bindings (this is the default)
If you use any of the `bundled` features, you will get pregenerated bindings for the
bundled version of SQLite/SQLCipher. If you need other specific pregenerated binding

View File

@ -12,7 +12,7 @@ keywords = ["sqlite", "sqlcipher", "ffi"]
categories = ["external-ffi-bindings"]
[features]
default = ["min_sqlite_version_3_6_8"]
default = ["min_sqlite_version_3_14_0"]
bundled = ["cc", "bundled_bindings"]
bundled-windows = ["cc", "bundled_bindings"]
bundled-sqlcipher = ["bundled"]
@ -20,9 +20,8 @@ bundled-sqlcipher-vendored-openssl = ["bundled-sqlcipher", "openssl-sys/vendored
buildtime_bindgen = ["bindgen", "pkg-config", "vcpkg"]
sqlcipher = []
min_sqlite_version_3_6_8 = ["pkg-config", "vcpkg"]
min_sqlite_version_3_6_23 = ["pkg-config", "vcpkg"]
min_sqlite_version_3_7_7 = ["pkg-config", "vcpkg"]
min_sqlite_version_3_7_16 = ["pkg-config", "vcpkg"]
min_sqlite_version_3_14_0 = ["pkg-config", "vcpkg"]
# Bundle only the bindings file. Note that this does nothing if
# `buildtime_bindgen` is enabled.
bundled_bindings = []

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -474,13 +474,18 @@ mod bindings {
use std::path::Path;
static PREBUILT_BINDGEN_PATHS: &[&str] = &[
#[cfg(feature = "min_sqlite_version_3_6_8")]
"bindgen-bindings/bindgen_3.6.8.rs",
#[cfg(feature = "min_sqlite_version_3_6_23")]
"bindgen-bindings/bindgen_3.6.23.rs",
#[cfg(feature = "min_sqlite_version_3_7_7")]
"bindgen-bindings/bindgen_3.7.7.rs",
#[cfg(feature = "min_sqlite_version_3_7_16")]
"bindgen-bindings/bindgen_3.7.16.rs",
#[cfg(any(
feature = "min_sqlite_version_3_14_0",
not(any(
feature = "min_sqlite_version_3_7_16",
feature = "min_sqlite_version_3_6_8"
))
))]
"bindgen-bindings/bindgen_3.14.0.rs",
];
pub fn write_to_out_dir(_header: HeaderLocation, out_path: &Path) {

View File

@ -75,11 +75,11 @@ unsafe fn report_error(ctx: *mut sqlite3_context, err: &Error) {
// an explicit feature check for that, and this doesn't really warrant one.
// We'll use the extended code if we're on the bundled version (since it's
// at least 3.17.0) and the normal constraint error code if not.
#[cfg(feature = "modern_sqlite")]
#[cfg(not(feature = "old_sqlite"))]
fn constraint_error_code() -> i32 {
ffi::SQLITE_CONSTRAINT_FUNCTION
}
#[cfg(not(feature = "modern_sqlite"))]
#[cfg(feature = "old_sqlite")]
fn constraint_error_code() -> i32 {
ffi::SQLITE_CONSTRAINT
}
@ -168,8 +168,8 @@ impl Context<'_> {
///
/// Will panic if `idx` is greater than or equal to
/// [`self.len()`](Context::len).
#[cfg(feature = "modern_sqlite")] // 3.9.0
#[cfg_attr(docsrs, doc(cfg(feature = "modern_sqlite")))]
#[cfg(not(feature = "old_sqlite"))] // 3.9.0
#[cfg_attr(docsrs, doc(cfg(not(feature = "old_sqlite"))))]
pub fn get_subtype(&self, idx: usize) -> std::os::raw::c_uint {
let arg = self.args[idx];
unsafe { ffi::sqlite3_value_subtype(arg) }
@ -249,8 +249,8 @@ impl Context<'_> {
}
/// Set the Subtype of an SQL function
#[cfg(feature = "modern_sqlite")] // 3.9.0
#[cfg_attr(docsrs, doc(cfg(feature = "modern_sqlite")))]
#[cfg(not(feature = "old_sqlite"))] // 3.9.0
#[cfg_attr(docsrs, doc(cfg(not(feature = "old_sqlite"))))]
pub fn set_result_subtype(&self, sub_type: std::os::raw::c_uint) {
unsafe { ffi::sqlite3_result_subtype(self.ctx, sub_type) };
}

View File

@ -181,7 +181,7 @@ pub enum AuthAction<'c> {
operation: TransactionOperation,
savepoint_name: &'c str,
},
#[cfg(feature = "modern_sqlite")]
#[cfg(not(feature = "old_sqlite"))]
Recursive,
}
@ -285,7 +285,7 @@ impl<'c> AuthAction<'c> {
operation: TransactionOperation::from_str(operation_str),
savepoint_name,
},
#[cfg(feature = "modern_sqlite")] // 3.8.3
#[cfg(not(feature = "old_sqlite"))] // 3.8.3
(ffi::SQLITE_RECURSIVE, ..) => Self::Recursive,
(code, arg1, arg2) => Self::Unknown { code, arg1, arg2 },
}

View File

@ -295,7 +295,7 @@ impl InnerConnection {
unsafe { ffi::sqlite3_get_autocommit(self.db()) != 0 }
}
#[cfg(feature = "modern_sqlite")] // 3.8.6
#[cfg(not(feature = "old_sqlite"))] // 3.8.6
pub fn is_busy(&self) -> bool {
let db = self.db();
unsafe {
@ -310,7 +310,7 @@ impl InnerConnection {
false
}
#[cfg(feature = "modern_sqlite")] // 3.10.0
#[cfg(not(feature = "old_sqlite"))] // 3.10.0
pub fn cache_flush(&mut self) -> Result<()> {
crate::error::check(unsafe { ffi::sqlite3_db_cacheflush(self.db()) })
}
@ -319,7 +319,7 @@ impl InnerConnection {
#[inline]
fn remove_hooks(&mut self) {}
#[cfg(feature = "modern_sqlite")] // 3.7.11
#[cfg(not(feature = "old_sqlite"))] // 3.7.11
pub fn db_readonly(&self, db_name: super::DatabaseName<'_>) -> Result<bool> {
let name = db_name.as_cstring()?;
let r = unsafe { ffi::sqlite3_db_readonly(self.db, name.as_ptr()) };

View File

@ -318,7 +318,7 @@ pub const TEMP_DB: DatabaseName<'static> = DatabaseName::Temp;
feature = "backup",
feature = "blob",
feature = "session",
feature = "modern_sqlite"
not(feature = "old_sqlite")
))]
impl DatabaseName<'_> {
#[inline]
@ -961,22 +961,22 @@ impl Connection {
/// Determine if all associated prepared statements have been reset.
#[inline]
#[cfg(feature = "modern_sqlite")] // 3.8.6
#[cfg_attr(docsrs, doc(cfg(feature = "modern_sqlite")))]
#[cfg(not(feature = "old_sqlite"))] // 3.8.6
#[cfg_attr(docsrs, doc(cfg(not(feature = "old_sqlite"))))]
pub fn is_busy(&self) -> bool {
self.db.borrow().is_busy()
}
/// Flush caches to disk mid-transaction
#[cfg(feature = "modern_sqlite")] // 3.10.0
#[cfg_attr(docsrs, doc(cfg(feature = "modern_sqlite")))]
#[cfg(not(feature = "old_sqlite"))] // 3.10.0
#[cfg_attr(docsrs, doc(cfg(not(feature = "old_sqlite"))))]
pub fn cache_flush(&self) -> Result<()> {
self.db.borrow_mut().cache_flush()
}
/// Determine if a database is read-only
#[cfg(feature = "modern_sqlite")] // 3.7.11
#[cfg_attr(docsrs, doc(cfg(feature = "modern_sqlite")))]
#[cfg(not(feature = "old_sqlite"))] // 3.7.11
#[cfg_attr(docsrs, doc(cfg(not(feature = "old_sqlite"))))]
pub fn is_readonly(&self, db_name: DatabaseName<'_>) -> Result<bool> {
self.db.borrow().db_readonly(db_name)
}
@ -1176,7 +1176,7 @@ impl InterruptHandle {
}
}
#[cfg(feature = "modern_sqlite")] // 3.7.10
#[cfg(not(feature = "old_sqlite"))] // 3.7.10
unsafe fn db_filename(db: *mut ffi::sqlite3) -> Option<PathBuf> {
let db_name = DatabaseName::Main.as_cstring().unwrap();
let db_filename = ffi::sqlite3_db_filename(db, db_name.as_ptr());
@ -1186,7 +1186,7 @@ unsafe fn db_filename(db: *mut ffi::sqlite3) -> Option<PathBuf> {
CStr::from_ptr(db_filename).to_str().ok().map(PathBuf::from)
}
}
#[cfg(not(feature = "modern_sqlite"))]
#[cfg(feature = "old_sqlite")]
unsafe fn db_filename(_: *mut ffi::sqlite3) -> Option<PathBuf> {
None
}
@ -1664,7 +1664,7 @@ mod test {
}
#[test]
#[cfg(feature = "modern_sqlite")]
#[cfg(not(feature = "old_sqlite"))]
fn test_is_busy() -> Result<()> {
let db = Connection::open_in_memory()?;
assert!(!db.is_busy());
@ -1695,11 +1695,11 @@ mod test {
fn test_notnull_constraint_error() -> Result<()> {
// extended error codes for constraints were added in SQLite 3.7.16; if we're
// running on our bundled version, we know the extended error code exists.
#[cfg(feature = "modern_sqlite")]
#[cfg(not(feature = "old_sqlite"))]
fn check_extended_code(extended_code: c_int) {
assert_eq!(extended_code, ffi::SQLITE_CONSTRAINT_NOTNULL);
}
#[cfg(not(feature = "modern_sqlite"))]
#[cfg(feature = "old_sqlite")]
fn check_extended_code(_extended_code: c_int) {}
let db = Connection::open_in_memory()?;
@ -2109,14 +2109,14 @@ mod test {
}
#[test]
#[cfg(feature = "modern_sqlite")]
#[cfg(not(feature = "old_sqlite"))]
fn test_cache_flush() -> Result<()> {
let db = Connection::open_in_memory()?;
db.cache_flush()
}
#[test]
#[cfg(feature = "modern_sqlite")]
#[cfg(not(feature = "old_sqlite"))]
pub fn db_readonly() -> Result<()> {
let db = Connection::open_in_memory()?;
assert!(!db.is_readonly(MAIN_DB)?);

View File

@ -1,7 +1,7 @@
use super::ffi;
use super::StatementStatus;
use crate::util::ParamIndexCache;
#[cfg(feature = "modern_sqlite")]
#[cfg(not(feature = "old_sqlite"))]
use crate::util::SqliteMallocString;
use std::ffi::CStr;
use std::os::raw::c_int;
@ -197,13 +197,13 @@ impl RawStatement {
// does not work for PRAGMA
#[inline]
#[cfg(all(feature = "extra_check", feature = "modern_sqlite"))] // 3.7.4
#[cfg(all(feature = "extra_check", not(feature = "old_sqlite")))] // 3.7.4
pub fn readonly(&self) -> bool {
unsafe { ffi::sqlite3_stmt_readonly(self.ptr) != 0 }
}
#[inline]
#[cfg(feature = "modern_sqlite")] // 3.14.0
#[cfg(not(feature = "old_sqlite"))] // 3.14.0
pub(crate) fn expanded_sql(&self) -> Option<SqliteMallocString> {
unsafe { SqliteMallocString::from_raw(ffi::sqlite3_expanded_sql(self.ptr)) }
}

View File

@ -796,7 +796,7 @@ impl Statement<'_> {
self.conn.decode_result(stmt.finalize())
}
#[cfg(all(feature = "modern_sqlite", feature = "extra_check"))]
#[cfg(all(not(feature = "old_sqlite"), feature = "extra_check"))]
#[inline]
fn check_update(&self) -> Result<()> {
// sqlite3_column_count works for DML but not for DDL (ie ALTER)
@ -806,7 +806,7 @@ impl Statement<'_> {
Ok(())
}
#[cfg(all(not(feature = "modern_sqlite"), feature = "extra_check"))]
#[cfg(all(feature = "old_sqlite", feature = "extra_check"))]
#[inline]
fn check_update(&self) -> Result<()> {
// sqlite3_column_count works for DML but not for DDL (ie ALTER)
@ -825,8 +825,8 @@ impl Statement<'_> {
/// Returns a string containing the SQL text of prepared statement with
/// bound parameters expanded.
#[cfg(feature = "modern_sqlite")]
#[cfg_attr(docsrs, doc(cfg(feature = "modern_sqlite")))]
#[cfg(not(feature = "old_sqlite"))]
#[cfg_attr(docsrs, doc(cfg(not(feature = "old_sqlite"))))]
pub fn expanded_sql(&self) -> Option<String> {
self.stmt
.expanded_sql()
@ -1407,7 +1407,7 @@ mod test {
}
#[test]
#[cfg(feature = "modern_sqlite")]
#[cfg(not(feature = "old_sqlite"))]
fn test_expanded_sql() -> Result<()> {
let db = Connection::open_in_memory()?;
let stmt = db.prepare("SELECT ?")?;
@ -1537,7 +1537,7 @@ mod test {
}
#[test]
#[cfg(all(feature = "modern_sqlite", not(feature = "bundled-sqlcipher")))] // SQLite >= 3.38.0
#[cfg(feature = "modern_sqlite")] // SQLite >= 3.38.0
fn test_error_offset() -> Result<()> {
use crate::ffi::ErrorCode;
let db = Connection::open_in_memory()?;

View File

@ -5,7 +5,7 @@ pub(crate) use param_cache::ParamIndexCache;
pub(crate) use small_cstr::SmallCString;
// Doesn't use any modern features or vtab stuff, but is only used by them.
#[cfg(any(feature = "modern_sqlite", feature = "vtab"))]
#[cfg(any(not(feature = "old_sqlite"), feature = "vtab"))]
mod sqlite_string;
#[cfg(any(feature = "modern_sqlite", feature = "vtab"))]
#[cfg(any(not(feature = "old_sqlite"), feature = "vtab"))]
pub(crate) use sqlite_string::SqliteMallocString;

View File

@ -2,7 +2,7 @@
// used in each feature. Avoid having to track this for each function. We will
// still warn for anything that's not used by either, though.
#![cfg_attr(
not(all(feature = "vtab", feature = "modern-sqlite")),
not(all(feature = "vtab", not(feature = "old_sqlite"))),
allow(dead_code)
)]
use crate::ffi;

View File

@ -187,7 +187,7 @@ pub fn eponymous_only_module<'vtab, T: VTab<'vtab>>() -> &'static Module<'vtab,
/// Virtual table configuration options
#[repr(i32)]
#[non_exhaustive]
#[cfg(feature = "modern_sqlite")] // 3.7.7
#[cfg(not(feature = "old_sqlite"))] // 3.7.7
#[derive(Debug, Clone, Copy, Eq, PartialEq)]
pub enum VTabConfig {
/// Equivalent to SQLITE_VTAB_CONSTRAINT_SUPPORT
@ -203,8 +203,8 @@ pub struct VTabConnection(*mut ffi::sqlite3);
impl VTabConnection {
/// Configure various facets of the virtual table interface
#[cfg(feature = "modern_sqlite")] // 3.7.7
#[cfg_attr(docsrs, doc(cfg(feature = "modern_sqlite")))]
#[cfg(not(feature = "old_sqlite"))] // 3.7.7
#[cfg_attr(docsrs, doc(cfg(not(feature = "old_sqlite"))))]
pub fn config(&mut self, config: VTabConfig) -> Result<()> {
crate::error::check(unsafe { ffi::sqlite3_vtab_config(self.0, config as c_int) })
}
@ -369,7 +369,7 @@ impl From<u8> for IndexConstraintOp {
}
}
#[cfg(feature = "modern_sqlite")] // 3.9.0
#[cfg(not(feature = "old_sqlite"))] // 3.9.0
bitflags::bitflags! {
/// Virtual table scan flags
/// See [Function Flags](https://sqlite.org/c3ref/c_index_scan_unique.html) for details.
@ -474,8 +474,8 @@ impl IndexInfo {
}
/// Estimated number of rows returned.
#[cfg(feature = "modern_sqlite")] // SQLite >= 3.8.2
#[cfg_attr(docsrs, doc(cfg(feature = "modern_sqlite")))]
#[cfg(not(feature = "old_sqlite"))] // SQLite >= 3.8.2
#[cfg_attr(docsrs, doc(cfg(not(feature = "old_sqlite"))))]
#[inline]
pub fn set_estimated_rows(&mut self, estimated_rows: i64) {
unsafe {
@ -484,16 +484,16 @@ impl IndexInfo {
}
/// Mask of SQLITE_INDEX_SCAN_* flags.
#[cfg(feature = "modern_sqlite")] // SQLite >= 3.9.0
#[cfg_attr(docsrs, doc(cfg(feature = "modern_sqlite")))]
#[cfg(not(feature = "old_sqlite"))] // SQLite >= 3.9.0
#[cfg_attr(docsrs, doc(cfg(not(feature = "old_sqlite"))))]
#[inline]
pub fn set_idx_flags(&mut self, flags: IndexFlags) {
unsafe { (*self.0).idxFlags = flags.bits() };
}
/// Mask of columns used by statement
#[cfg(feature = "modern_sqlite")] // SQLite >= 3.10.0
#[cfg_attr(docsrs, doc(cfg(feature = "modern_sqlite")))]
#[cfg(not(feature = "old_sqlite"))] // SQLite >= 3.10.0
#[cfg_attr(docsrs, doc(cfg(not(feature = "old_sqlite"))))]
#[inline]
pub fn col_used(&self) -> u64 {
unsafe { (*self.0).colUsed }