mirror of
https://github.com/isar/rusqlite.git
synced 2024-11-26 19:41:37 +08:00
commit
bb3db3f877
@ -8,7 +8,7 @@ use std::mem;
|
||||
mod error;
|
||||
|
||||
pub fn SQLITE_STATIC() -> sqlite3_destructor_type {
|
||||
Some(unsafe { mem::transmute(0isize) })
|
||||
None
|
||||
}
|
||||
|
||||
pub fn SQLITE_TRANSIENT() -> sqlite3_destructor_type {
|
||||
|
18
src/error.rs
18
src/error.rs
@ -142,7 +142,7 @@ impl PartialEq for Error {
|
||||
(Error::UnwindingPanic, Error::UnwindingPanic) => true,
|
||||
#[cfg(feature = "functions")]
|
||||
(Error::GetAuxWrongType, Error::GetAuxWrongType) => true,
|
||||
(_, _) => false,
|
||||
(..) => false,
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -261,7 +261,7 @@ impl error::Error for Error {
|
||||
"SQLite was compiled or configured for single-threaded use only"
|
||||
}
|
||||
Error::FromSqlConversionFailure(_, _, ref err) => err.description(),
|
||||
Error::IntegralValueOutOfRange(_, _) => "integral value out of range of requested type",
|
||||
Error::IntegralValueOutOfRange(..) => "integral value out of range of requested type",
|
||||
Error::Utf8Error(ref err) => err.description(),
|
||||
Error::InvalidParameterName(_) => "invalid parameter name",
|
||||
Error::NulError(ref err) => err.description(),
|
||||
@ -272,13 +272,13 @@ impl error::Error for Error {
|
||||
Error::QueryReturnedNoRows => "query returned no rows",
|
||||
Error::InvalidColumnIndex(_) => "invalid column index",
|
||||
Error::InvalidColumnName(_) => "invalid column name",
|
||||
Error::InvalidColumnType(_, _, _) => "invalid column type",
|
||||
Error::InvalidColumnType(..) => "invalid column type",
|
||||
Error::StatementChangedRows(_) => "query inserted zero or more than one row",
|
||||
|
||||
#[cfg(feature = "functions")]
|
||||
Error::InvalidFunctionParameterType(_, _) => "invalid function parameter type",
|
||||
Error::InvalidFunctionParameterType(..) => "invalid function parameter type",
|
||||
#[cfg(feature = "vtab")]
|
||||
Error::InvalidFilterParameterType(_, _) => "invalid filter parameter type",
|
||||
Error::InvalidFilterParameterType(..) => "invalid filter parameter type",
|
||||
#[cfg(feature = "functions")]
|
||||
Error::UserFunctionError(ref err) => err.description(),
|
||||
Error::ToSqlConversionFailure(ref err) => err.description(),
|
||||
@ -299,23 +299,23 @@ impl error::Error for Error {
|
||||
Error::Utf8Error(ref err) => Some(err),
|
||||
Error::NulError(ref err) => Some(err),
|
||||
|
||||
Error::IntegralValueOutOfRange(_, _)
|
||||
Error::IntegralValueOutOfRange(..)
|
||||
| Error::SqliteSingleThreadedMode
|
||||
| Error::InvalidParameterName(_)
|
||||
| Error::ExecuteReturnedResults
|
||||
| Error::QueryReturnedNoRows
|
||||
| Error::InvalidColumnIndex(_)
|
||||
| Error::InvalidColumnName(_)
|
||||
| Error::InvalidColumnType(_, _, _)
|
||||
| Error::InvalidColumnType(..)
|
||||
| Error::InvalidPath(_)
|
||||
| Error::StatementChangedRows(_)
|
||||
| Error::InvalidQuery
|
||||
| Error::MultipleStatement => None,
|
||||
|
||||
#[cfg(feature = "functions")]
|
||||
Error::InvalidFunctionParameterType(_, _) => None,
|
||||
Error::InvalidFunctionParameterType(..) => None,
|
||||
#[cfg(feature = "vtab")]
|
||||
Error::InvalidFilterParameterType(_, _) => None,
|
||||
Error::InvalidFilterParameterType(..) => None,
|
||||
|
||||
#[cfg(feature = "functions")]
|
||||
Error::UserFunctionError(ref err) => Some(&**err),
|
||||
|
@ -92,7 +92,7 @@ impl InnerConnection {
|
||||
if let Error::SqliteFailure(
|
||||
ffi::Error {
|
||||
code: ffi::ErrorCode::CannotOpen,
|
||||
extended_code: _,
|
||||
..
|
||||
},
|
||||
Some(msg),
|
||||
) = e
|
||||
|
32
src/lib.rs
32
src/lib.rs
@ -701,7 +701,11 @@ impl Connection {
|
||||
///
|
||||
/// You should not need to use this function. If you do need to, please
|
||||
/// [open an issue on the rusqlite repository](https://github.com/jgallagher/rusqlite/issues) and describe
|
||||
/// your use case. This function is unsafe because it gives you raw access
|
||||
/// your use case.
|
||||
///
|
||||
/// # Safety
|
||||
///
|
||||
/// This function is unsafe because it gives you raw access
|
||||
/// to the SQLite connection, and what you do with it could impact the
|
||||
/// safety of this `Connection`.
|
||||
pub unsafe fn handle(&self) -> *mut ffi::sqlite3 {
|
||||
@ -797,8 +801,11 @@ impl Default for OpenFlags {
|
||||
/// If you are encountering that panic _and_ can ensure that SQLite has been
|
||||
/// initialized in either multi-thread or serialized mode, call this function
|
||||
/// prior to attempting to open a connection and rusqlite's initialization
|
||||
/// process will by skipped. This
|
||||
/// function is unsafe because if you call it and SQLite has actually been
|
||||
/// process will by skipped.
|
||||
///
|
||||
/// # Safety
|
||||
///
|
||||
/// This function is unsafe because if you call it and SQLite has actually been
|
||||
/// configured to run in single-thread mode,
|
||||
/// you may enounter memory errors or data corruption or any number of terrible
|
||||
/// things that should not be possible when you're using Rust.
|
||||
@ -809,11 +816,13 @@ pub unsafe fn bypass_sqlite_initialization() {
|
||||
/// rusqlite performs a one-time check that the runtime SQLite version is at
|
||||
/// least as new as the version of SQLite found when rusqlite was built.
|
||||
/// Bypassing this check may be dangerous; e.g., if you use features of SQLite
|
||||
/// that are not present in the runtime
|
||||
/// version. If you are sure the runtime version is compatible with the
|
||||
/// that are not present in the runtime version.
|
||||
///
|
||||
/// # Safety
|
||||
///
|
||||
/// If you are sure the runtime version is compatible with the
|
||||
/// build-time version for your usage, you can bypass the version check by
|
||||
/// calling this function before
|
||||
/// your first connection attempt.
|
||||
/// calling this function before your first connection attempt.
|
||||
pub unsafe fn bypass_sqlite_version_check() {
|
||||
#[cfg(not(feature = "bundled"))]
|
||||
inner_connection::BYPASS_VERSION_CHECK.store(true, Ordering::Relaxed);
|
||||
@ -992,10 +1001,11 @@ mod test {
|
||||
let raw_db = db.db.borrow_mut().db;
|
||||
let sql = "SELECT 1";
|
||||
let mut raw_stmt = MaybeUninit::uninit();
|
||||
let cstring = str_to_cstring(sql).unwrap();
|
||||
let rc = unsafe {
|
||||
ffi::sqlite3_prepare_v2(
|
||||
raw_db,
|
||||
str_to_cstring(sql).unwrap().as_ptr(),
|
||||
cstring.as_ptr(),
|
||||
(sql.len() + 1) as c_int,
|
||||
raw_stmt.as_mut_ptr(),
|
||||
ptr::null_mut(),
|
||||
@ -1511,7 +1521,7 @@ mod test {
|
||||
.collect();
|
||||
|
||||
match bad_type.unwrap_err() {
|
||||
Error::InvalidColumnType(_, _, _) => (),
|
||||
Error::InvalidColumnType(..) => (),
|
||||
err => panic!("Unexpected error {}", err),
|
||||
}
|
||||
|
||||
@ -1566,7 +1576,7 @@ mod test {
|
||||
.collect();
|
||||
|
||||
match bad_type.unwrap_err() {
|
||||
CustomError::Sqlite(Error::InvalidColumnType(_, _, _)) => (),
|
||||
CustomError::Sqlite(Error::InvalidColumnType(..)) => (),
|
||||
err => panic!("Unexpected error {}", err),
|
||||
}
|
||||
|
||||
@ -1623,7 +1633,7 @@ mod test {
|
||||
});
|
||||
|
||||
match bad_type.unwrap_err() {
|
||||
CustomError::Sqlite(Error::InvalidColumnType(_, _, _)) => (),
|
||||
CustomError::Sqlite(Error::InvalidColumnType(..)) => (),
|
||||
err => panic!("Unexpected error {}", err),
|
||||
}
|
||||
|
||||
|
@ -1051,7 +1051,7 @@ mod test {
|
||||
use std::collections::BTreeSet;
|
||||
let data: BTreeSet<String> = ["one", "two", "three"]
|
||||
.iter()
|
||||
.map(|s| s.to_string())
|
||||
.map(|s| (*s).to_string())
|
||||
.collect();
|
||||
db.query_row("SELECT ?1, ?2, ?3", &data, |row| row.get::<_, String>(0))
|
||||
.unwrap();
|
||||
|
@ -12,6 +12,9 @@ use crate::error::error_from_sqlite_code;
|
||||
use crate::{Connection, Result};
|
||||
|
||||
/// Set up the process-wide SQLite error logging callback.
|
||||
///
|
||||
/// # Safety
|
||||
///
|
||||
/// This function is marked unsafe for two reasons:
|
||||
///
|
||||
/// * The function is not threadsafe. No other SQLite calls may be made while
|
||||
|
@ -36,7 +36,7 @@ impl PartialEq for FromSqlError {
|
||||
(FromSqlError::InvalidI128Size(s1), FromSqlError::InvalidI128Size(s2)) => s1 == s2,
|
||||
#[cfg(feature = "uuid")]
|
||||
(FromSqlError::InvalidUuidSize(s1), FromSqlError::InvalidUuidSize(s2)) => s1 == s2,
|
||||
(_, _) => false,
|
||||
(..) => false,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -225,7 +225,7 @@ mod test {
|
||||
fn test_mismatched_types() {
|
||||
fn is_invalid_column_type(err: Error) -> bool {
|
||||
match err {
|
||||
Error::InvalidColumnType(_, _, _) => true,
|
||||
Error::InvalidColumnType(..) => true,
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
|
@ -162,7 +162,11 @@ impl VTabConnection {
|
||||
///
|
||||
/// You should not need to use this function. If you do need to, please
|
||||
/// [open an issue on the rusqlite repository](https://github.com/jgallagher/rusqlite/issues) and describe
|
||||
/// your use case. This function is unsafe because it gives you raw access
|
||||
/// your use case.
|
||||
///
|
||||
/// # Safety
|
||||
///
|
||||
/// This function is unsafe because it gives you raw access
|
||||
/// to the SQLite connection, and what you do with it could impact the
|
||||
/// safety of this `Connection`.
|
||||
pub unsafe fn handle(&mut self) -> *mut ffi::sqlite3 {
|
||||
|
Loading…
Reference in New Issue
Block a user