mirror of
https://github.com/isar/rusqlite.git
synced 2025-08-20 12:59:28 +08:00
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:
@@ -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) };
|
||||
}
|
||||
|
@@ -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 },
|
||||
}
|
||||
|
@@ -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()) };
|
||||
|
28
src/lib.rs
28
src/lib.rs
@@ -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)?);
|
||||
|
@@ -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)) }
|
||||
}
|
||||
|
@@ -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()?;
|
||||
|
@@ -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;
|
||||
|
@@ -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;
|
||||
|
@@ -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 }
|
||||
|
Reference in New Issue
Block a user