mirror of
https://github.com/isar/rusqlite.git
synced 2025-06-15 16:02:36 +08:00
clippy::use_self
This commit is contained in:
parent
90320c9d37
commit
0c3933b68c
@ -336,7 +336,7 @@ pub enum HeaderLocation {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl From<HeaderLocation> for String {
|
impl From<HeaderLocation> for String {
|
||||||
fn from(header: HeaderLocation) -> String {
|
fn from(header: HeaderLocation) -> Self {
|
||||||
match header {
|
match header {
|
||||||
HeaderLocation::FromEnvironment => {
|
HeaderLocation::FromEnvironment => {
|
||||||
let prefix = env_prefix();
|
let prefix = env_prefix();
|
||||||
|
@ -64,7 +64,7 @@ pub struct Error {
|
|||||||
|
|
||||||
impl Error {
|
impl Error {
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub fn new(result_code: c_int) -> Error {
|
pub fn new(result_code: c_int) -> Self {
|
||||||
let code = match result_code & 0xff {
|
let code = match result_code & 0xff {
|
||||||
super::SQLITE_INTERNAL => ErrorCode::InternalMalfunction,
|
super::SQLITE_INTERNAL => ErrorCode::InternalMalfunction,
|
||||||
super::SQLITE_PERM => ErrorCode::PermissionDenied,
|
super::SQLITE_PERM => ErrorCode::PermissionDenied,
|
||||||
@ -92,7 +92,7 @@ impl Error {
|
|||||||
_ => ErrorCode::Unknown,
|
_ => ErrorCode::Unknown,
|
||||||
};
|
};
|
||||||
|
|
||||||
Error {
|
Self {
|
||||||
code,
|
code,
|
||||||
extended_code: result_code,
|
extended_code: result_code,
|
||||||
}
|
}
|
||||||
@ -288,13 +288,13 @@ pub enum InitError {
|
|||||||
impl ::std::fmt::Display for InitError {
|
impl ::std::fmt::Display for InitError {
|
||||||
fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {
|
fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {
|
||||||
match *self {
|
match *self {
|
||||||
InitError::VersionMismatch {
|
Self::VersionMismatch {
|
||||||
compile_time,
|
compile_time,
|
||||||
runtime,
|
runtime,
|
||||||
} => {
|
} => {
|
||||||
write!(f, "SQLite version mismatch: {runtime} < {compile_time}")
|
write!(f, "SQLite version mismatch: {runtime} < {compile_time}")
|
||||||
}
|
}
|
||||||
InitError::NullFunctionPointer => {
|
Self::NullFunctionPointer => {
|
||||||
write!(f, "Some sqlite3_api_routines fields are null")
|
write!(f, "Some sqlite3_api_routines fields are null")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -65,7 +65,7 @@ impl Connection {
|
|||||||
progress: Option<fn(Progress)>,
|
progress: Option<fn(Progress)>,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
use self::StepResult::{Busy, Done, Locked, More};
|
use self::StepResult::{Busy, Done, Locked, More};
|
||||||
let mut dst = Connection::open(dst_path)?;
|
let mut dst = Self::open(dst_path)?;
|
||||||
let backup = Backup::new_with_names(self, name, &mut dst, DatabaseName::Main)?;
|
let backup = Backup::new_with_names(self, name, &mut dst, DatabaseName::Main)?;
|
||||||
|
|
||||||
let mut r = More;
|
let mut r = More;
|
||||||
@ -103,7 +103,7 @@ impl Connection {
|
|||||||
progress: Option<F>,
|
progress: Option<F>,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
use self::StepResult::{Busy, Done, Locked, More};
|
use self::StepResult::{Busy, Done, Locked, More};
|
||||||
let src = Connection::open(src_path)?;
|
let src = Self::open(src_path)?;
|
||||||
let restore = Backup::new_with_names(&src, DatabaseName::Main, self, name)?;
|
let restore = Backup::new_with_names(&src, DatabaseName::Main, self, name)?;
|
||||||
|
|
||||||
let mut r = More;
|
let mut r = More;
|
||||||
|
@ -413,7 +413,7 @@ pub struct ZeroBlob(pub i32);
|
|||||||
impl ToSql for ZeroBlob {
|
impl ToSql for ZeroBlob {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn to_sql(&self) -> Result<ToSqlOutput<'_>> {
|
fn to_sql(&self) -> Result<ToSqlOutput<'_>> {
|
||||||
let ZeroBlob(length) = *self;
|
let Self(length) = *self;
|
||||||
Ok(ToSqlOutput::ZeroBlob(length))
|
Ok(ToSqlOutput::ZeroBlob(length))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -119,8 +119,8 @@ impl CachedStatement<'_> {
|
|||||||
impl StatementCache {
|
impl StatementCache {
|
||||||
/// Create a statement cache.
|
/// Create a statement cache.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn with_capacity(capacity: usize) -> StatementCache {
|
pub fn with_capacity(capacity: usize) -> Self {
|
||||||
StatementCache(RefCell::new(LruCache::new(capacity)))
|
Self(RefCell::new(LruCache::new(capacity)))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
|
@ -27,10 +27,7 @@ impl Connection {
|
|||||||
|
|
||||||
/// Collation needed callback
|
/// Collation needed callback
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn collation_needed(
|
pub fn collation_needed(&self, x_coll_needed: fn(&Self, &str) -> Result<()>) -> Result<()> {
|
||||||
&self,
|
|
||||||
x_coll_needed: fn(&Connection, &str) -> Result<()>,
|
|
||||||
) -> Result<()> {
|
|
||||||
self.db.borrow_mut().collation_needed(x_coll_needed)
|
self.db.borrow_mut().collation_needed(x_coll_needed)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
192
src/error.rs
192
src/error.rs
@ -151,55 +151,55 @@ pub enum Error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl PartialEq for Error {
|
impl PartialEq for Error {
|
||||||
fn eq(&self, other: &Error) -> bool {
|
fn eq(&self, other: &Self) -> bool {
|
||||||
match (self, other) {
|
match (self, other) {
|
||||||
(Error::SqliteFailure(e1, s1), Error::SqliteFailure(e2, s2)) => e1 == e2 && s1 == s2,
|
(Self::SqliteFailure(e1, s1), Self::SqliteFailure(e2, s2)) => e1 == e2 && s1 == s2,
|
||||||
(Error::SqliteSingleThreadedMode, Error::SqliteSingleThreadedMode) => true,
|
(Self::SqliteSingleThreadedMode, Self::SqliteSingleThreadedMode) => true,
|
||||||
(Error::IntegralValueOutOfRange(i1, n1), Error::IntegralValueOutOfRange(i2, n2)) => {
|
(Self::IntegralValueOutOfRange(i1, n1), Self::IntegralValueOutOfRange(i2, n2)) => {
|
||||||
i1 == i2 && n1 == n2
|
i1 == i2 && n1 == n2
|
||||||
}
|
}
|
||||||
(Error::Utf8Error(e1), Error::Utf8Error(e2)) => e1 == e2,
|
(Self::Utf8Error(e1), Self::Utf8Error(e2)) => e1 == e2,
|
||||||
(Error::NulError(e1), Error::NulError(e2)) => e1 == e2,
|
(Self::NulError(e1), Self::NulError(e2)) => e1 == e2,
|
||||||
(Error::InvalidParameterName(n1), Error::InvalidParameterName(n2)) => n1 == n2,
|
(Self::InvalidParameterName(n1), Self::InvalidParameterName(n2)) => n1 == n2,
|
||||||
(Error::InvalidPath(p1), Error::InvalidPath(p2)) => p1 == p2,
|
(Self::InvalidPath(p1), Self::InvalidPath(p2)) => p1 == p2,
|
||||||
(Error::ExecuteReturnedResults, Error::ExecuteReturnedResults) => true,
|
(Self::ExecuteReturnedResults, Self::ExecuteReturnedResults) => true,
|
||||||
(Error::QueryReturnedNoRows, Error::QueryReturnedNoRows) => true,
|
(Self::QueryReturnedNoRows, Self::QueryReturnedNoRows) => true,
|
||||||
(Error::InvalidColumnIndex(i1), Error::InvalidColumnIndex(i2)) => i1 == i2,
|
(Self::InvalidColumnIndex(i1), Self::InvalidColumnIndex(i2)) => i1 == i2,
|
||||||
(Error::InvalidColumnName(n1), Error::InvalidColumnName(n2)) => n1 == n2,
|
(Self::InvalidColumnName(n1), Self::InvalidColumnName(n2)) => n1 == n2,
|
||||||
(Error::InvalidColumnType(i1, n1, t1), Error::InvalidColumnType(i2, n2, t2)) => {
|
(Self::InvalidColumnType(i1, n1, t1), Self::InvalidColumnType(i2, n2, t2)) => {
|
||||||
i1 == i2 && t1 == t2 && n1 == n2
|
i1 == i2 && t1 == t2 && n1 == n2
|
||||||
}
|
}
|
||||||
(Error::StatementChangedRows(n1), Error::StatementChangedRows(n2)) => n1 == n2,
|
(Self::StatementChangedRows(n1), Self::StatementChangedRows(n2)) => n1 == n2,
|
||||||
#[cfg(feature = "functions")]
|
#[cfg(feature = "functions")]
|
||||||
(
|
(
|
||||||
Error::InvalidFunctionParameterType(i1, t1),
|
Self::InvalidFunctionParameterType(i1, t1),
|
||||||
Error::InvalidFunctionParameterType(i2, t2),
|
Self::InvalidFunctionParameterType(i2, t2),
|
||||||
) => i1 == i2 && t1 == t2,
|
) => i1 == i2 && t1 == t2,
|
||||||
#[cfg(feature = "vtab")]
|
#[cfg(feature = "vtab")]
|
||||||
(
|
(
|
||||||
Error::InvalidFilterParameterType(i1, t1),
|
Self::InvalidFilterParameterType(i1, t1),
|
||||||
Error::InvalidFilterParameterType(i2, t2),
|
Self::InvalidFilterParameterType(i2, t2),
|
||||||
) => i1 == i2 && t1 == t2,
|
) => i1 == i2 && t1 == t2,
|
||||||
(Error::InvalidQuery, Error::InvalidQuery) => true,
|
(Self::InvalidQuery, Self::InvalidQuery) => true,
|
||||||
#[cfg(feature = "vtab")]
|
#[cfg(feature = "vtab")]
|
||||||
(Error::ModuleError(s1), Error::ModuleError(s2)) => s1 == s2,
|
(Self::ModuleError(s1), Self::ModuleError(s2)) => s1 == s2,
|
||||||
(Error::UnwindingPanic, Error::UnwindingPanic) => true,
|
(Self::UnwindingPanic, Self::UnwindingPanic) => true,
|
||||||
#[cfg(feature = "functions")]
|
#[cfg(feature = "functions")]
|
||||||
(Error::GetAuxWrongType, Error::GetAuxWrongType) => true,
|
(Self::GetAuxWrongType, Self::GetAuxWrongType) => true,
|
||||||
(Error::InvalidParameterCount(i1, n1), Error::InvalidParameterCount(i2, n2)) => {
|
(Self::InvalidParameterCount(i1, n1), Self::InvalidParameterCount(i2, n2)) => {
|
||||||
i1 == i2 && n1 == n2
|
i1 == i2 && n1 == n2
|
||||||
}
|
}
|
||||||
#[cfg(feature = "blob")]
|
#[cfg(feature = "blob")]
|
||||||
(Error::BlobSizeError, Error::BlobSizeError) => true,
|
(Self::BlobSizeError, Self::BlobSizeError) => true,
|
||||||
#[cfg(feature = "modern_sqlite")]
|
#[cfg(feature = "modern_sqlite")]
|
||||||
(
|
(
|
||||||
Error::SqlInputError {
|
Self::SqlInputError {
|
||||||
error: e1,
|
error: e1,
|
||||||
msg: m1,
|
msg: m1,
|
||||||
sql: s1,
|
sql: s1,
|
||||||
offset: o1,
|
offset: o1,
|
||||||
},
|
},
|
||||||
Error::SqlInputError {
|
Self::SqlInputError {
|
||||||
error: e2,
|
error: e2,
|
||||||
msg: m2,
|
msg: m2,
|
||||||
sql: s2,
|
sql: s2,
|
||||||
@ -207,9 +207,9 @@ impl PartialEq for Error {
|
|||||||
},
|
},
|
||||||
) => e1 == e2 && m1 == m2 && s1 == s2 && o1 == o2,
|
) => e1 == e2 && m1 == m2 && s1 == s2 && o1 == o2,
|
||||||
#[cfg(feature = "loadable_extension")]
|
#[cfg(feature = "loadable_extension")]
|
||||||
(Error::InitError(e1), Error::InitError(e2)) => e1 == e2,
|
(Self::InitError(e1), Self::InitError(e2)) => e1 == e2,
|
||||||
#[cfg(feature = "modern_sqlite")]
|
#[cfg(feature = "modern_sqlite")]
|
||||||
(Error::InvalidDatabaseIndex(i1), Error::InvalidDatabaseIndex(i2)) => i1 == i2,
|
(Self::InvalidDatabaseIndex(i1), Self::InvalidDatabaseIndex(i2)) => i1 == i2,
|
||||||
(..) => false,
|
(..) => false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -217,15 +217,15 @@ impl PartialEq for Error {
|
|||||||
|
|
||||||
impl From<str::Utf8Error> for Error {
|
impl From<str::Utf8Error> for Error {
|
||||||
#[cold]
|
#[cold]
|
||||||
fn from(err: str::Utf8Error) -> Error {
|
fn from(err: str::Utf8Error) -> Self {
|
||||||
Error::Utf8Error(err)
|
Self::Utf8Error(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<std::ffi::NulError> for Error {
|
impl From<std::ffi::NulError> for Error {
|
||||||
#[cold]
|
#[cold]
|
||||||
fn from(err: std::ffi::NulError) -> Error {
|
fn from(err: std::ffi::NulError) -> Self {
|
||||||
Error::NulError(err)
|
Self::NulError(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -235,18 +235,18 @@ const UNKNOWN_COLUMN: usize = usize::MAX;
|
|||||||
/// to allow use of `get_raw(…).as_…()?` in callbacks that take `Error`.
|
/// to allow use of `get_raw(…).as_…()?` in callbacks that take `Error`.
|
||||||
impl From<FromSqlError> for Error {
|
impl From<FromSqlError> for Error {
|
||||||
#[cold]
|
#[cold]
|
||||||
fn from(err: FromSqlError) -> Error {
|
fn from(err: FromSqlError) -> Self {
|
||||||
// The error type requires index and type fields, but they aren't known in this
|
// The error type requires index and type fields, but they aren't known in this
|
||||||
// context.
|
// context.
|
||||||
match err {
|
match err {
|
||||||
FromSqlError::OutOfRange(val) => Error::IntegralValueOutOfRange(UNKNOWN_COLUMN, val),
|
FromSqlError::OutOfRange(val) => Self::IntegralValueOutOfRange(UNKNOWN_COLUMN, val),
|
||||||
FromSqlError::InvalidBlobSize { .. } => {
|
FromSqlError::InvalidBlobSize { .. } => {
|
||||||
Error::FromSqlConversionFailure(UNKNOWN_COLUMN, Type::Blob, Box::new(err))
|
Self::FromSqlConversionFailure(UNKNOWN_COLUMN, Type::Blob, Box::new(err))
|
||||||
}
|
}
|
||||||
FromSqlError::Other(source) => {
|
FromSqlError::Other(source) => {
|
||||||
Error::FromSqlConversionFailure(UNKNOWN_COLUMN, Type::Null, source)
|
Self::FromSqlConversionFailure(UNKNOWN_COLUMN, Type::Null, source)
|
||||||
}
|
}
|
||||||
_ => Error::FromSqlConversionFailure(UNKNOWN_COLUMN, Type::Null, Box::new(err)),
|
_ => Self::FromSqlConversionFailure(UNKNOWN_COLUMN, Type::Null, Box::new(err)),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -254,84 +254,84 @@ impl From<FromSqlError> for Error {
|
|||||||
#[cfg(feature = "loadable_extension")]
|
#[cfg(feature = "loadable_extension")]
|
||||||
impl From<ffi::InitError> for Error {
|
impl From<ffi::InitError> for Error {
|
||||||
#[cold]
|
#[cold]
|
||||||
fn from(err: ffi::InitError) -> Error {
|
fn from(err: ffi::InitError) -> Self {
|
||||||
Error::InitError(err)
|
Self::InitError(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl fmt::Display for Error {
|
impl fmt::Display for Error {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
match *self {
|
match *self {
|
||||||
Error::SqliteFailure(ref err, None) => err.fmt(f),
|
Self::SqliteFailure(ref err, None) => err.fmt(f),
|
||||||
Error::SqliteFailure(_, Some(ref s)) => write!(f, "{s}"),
|
Self::SqliteFailure(_, Some(ref s)) => write!(f, "{s}"),
|
||||||
Error::SqliteSingleThreadedMode => write!(
|
Self::SqliteSingleThreadedMode => write!(
|
||||||
f,
|
f,
|
||||||
"SQLite was compiled or configured for single-threaded use only"
|
"SQLite was compiled or configured for single-threaded use only"
|
||||||
),
|
),
|
||||||
Error::FromSqlConversionFailure(i, ref t, ref err) => {
|
Self::FromSqlConversionFailure(i, ref t, ref err) => {
|
||||||
if i != UNKNOWN_COLUMN {
|
if i != UNKNOWN_COLUMN {
|
||||||
write!(f, "Conversion error from type {t} at index: {i}, {err}")
|
write!(f, "Conversion error from type {t} at index: {i}, {err}")
|
||||||
} else {
|
} else {
|
||||||
err.fmt(f)
|
err.fmt(f)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Error::IntegralValueOutOfRange(col, val) => {
|
Self::IntegralValueOutOfRange(col, val) => {
|
||||||
if col != UNKNOWN_COLUMN {
|
if col != UNKNOWN_COLUMN {
|
||||||
write!(f, "Integer {val} out of range at index {col}")
|
write!(f, "Integer {val} out of range at index {col}")
|
||||||
} else {
|
} else {
|
||||||
write!(f, "Integer {val} out of range")
|
write!(f, "Integer {val} out of range")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Error::Utf8Error(ref err) => err.fmt(f),
|
Self::Utf8Error(ref err) => err.fmt(f),
|
||||||
Error::NulError(ref err) => err.fmt(f),
|
Self::NulError(ref err) => err.fmt(f),
|
||||||
Error::InvalidParameterName(ref name) => write!(f, "Invalid parameter name: {name}"),
|
Self::InvalidParameterName(ref name) => write!(f, "Invalid parameter name: {name}"),
|
||||||
Error::InvalidPath(ref p) => write!(f, "Invalid path: {}", p.to_string_lossy()),
|
Self::InvalidPath(ref p) => write!(f, "Invalid path: {}", p.to_string_lossy()),
|
||||||
Error::ExecuteReturnedResults => {
|
Self::ExecuteReturnedResults => {
|
||||||
write!(f, "Execute returned results - did you mean to call query?")
|
write!(f, "Execute returned results - did you mean to call query?")
|
||||||
}
|
}
|
||||||
Error::QueryReturnedNoRows => write!(f, "Query returned no rows"),
|
Self::QueryReturnedNoRows => write!(f, "Query returned no rows"),
|
||||||
Error::InvalidColumnIndex(i) => write!(f, "Invalid column index: {i}"),
|
Self::InvalidColumnIndex(i) => write!(f, "Invalid column index: {i}"),
|
||||||
Error::InvalidColumnName(ref name) => write!(f, "Invalid column name: {name}"),
|
Self::InvalidColumnName(ref name) => write!(f, "Invalid column name: {name}"),
|
||||||
Error::InvalidColumnType(i, ref name, ref t) => {
|
Self::InvalidColumnType(i, ref name, ref t) => {
|
||||||
write!(f, "Invalid column type {t} at index: {i}, name: {name}")
|
write!(f, "Invalid column type {t} at index: {i}, name: {name}")
|
||||||
}
|
}
|
||||||
Error::InvalidParameterCount(i1, n1) => write!(
|
Self::InvalidParameterCount(i1, n1) => write!(
|
||||||
f,
|
f,
|
||||||
"Wrong number of parameters passed to query. Got {i1}, needed {n1}"
|
"Wrong number of parameters passed to query. Got {i1}, needed {n1}"
|
||||||
),
|
),
|
||||||
Error::StatementChangedRows(i) => write!(f, "Query changed {i} rows"),
|
Self::StatementChangedRows(i) => write!(f, "Query changed {i} rows"),
|
||||||
|
|
||||||
#[cfg(feature = "functions")]
|
#[cfg(feature = "functions")]
|
||||||
Error::InvalidFunctionParameterType(i, ref t) => {
|
Self::InvalidFunctionParameterType(i, ref t) => {
|
||||||
write!(f, "Invalid function parameter type {t} at index {i}")
|
write!(f, "Invalid function parameter type {t} at index {i}")
|
||||||
}
|
}
|
||||||
#[cfg(feature = "vtab")]
|
#[cfg(feature = "vtab")]
|
||||||
Error::InvalidFilterParameterType(i, ref t) => {
|
Self::InvalidFilterParameterType(i, ref t) => {
|
||||||
write!(f, "Invalid filter parameter type {t} at index {i}")
|
write!(f, "Invalid filter parameter type {t} at index {i}")
|
||||||
}
|
}
|
||||||
#[cfg(feature = "functions")]
|
#[cfg(feature = "functions")]
|
||||||
Error::UserFunctionError(ref err) => err.fmt(f),
|
Self::UserFunctionError(ref err) => err.fmt(f),
|
||||||
Error::ToSqlConversionFailure(ref err) => err.fmt(f),
|
Self::ToSqlConversionFailure(ref err) => err.fmt(f),
|
||||||
Error::InvalidQuery => write!(f, "Query is not read-only"),
|
Self::InvalidQuery => write!(f, "Query is not read-only"),
|
||||||
#[cfg(feature = "vtab")]
|
#[cfg(feature = "vtab")]
|
||||||
Error::ModuleError(ref desc) => write!(f, "{desc}"),
|
Self::ModuleError(ref desc) => write!(f, "{desc}"),
|
||||||
Error::UnwindingPanic => write!(f, "unwinding panic"),
|
Self::UnwindingPanic => write!(f, "unwinding panic"),
|
||||||
#[cfg(feature = "functions")]
|
#[cfg(feature = "functions")]
|
||||||
Error::GetAuxWrongType => write!(f, "get_aux called with wrong type"),
|
Self::GetAuxWrongType => write!(f, "get_aux called with wrong type"),
|
||||||
Error::MultipleStatement => write!(f, "Multiple statements provided"),
|
Self::MultipleStatement => write!(f, "Multiple statements provided"),
|
||||||
#[cfg(feature = "blob")]
|
#[cfg(feature = "blob")]
|
||||||
Error::BlobSizeError => "Blob size is insufficient".fmt(f),
|
Self::BlobSizeError => "Blob size is insufficient".fmt(f),
|
||||||
#[cfg(feature = "modern_sqlite")]
|
#[cfg(feature = "modern_sqlite")]
|
||||||
Error::SqlInputError {
|
Self::SqlInputError {
|
||||||
ref msg,
|
ref msg,
|
||||||
offset,
|
offset,
|
||||||
ref sql,
|
ref sql,
|
||||||
..
|
..
|
||||||
} => write!(f, "{msg} in {sql} at offset {offset}"),
|
} => write!(f, "{msg} in {sql} at offset {offset}"),
|
||||||
#[cfg(feature = "loadable_extension")]
|
#[cfg(feature = "loadable_extension")]
|
||||||
Error::InitError(ref err) => err.fmt(f),
|
Self::InitError(ref err) => err.fmt(f),
|
||||||
#[cfg(feature = "modern_sqlite")]
|
#[cfg(feature = "modern_sqlite")]
|
||||||
Error::InvalidDatabaseIndex(i) => write!(f, "Invalid database index: {i}"),
|
Self::InvalidDatabaseIndex(i) => write!(f, "Invalid database index: {i}"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -339,51 +339,51 @@ impl fmt::Display for Error {
|
|||||||
impl error::Error for Error {
|
impl error::Error for Error {
|
||||||
fn source(&self) -> Option<&(dyn error::Error + 'static)> {
|
fn source(&self) -> Option<&(dyn error::Error + 'static)> {
|
||||||
match *self {
|
match *self {
|
||||||
Error::SqliteFailure(ref err, _) => Some(err),
|
Self::SqliteFailure(ref err, _) => Some(err),
|
||||||
Error::Utf8Error(ref err) => Some(err),
|
Self::Utf8Error(ref err) => Some(err),
|
||||||
Error::NulError(ref err) => Some(err),
|
Self::NulError(ref err) => Some(err),
|
||||||
|
|
||||||
Error::IntegralValueOutOfRange(..)
|
Self::IntegralValueOutOfRange(..)
|
||||||
| Error::SqliteSingleThreadedMode
|
| Self::SqliteSingleThreadedMode
|
||||||
| Error::InvalidParameterName(_)
|
| Self::InvalidParameterName(_)
|
||||||
| Error::ExecuteReturnedResults
|
| Self::ExecuteReturnedResults
|
||||||
| Error::QueryReturnedNoRows
|
| Self::QueryReturnedNoRows
|
||||||
| Error::InvalidColumnIndex(_)
|
| Self::InvalidColumnIndex(_)
|
||||||
| Error::InvalidColumnName(_)
|
| Self::InvalidColumnName(_)
|
||||||
| Error::InvalidColumnType(..)
|
| Self::InvalidColumnType(..)
|
||||||
| Error::InvalidPath(_)
|
| Self::InvalidPath(_)
|
||||||
| Error::InvalidParameterCount(..)
|
| Self::InvalidParameterCount(..)
|
||||||
| Error::StatementChangedRows(_)
|
| Self::StatementChangedRows(_)
|
||||||
| Error::InvalidQuery
|
| Self::InvalidQuery
|
||||||
| Error::MultipleStatement => None,
|
| Self::MultipleStatement => None,
|
||||||
|
|
||||||
#[cfg(feature = "functions")]
|
#[cfg(feature = "functions")]
|
||||||
Error::InvalidFunctionParameterType(..) => None,
|
Self::InvalidFunctionParameterType(..) => None,
|
||||||
#[cfg(feature = "vtab")]
|
#[cfg(feature = "vtab")]
|
||||||
Error::InvalidFilterParameterType(..) => None,
|
Self::InvalidFilterParameterType(..) => None,
|
||||||
|
|
||||||
#[cfg(feature = "functions")]
|
#[cfg(feature = "functions")]
|
||||||
Error::UserFunctionError(ref err) => Some(&**err),
|
Self::UserFunctionError(ref err) => Some(&**err),
|
||||||
|
|
||||||
Error::FromSqlConversionFailure(_, _, ref err)
|
Self::FromSqlConversionFailure(_, _, ref err)
|
||||||
| Error::ToSqlConversionFailure(ref err) => Some(&**err),
|
| Self::ToSqlConversionFailure(ref err) => Some(&**err),
|
||||||
|
|
||||||
#[cfg(feature = "vtab")]
|
#[cfg(feature = "vtab")]
|
||||||
Error::ModuleError(_) => None,
|
Self::ModuleError(_) => None,
|
||||||
|
|
||||||
Error::UnwindingPanic => None,
|
Self::UnwindingPanic => None,
|
||||||
|
|
||||||
#[cfg(feature = "functions")]
|
#[cfg(feature = "functions")]
|
||||||
Error::GetAuxWrongType => None,
|
Self::GetAuxWrongType => None,
|
||||||
|
|
||||||
#[cfg(feature = "blob")]
|
#[cfg(feature = "blob")]
|
||||||
Error::BlobSizeError => None,
|
Self::BlobSizeError => None,
|
||||||
#[cfg(feature = "modern_sqlite")]
|
#[cfg(feature = "modern_sqlite")]
|
||||||
Error::SqlInputError { ref error, .. } => Some(error),
|
Self::SqlInputError { ref error, .. } => Some(error),
|
||||||
#[cfg(feature = "loadable_extension")]
|
#[cfg(feature = "loadable_extension")]
|
||||||
Error::InitError(ref err) => Some(err),
|
Self::InitError(ref err) => Some(err),
|
||||||
#[cfg(feature = "modern_sqlite")]
|
#[cfg(feature = "modern_sqlite")]
|
||||||
Error::InvalidDatabaseIndex(_) => None,
|
Self::InvalidDatabaseIndex(_) => None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -392,8 +392,8 @@ bitflags::bitflags! {
|
|||||||
|
|
||||||
impl Default for FunctionFlags {
|
impl Default for FunctionFlags {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn default() -> FunctionFlags {
|
fn default() -> Self {
|
||||||
FunctionFlags::SQLITE_UTF8
|
Self::SQLITE_UTF8
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -33,12 +33,12 @@ pub enum Action {
|
|||||||
|
|
||||||
impl From<i32> for Action {
|
impl From<i32> for Action {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn from(code: i32) -> Action {
|
fn from(code: i32) -> Self {
|
||||||
match code {
|
match code {
|
||||||
ffi::SQLITE_DELETE => Action::SQLITE_DELETE,
|
ffi::SQLITE_DELETE => Self::SQLITE_DELETE,
|
||||||
ffi::SQLITE_INSERT => Action::SQLITE_INSERT,
|
ffi::SQLITE_INSERT => Self::SQLITE_INSERT,
|
||||||
ffi::SQLITE_UPDATE => Action::SQLITE_UPDATE,
|
ffi::SQLITE_UPDATE => Self::SQLITE_UPDATE,
|
||||||
_ => Action::UNKNOWN,
|
_ => Self::UNKNOWN,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -43,8 +43,8 @@ unsafe impl Send for InnerConnection {}
|
|||||||
impl InnerConnection {
|
impl InnerConnection {
|
||||||
#[allow(clippy::mutex_atomic, clippy::arc_with_non_send_sync)] // See unsafe impl Send / Sync for InterruptHandle
|
#[allow(clippy::mutex_atomic, clippy::arc_with_non_send_sync)] // See unsafe impl Send / Sync for InterruptHandle
|
||||||
#[inline]
|
#[inline]
|
||||||
pub unsafe fn new(db: *mut ffi::sqlite3, owned: bool) -> InnerConnection {
|
pub unsafe fn new(db: *mut ffi::sqlite3, owned: bool) -> Self {
|
||||||
InnerConnection {
|
Self {
|
||||||
db,
|
db,
|
||||||
interrupt_lock: Arc::new(Mutex::new(if owned { db } else { ptr::null_mut() })),
|
interrupt_lock: Arc::new(Mutex::new(if owned { db } else { ptr::null_mut() })),
|
||||||
#[cfg(feature = "hooks")]
|
#[cfg(feature = "hooks")]
|
||||||
@ -67,7 +67,7 @@ impl InnerConnection {
|
|||||||
c_path: &CStr,
|
c_path: &CStr,
|
||||||
mut flags: OpenFlags,
|
mut flags: OpenFlags,
|
||||||
vfs: Option<&CStr>,
|
vfs: Option<&CStr>,
|
||||||
) -> Result<InnerConnection> {
|
) -> Result<Self> {
|
||||||
ensure_safe_sqlite_threading_mode()?;
|
ensure_safe_sqlite_threading_mode()?;
|
||||||
|
|
||||||
let z_vfs = match vfs {
|
let z_vfs = match vfs {
|
||||||
@ -123,7 +123,7 @@ impl InnerConnection {
|
|||||||
return Err(e);
|
return Err(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(InnerConnection::new(db, true))
|
Ok(Self::new(db, true))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -134,7 +134,7 @@ impl InnerConnection {
|
|||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn decode_result(&self, code: c_int) -> Result<()> {
|
pub fn decode_result(&self, code: c_int) -> Result<()> {
|
||||||
unsafe { InnerConnection::decode_result_raw(self.db(), code) }
|
unsafe { Self::decode_result_raw(self.db(), code) }
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
@ -166,7 +166,7 @@ impl InnerConnection {
|
|||||||
let r = ffi::sqlite3_close(self.db);
|
let r = ffi::sqlite3_close(self.db);
|
||||||
// Need to use _raw because _guard has a reference out, and
|
// Need to use _raw because _guard has a reference out, and
|
||||||
// decode_result takes &mut self.
|
// decode_result takes &mut self.
|
||||||
let r = InnerConnection::decode_result_raw(self.db, r);
|
let r = Self::decode_result_raw(self.db, r);
|
||||||
if r.is_ok() {
|
if r.is_ok() {
|
||||||
*shared_handle = ptr::null_mut();
|
*shared_handle = ptr::null_mut();
|
||||||
self.db = ptr::null_mut();
|
self.db = ptr::null_mut();
|
||||||
|
62
src/lib.rs
62
src/lib.rs
@ -443,9 +443,9 @@ impl Connection {
|
|||||||
/// Will return `Err` if `path` cannot be converted to a C-compatible string
|
/// Will return `Err` if `path` cannot be converted to a C-compatible string
|
||||||
/// or if the underlying SQLite open call fails.
|
/// or if the underlying SQLite open call fails.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn open<P: AsRef<Path>>(path: P) -> Result<Connection> {
|
pub fn open<P: AsRef<Path>>(path: P) -> Result<Self> {
|
||||||
let flags = OpenFlags::default();
|
let flags = OpenFlags::default();
|
||||||
Connection::open_with_flags(path, flags)
|
Self::open_with_flags(path, flags)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Open a new connection to an in-memory SQLite database.
|
/// Open a new connection to an in-memory SQLite database.
|
||||||
@ -454,9 +454,9 @@ impl Connection {
|
|||||||
///
|
///
|
||||||
/// Will return `Err` if the underlying SQLite open call fails.
|
/// Will return `Err` if the underlying SQLite open call fails.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn open_in_memory() -> Result<Connection> {
|
pub fn open_in_memory() -> Result<Self> {
|
||||||
let flags = OpenFlags::default();
|
let flags = OpenFlags::default();
|
||||||
Connection::open_in_memory_with_flags(flags)
|
Self::open_in_memory_with_flags(flags)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Open a new connection to a SQLite database.
|
/// Open a new connection to a SQLite database.
|
||||||
@ -469,9 +469,9 @@ impl Connection {
|
|||||||
/// Will return `Err` if `path` cannot be converted to a C-compatible
|
/// Will return `Err` if `path` cannot be converted to a C-compatible
|
||||||
/// string or if the underlying SQLite open call fails.
|
/// string or if the underlying SQLite open call fails.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn open_with_flags<P: AsRef<Path>>(path: P, flags: OpenFlags) -> Result<Connection> {
|
pub fn open_with_flags<P: AsRef<Path>>(path: P, flags: OpenFlags) -> Result<Self> {
|
||||||
let c_path = path_to_cstring(path.as_ref())?;
|
let c_path = path_to_cstring(path.as_ref())?;
|
||||||
InnerConnection::open_with_flags(&c_path, flags, None).map(|db| Connection {
|
InnerConnection::open_with_flags(&c_path, flags, None).map(|db| Self {
|
||||||
db: RefCell::new(db),
|
db: RefCell::new(db),
|
||||||
cache: StatementCache::with_capacity(STATEMENT_CACHE_DEFAULT_CAPACITY),
|
cache: StatementCache::with_capacity(STATEMENT_CACHE_DEFAULT_CAPACITY),
|
||||||
transaction_behavior: TransactionBehavior::Deferred,
|
transaction_behavior: TransactionBehavior::Deferred,
|
||||||
@ -493,10 +493,10 @@ impl Connection {
|
|||||||
path: P,
|
path: P,
|
||||||
flags: OpenFlags,
|
flags: OpenFlags,
|
||||||
vfs: &str,
|
vfs: &str,
|
||||||
) -> Result<Connection> {
|
) -> Result<Self> {
|
||||||
let c_path = path_to_cstring(path.as_ref())?;
|
let c_path = path_to_cstring(path.as_ref())?;
|
||||||
let c_vfs = str_to_cstring(vfs)?;
|
let c_vfs = str_to_cstring(vfs)?;
|
||||||
InnerConnection::open_with_flags(&c_path, flags, Some(&c_vfs)).map(|db| Connection {
|
InnerConnection::open_with_flags(&c_path, flags, Some(&c_vfs)).map(|db| Self {
|
||||||
db: RefCell::new(db),
|
db: RefCell::new(db),
|
||||||
cache: StatementCache::with_capacity(STATEMENT_CACHE_DEFAULT_CAPACITY),
|
cache: StatementCache::with_capacity(STATEMENT_CACHE_DEFAULT_CAPACITY),
|
||||||
transaction_behavior: TransactionBehavior::Deferred,
|
transaction_behavior: TransactionBehavior::Deferred,
|
||||||
@ -512,8 +512,8 @@ impl Connection {
|
|||||||
///
|
///
|
||||||
/// Will return `Err` if the underlying SQLite open call fails.
|
/// Will return `Err` if the underlying SQLite open call fails.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn open_in_memory_with_flags(flags: OpenFlags) -> Result<Connection> {
|
pub fn open_in_memory_with_flags(flags: OpenFlags) -> Result<Self> {
|
||||||
Connection::open_with_flags(":memory:", flags)
|
Self::open_with_flags(":memory:", flags)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Open a new connection to an in-memory SQLite database using the specific
|
/// Open a new connection to an in-memory SQLite database using the specific
|
||||||
@ -527,8 +527,8 @@ impl Connection {
|
|||||||
/// Will return `Err` if `vfs` cannot be converted to a C-compatible
|
/// Will return `Err` if `vfs` cannot be converted to a C-compatible
|
||||||
/// string or if the underlying SQLite open call fails.
|
/// string or if the underlying SQLite open call fails.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn open_in_memory_with_flags_and_vfs(flags: OpenFlags, vfs: &str) -> Result<Connection> {
|
pub fn open_in_memory_with_flags_and_vfs(flags: OpenFlags, vfs: &str) -> Result<Self> {
|
||||||
Connection::open_with_flags_and_vfs(":memory:", flags, vfs)
|
Self::open_with_flags_and_vfs(":memory:", flags, vfs)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Convenience method to run multiple SQL statements (that cannot take any
|
/// Convenience method to run multiple SQL statements (that cannot take any
|
||||||
@ -792,7 +792,7 @@ impl Connection {
|
|||||||
///
|
///
|
||||||
/// Will return `Err` if the underlying SQLite call fails.
|
/// Will return `Err` if the underlying SQLite call fails.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn close(self) -> Result<(), (Connection, Error)> {
|
pub fn close(self) -> Result<(), (Self, Error)> {
|
||||||
self.flush_prepared_statement_cache();
|
self.flush_prepared_statement_cache();
|
||||||
let r = self.db.borrow_mut().close();
|
let r = self.db.borrow_mut().close();
|
||||||
r.map_err(move |err| (self, err))
|
r.map_err(move |err| (self, err))
|
||||||
@ -947,9 +947,9 @@ impl Connection {
|
|||||||
///
|
///
|
||||||
/// This function is unsafe because improper use may impact the Connection.
|
/// This function is unsafe because improper use may impact the Connection.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub unsafe fn from_handle(db: *mut ffi::sqlite3) -> Result<Connection> {
|
pub unsafe fn from_handle(db: *mut ffi::sqlite3) -> Result<Self> {
|
||||||
let db = InnerConnection::new(db, false);
|
let db = InnerConnection::new(db, false);
|
||||||
Ok(Connection {
|
Ok(Self {
|
||||||
db: RefCell::new(db),
|
db: RefCell::new(db),
|
||||||
cache: StatementCache::with_capacity(STATEMENT_CACHE_DEFAULT_CAPACITY),
|
cache: StatementCache::with_capacity(STATEMENT_CACHE_DEFAULT_CAPACITY),
|
||||||
transaction_behavior: TransactionBehavior::Deferred,
|
transaction_behavior: TransactionBehavior::Deferred,
|
||||||
@ -967,14 +967,14 @@ impl Connection {
|
|||||||
db: *mut ffi::sqlite3,
|
db: *mut ffi::sqlite3,
|
||||||
pz_err_msg: *mut *mut c_char,
|
pz_err_msg: *mut *mut c_char,
|
||||||
p_api: *mut ffi::sqlite3_api_routines,
|
p_api: *mut ffi::sqlite3_api_routines,
|
||||||
init: fn(Connection) -> Result<bool>,
|
init: fn(Self) -> Result<bool>,
|
||||||
) -> c_int {
|
) -> c_int {
|
||||||
if p_api.is_null() {
|
if p_api.is_null() {
|
||||||
return ffi::SQLITE_ERROR;
|
return ffi::SQLITE_ERROR;
|
||||||
}
|
}
|
||||||
match ffi::rusqlite_extension_init2(p_api)
|
match ffi::rusqlite_extension_init2(p_api)
|
||||||
.map_err(Error::from)
|
.map_err(Error::from)
|
||||||
.and(Connection::from_handle(db))
|
.and(Self::from_handle(db))
|
||||||
.and_then(init)
|
.and_then(init)
|
||||||
{
|
{
|
||||||
Err(err) => to_sqlite_error(&err, pz_err_msg),
|
Err(err) => to_sqlite_error(&err, pz_err_msg),
|
||||||
@ -996,9 +996,9 @@ impl Connection {
|
|||||||
/// and owned by the caller, e.g. as a result of calling
|
/// and owned by the caller, e.g. as a result of calling
|
||||||
/// `ffi::sqlite3_open`().
|
/// `ffi::sqlite3_open`().
|
||||||
#[inline]
|
#[inline]
|
||||||
pub unsafe fn from_handle_owned(db: *mut ffi::sqlite3) -> Result<Connection> {
|
pub unsafe fn from_handle_owned(db: *mut ffi::sqlite3) -> Result<Self> {
|
||||||
let db = InnerConnection::new(db, true);
|
let db = InnerConnection::new(db, true);
|
||||||
Ok(Connection {
|
Ok(Self {
|
||||||
db: RefCell::new(db),
|
db: RefCell::new(db),
|
||||||
cache: StatementCache::with_capacity(STATEMENT_CACHE_DEFAULT_CAPACITY),
|
cache: StatementCache::with_capacity(STATEMENT_CACHE_DEFAULT_CAPACITY),
|
||||||
transaction_behavior: TransactionBehavior::Deferred,
|
transaction_behavior: TransactionBehavior::Deferred,
|
||||||
@ -1121,7 +1121,7 @@ pub struct Batch<'conn, 'sql> {
|
|||||||
|
|
||||||
impl<'conn, 'sql> Batch<'conn, 'sql> {
|
impl<'conn, 'sql> Batch<'conn, 'sql> {
|
||||||
/// Constructor
|
/// Constructor
|
||||||
pub fn new(conn: &'conn Connection, sql: &'sql str) -> Batch<'conn, 'sql> {
|
pub fn new(conn: &'conn Connection, sql: &'sql str) -> Self {
|
||||||
Batch { conn, sql, tail: 0 }
|
Batch { conn, sql, tail: 0 }
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1230,13 +1230,13 @@ bitflags::bitflags! {
|
|||||||
|
|
||||||
impl Default for OpenFlags {
|
impl Default for OpenFlags {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn default() -> OpenFlags {
|
fn default() -> Self {
|
||||||
// Note: update the `Connection::open` and top-level `OpenFlags` docs if
|
// Note: update the `Connection::open` and top-level `OpenFlags` docs if
|
||||||
// you change these.
|
// you change these.
|
||||||
OpenFlags::SQLITE_OPEN_READ_WRITE
|
Self::SQLITE_OPEN_READ_WRITE
|
||||||
| OpenFlags::SQLITE_OPEN_CREATE
|
| Self::SQLITE_OPEN_CREATE
|
||||||
| OpenFlags::SQLITE_OPEN_NO_MUTEX
|
| Self::SQLITE_OPEN_NO_MUTEX
|
||||||
| OpenFlags::SQLITE_OPEN_URI
|
| Self::SQLITE_OPEN_URI
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1951,8 +1951,8 @@ mod test {
|
|||||||
impl fmt::Display for CustomError {
|
impl fmt::Display for CustomError {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> {
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> {
|
||||||
match *self {
|
match *self {
|
||||||
CustomError::SomeError => write!(f, "my custom error"),
|
Self::SomeError => write!(f, "my custom error"),
|
||||||
CustomError::Sqlite(ref se) => write!(f, "my custom error: {se}"),
|
Self::Sqlite(ref se) => write!(f, "my custom error: {se}"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1964,15 +1964,15 @@ mod test {
|
|||||||
|
|
||||||
fn cause(&self) -> Option<&dyn StdError> {
|
fn cause(&self) -> Option<&dyn StdError> {
|
||||||
match *self {
|
match *self {
|
||||||
CustomError::SomeError => None,
|
Self::SomeError => None,
|
||||||
CustomError::Sqlite(ref se) => Some(se),
|
Self::Sqlite(ref se) => Some(se),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<Error> for CustomError {
|
impl From<Error> for CustomError {
|
||||||
fn from(se: Error) -> CustomError {
|
fn from(se: Error) -> Self {
|
||||||
CustomError::Sqlite(se)
|
Self::Sqlite(se)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -12,8 +12,8 @@ pub struct Sql {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Sql {
|
impl Sql {
|
||||||
pub fn new() -> Sql {
|
pub fn new() -> Self {
|
||||||
Sql { buf: String::new() }
|
Self { buf: String::new() }
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn push_pragma(
|
pub fn push_pragma(
|
||||||
|
@ -29,8 +29,8 @@ pub struct RawStatement {
|
|||||||
|
|
||||||
impl RawStatement {
|
impl RawStatement {
|
||||||
#[inline]
|
#[inline]
|
||||||
pub unsafe fn new(stmt: *mut ffi::sqlite3_stmt, tail: usize) -> RawStatement {
|
pub unsafe fn new(stmt: *mut ffi::sqlite3_stmt, tail: usize) -> Self {
|
||||||
RawStatement {
|
Self {
|
||||||
ptr: stmt,
|
ptr: stmt,
|
||||||
tail,
|
tail,
|
||||||
cache: ParamIndexCache::default(),
|
cache: ParamIndexCache::default(),
|
||||||
|
@ -90,7 +90,7 @@ impl<'stmt> Rows<'stmt> {
|
|||||||
|
|
||||||
impl<'stmt> Rows<'stmt> {
|
impl<'stmt> Rows<'stmt> {
|
||||||
#[inline]
|
#[inline]
|
||||||
pub(crate) fn new(stmt: &'stmt Statement<'stmt>) -> Rows<'stmt> {
|
pub(crate) fn new(stmt: &'stmt Statement<'stmt>) -> Self {
|
||||||
Rows {
|
Rows {
|
||||||
stmt: Some(stmt),
|
stmt: Some(stmt),
|
||||||
row: None,
|
row: None,
|
||||||
|
@ -20,7 +20,7 @@ impl FromSql for NaiveDate {
|
|||||||
fn column_result(value: ValueRef<'_>) -> FromSqlResult<Self> {
|
fn column_result(value: ValueRef<'_>) -> FromSqlResult<Self> {
|
||||||
value
|
value
|
||||||
.as_str()
|
.as_str()
|
||||||
.and_then(|s| match NaiveDate::parse_from_str(s, "%F") {
|
.and_then(|s| match Self::parse_from_str(s, "%F") {
|
||||||
Ok(dt) => Ok(dt),
|
Ok(dt) => Ok(dt),
|
||||||
Err(err) => Err(FromSqlError::Other(Box::new(err))),
|
Err(err) => Err(FromSqlError::Other(Box::new(err))),
|
||||||
})
|
})
|
||||||
@ -45,7 +45,7 @@ impl FromSql for NaiveTime {
|
|||||||
8 => "%T",
|
8 => "%T",
|
||||||
_ => "%T%.f",
|
_ => "%T%.f",
|
||||||
};
|
};
|
||||||
match NaiveTime::parse_from_str(s, fmt) {
|
match Self::parse_from_str(s, fmt) {
|
||||||
Ok(dt) => Ok(dt),
|
Ok(dt) => Ok(dt),
|
||||||
Err(err) => Err(FromSqlError::Other(Box::new(err))),
|
Err(err) => Err(FromSqlError::Other(Box::new(err))),
|
||||||
}
|
}
|
||||||
@ -75,7 +75,7 @@ impl FromSql for NaiveDateTime {
|
|||||||
"%F %T%.f"
|
"%F %T%.f"
|
||||||
};
|
};
|
||||||
|
|
||||||
match NaiveDateTime::parse_from_str(s, fmt) {
|
match Self::parse_from_str(s, fmt) {
|
||||||
Ok(dt) => Ok(dt),
|
Ok(dt) => Ok(dt),
|
||||||
Err(err) => Err(FromSqlError::Other(Box::new(err))),
|
Err(err) => Err(FromSqlError::Other(Box::new(err))),
|
||||||
}
|
}
|
||||||
|
@ -28,16 +28,16 @@ pub enum FromSqlError {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl PartialEq for FromSqlError {
|
impl PartialEq for FromSqlError {
|
||||||
fn eq(&self, other: &FromSqlError) -> bool {
|
fn eq(&self, other: &Self) -> bool {
|
||||||
match (self, other) {
|
match (self, other) {
|
||||||
(FromSqlError::InvalidType, FromSqlError::InvalidType) => true,
|
(Self::InvalidType, Self::InvalidType) => true,
|
||||||
(FromSqlError::OutOfRange(n1), FromSqlError::OutOfRange(n2)) => n1 == n2,
|
(Self::OutOfRange(n1), Self::OutOfRange(n2)) => n1 == n2,
|
||||||
(
|
(
|
||||||
FromSqlError::InvalidBlobSize {
|
Self::InvalidBlobSize {
|
||||||
expected_size: es1,
|
expected_size: es1,
|
||||||
blob_size: bs1,
|
blob_size: bs1,
|
||||||
},
|
},
|
||||||
FromSqlError::InvalidBlobSize {
|
Self::InvalidBlobSize {
|
||||||
expected_size: es2,
|
expected_size: es2,
|
||||||
blob_size: bs2,
|
blob_size: bs2,
|
||||||
},
|
},
|
||||||
@ -50,9 +50,9 @@ impl PartialEq for FromSqlError {
|
|||||||
impl fmt::Display for FromSqlError {
|
impl fmt::Display for FromSqlError {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
match *self {
|
match *self {
|
||||||
FromSqlError::InvalidType => write!(f, "Invalid type"),
|
Self::InvalidType => write!(f, "Invalid type"),
|
||||||
FromSqlError::OutOfRange(i) => write!(f, "Value {i} out of range"),
|
Self::OutOfRange(i) => write!(f, "Value {i} out of range"),
|
||||||
FromSqlError::InvalidBlobSize {
|
Self::InvalidBlobSize {
|
||||||
expected_size,
|
expected_size,
|
||||||
blob_size,
|
blob_size,
|
||||||
} => {
|
} => {
|
||||||
@ -61,14 +61,14 @@ impl fmt::Display for FromSqlError {
|
|||||||
"Cannot read {expected_size} byte value out of {blob_size} byte blob"
|
"Cannot read {expected_size} byte value out of {blob_size} byte blob"
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
FromSqlError::Other(ref err) => err.fmt(f),
|
Self::Other(ref err) => err.fmt(f),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Error for FromSqlError {
|
impl Error for FromSqlError {
|
||||||
fn source(&self) -> Option<&(dyn Error + 'static)> {
|
fn source(&self) -> Option<&(dyn Error + 'static)> {
|
||||||
if let FromSqlError::Other(ref err) = self {
|
if let Self::Other(ref err) = self {
|
||||||
Some(&**err)
|
Some(&**err)
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
@ -144,8 +144,8 @@ impl FromSql for f32 {
|
|||||||
#[inline]
|
#[inline]
|
||||||
fn column_result(value: ValueRef<'_>) -> FromSqlResult<Self> {
|
fn column_result(value: ValueRef<'_>) -> FromSqlResult<Self> {
|
||||||
match value {
|
match value {
|
||||||
ValueRef::Integer(i) => Ok(i as f32),
|
ValueRef::Integer(i) => Ok(i as Self),
|
||||||
ValueRef::Real(f) => Ok(f as f32),
|
ValueRef::Real(f) => Ok(f as Self),
|
||||||
_ => Err(FromSqlError::InvalidType),
|
_ => Err(FromSqlError::InvalidType),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -155,7 +155,7 @@ impl FromSql for f64 {
|
|||||||
#[inline]
|
#[inline]
|
||||||
fn column_result(value: ValueRef<'_>) -> FromSqlResult<Self> {
|
fn column_result(value: ValueRef<'_>) -> FromSqlResult<Self> {
|
||||||
match value {
|
match value {
|
||||||
ValueRef::Integer(i) => Ok(i as f64),
|
ValueRef::Integer(i) => Ok(i as Self),
|
||||||
ValueRef::Real(f) => Ok(f),
|
ValueRef::Real(f) => Ok(f),
|
||||||
_ => Err(FromSqlError::InvalidType),
|
_ => Err(FromSqlError::InvalidType),
|
||||||
}
|
}
|
||||||
@ -221,7 +221,7 @@ impl FromSql for i128 {
|
|||||||
#[inline]
|
#[inline]
|
||||||
fn column_result(value: ValueRef<'_>) -> FromSqlResult<Self> {
|
fn column_result(value: ValueRef<'_>) -> FromSqlResult<Self> {
|
||||||
let bytes = <[u8; 16]>::column_result(value)?;
|
let bytes = <[u8; 16]>::column_result(value)?;
|
||||||
Ok(i128::from_be_bytes(bytes) ^ (1_i128 << 127))
|
Ok(Self::from_be_bytes(bytes) ^ (1_i128 << 127))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -231,7 +231,7 @@ impl FromSql for uuid::Uuid {
|
|||||||
#[inline]
|
#[inline]
|
||||||
fn column_result(value: ValueRef<'_>) -> FromSqlResult<Self> {
|
fn column_result(value: ValueRef<'_>) -> FromSqlResult<Self> {
|
||||||
let bytes = <[u8; 16]>::column_result(value)?;
|
let bytes = <[u8; 16]>::column_result(value)?;
|
||||||
Ok(uuid::Uuid::from_u128(u128::from_be_bytes(bytes)))
|
Ok(Self::from_u128(u128::from_be_bytes(bytes)))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -19,7 +19,7 @@ impl ToSql for Date {
|
|||||||
impl FromSql for Date {
|
impl FromSql for Date {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn column_result(value: ValueRef<'_>) -> FromSqlResult<Self> {
|
fn column_result(value: ValueRef<'_>) -> FromSqlResult<Self> {
|
||||||
value.as_str().and_then(|s| match Date::from_str(s) {
|
value.as_str().and_then(|s| match Self::from_str(s) {
|
||||||
Ok(d) => Ok(d),
|
Ok(d) => Ok(d),
|
||||||
Err(err) => Err(FromSqlError::Other(Box::new(err))),
|
Err(err) => Err(FromSqlError::Other(Box::new(err))),
|
||||||
})
|
})
|
||||||
@ -37,7 +37,7 @@ impl ToSql for Time {
|
|||||||
/// "HH:MM:SS.SSS" => time.
|
/// "HH:MM:SS.SSS" => time.
|
||||||
impl FromSql for Time {
|
impl FromSql for Time {
|
||||||
fn column_result(value: ValueRef<'_>) -> FromSqlResult<Self> {
|
fn column_result(value: ValueRef<'_>) -> FromSqlResult<Self> {
|
||||||
value.as_str().and_then(|s| match Time::from_str(s) {
|
value.as_str().and_then(|s| match Self::from_str(s) {
|
||||||
Ok(t) => Ok(t),
|
Ok(t) => Ok(t),
|
||||||
Err(err) => Err(FromSqlError::Other(Box::new(err))),
|
Err(err) => Err(FromSqlError::Other(Box::new(err))),
|
||||||
})
|
})
|
||||||
@ -56,7 +56,7 @@ impl ToSql for DateTime {
|
|||||||
/// "YYYY-MM-DDTHH:MM:SS.SSS" => Gregorian datetime.
|
/// "YYYY-MM-DDTHH:MM:SS.SSS" => Gregorian datetime.
|
||||||
impl FromSql for DateTime {
|
impl FromSql for DateTime {
|
||||||
fn column_result(value: ValueRef<'_>) -> FromSqlResult<Self> {
|
fn column_result(value: ValueRef<'_>) -> FromSqlResult<Self> {
|
||||||
value.as_str().and_then(|s| match DateTime::from_str(s) {
|
value.as_str().and_then(|s| match Self::from_str(s) {
|
||||||
Ok(dt) => Ok(dt),
|
Ok(dt) => Ok(dt),
|
||||||
Err(err) => Err(FromSqlError::Other(Box::new(err))),
|
Err(err) => Err(FromSqlError::Other(Box::new(err))),
|
||||||
})
|
})
|
||||||
|
@ -131,11 +131,11 @@ pub enum Type {
|
|||||||
impl fmt::Display for Type {
|
impl fmt::Display for Type {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
match *self {
|
match *self {
|
||||||
Type::Null => f.pad("Null"),
|
Self::Null => f.pad("Null"),
|
||||||
Type::Integer => f.pad("Integer"),
|
Self::Integer => f.pad("Integer"),
|
||||||
Type::Real => f.pad("Real"),
|
Self::Real => f.pad("Real"),
|
||||||
Type::Text => f.pad("Text"),
|
Self::Text => f.pad("Text"),
|
||||||
Type::Blob => f.pad("Blob"),
|
Self::Blob => f.pad("Blob"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -18,9 +18,9 @@ impl ToSql for Value {
|
|||||||
#[inline]
|
#[inline]
|
||||||
fn to_sql(&self) -> Result<ToSqlOutput<'_>> {
|
fn to_sql(&self) -> Result<ToSqlOutput<'_>> {
|
||||||
match self {
|
match self {
|
||||||
Value::Null => Ok(ToSqlOutput::Borrowed(ValueRef::Null)),
|
Self::Null => Ok(ToSqlOutput::Borrowed(ValueRef::Null)),
|
||||||
Value::Number(n) if n.is_i64() => Ok(ToSqlOutput::from(n.as_i64().unwrap())),
|
Self::Number(n) if n.is_i64() => Ok(ToSqlOutput::from(n.as_i64().unwrap())),
|
||||||
Value::Number(n) if n.is_f64() => Ok(ToSqlOutput::from(n.as_f64().unwrap())),
|
Self::Number(n) if n.is_f64() => Ok(ToSqlOutput::from(n.as_f64().unwrap())),
|
||||||
_ => serde_json::to_string(self)
|
_ => serde_json::to_string(self)
|
||||||
.map(ToSqlOutput::from)
|
.map(ToSqlOutput::from)
|
||||||
.map_err(|err| Error::ToSqlConversionFailure(err.into())),
|
.map_err(|err| Error::ToSqlConversionFailure(err.into())),
|
||||||
@ -47,14 +47,14 @@ impl FromSql for Value {
|
|||||||
match value {
|
match value {
|
||||||
ValueRef::Text(s) => serde_json::from_slice(s), // KO for b"text"
|
ValueRef::Text(s) => serde_json::from_slice(s), // KO for b"text"
|
||||||
ValueRef::Blob(b) => serde_json::from_slice(b),
|
ValueRef::Blob(b) => serde_json::from_slice(b),
|
||||||
ValueRef::Integer(i) => Ok(Value::Number(Number::from(i))),
|
ValueRef::Integer(i) => Ok(Self::Number(Number::from(i))),
|
||||||
ValueRef::Real(f) => {
|
ValueRef::Real(f) => {
|
||||||
match Number::from_f64(f) {
|
match Number::from_f64(f) {
|
||||||
Some(n) => Ok(Value::Number(n)),
|
Some(n) => Ok(Self::Number(n)),
|
||||||
_ => return Err(FromSqlError::InvalidType), // FIXME
|
_ => return Err(FromSqlError::InvalidType), // FIXME
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ValueRef::Null => Ok(Value::Null),
|
ValueRef::Null => Ok(Self::Null),
|
||||||
}
|
}
|
||||||
.map_err(|err| FromSqlError::Other(Box::new(err)))
|
.map_err(|err| FromSqlError::Other(Box::new(err)))
|
||||||
}
|
}
|
||||||
|
@ -69,12 +69,12 @@ impl FromSql for OffsetDateTime {
|
|||||||
value.as_str().and_then(|s| {
|
value.as_str().and_then(|s| {
|
||||||
if let Some(b' ') = s.as_bytes().get(23) {
|
if let Some(b' ') = s.as_bytes().get(23) {
|
||||||
// legacy
|
// legacy
|
||||||
return OffsetDateTime::parse(s, &LEGACY_DATE_TIME_FORMAT)
|
return Self::parse(s, &LEGACY_DATE_TIME_FORMAT)
|
||||||
.map_err(|err| FromSqlError::Other(Box::new(err)));
|
.map_err(|err| FromSqlError::Other(Box::new(err)));
|
||||||
}
|
}
|
||||||
if s[8..].contains('+') || s[8..].contains('-') {
|
if s[8..].contains('+') || s[8..].contains('-') {
|
||||||
// Formats 2-7 with timezone
|
// Formats 2-7 with timezone
|
||||||
return OffsetDateTime::parse(s, &OFFSET_DATE_TIME_FORMAT)
|
return Self::parse(s, &OFFSET_DATE_TIME_FORMAT)
|
||||||
.map_err(|err| FromSqlError::Other(Box::new(err)));
|
.map_err(|err| FromSqlError::Other(Box::new(err)));
|
||||||
}
|
}
|
||||||
// Formats 2-7 without timezone
|
// Formats 2-7 without timezone
|
||||||
@ -101,7 +101,7 @@ impl FromSql for Date {
|
|||||||
#[inline]
|
#[inline]
|
||||||
fn column_result(value: ValueRef<'_>) -> FromSqlResult<Self> {
|
fn column_result(value: ValueRef<'_>) -> FromSqlResult<Self> {
|
||||||
value.as_str().and_then(|s| {
|
value.as_str().and_then(|s| {
|
||||||
Date::parse(s, &DATE_FORMAT).map_err(|err| FromSqlError::Other(err.into()))
|
Self::parse(s, &DATE_FORMAT).map_err(|err| FromSqlError::Other(err.into()))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -122,7 +122,7 @@ impl FromSql for Time {
|
|||||||
#[inline]
|
#[inline]
|
||||||
fn column_result(value: ValueRef<'_>) -> FromSqlResult<Self> {
|
fn column_result(value: ValueRef<'_>) -> FromSqlResult<Self> {
|
||||||
value.as_str().and_then(|s| {
|
value.as_str().and_then(|s| {
|
||||||
Time::parse(s, &TIME_FORMAT).map_err(|err| FromSqlError::Other(err.into()))
|
Self::parse(s, &TIME_FORMAT).map_err(|err| FromSqlError::Other(err.into()))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -149,7 +149,7 @@ impl FromSql for PrimitiveDateTime {
|
|||||||
#[inline]
|
#[inline]
|
||||||
fn column_result(value: ValueRef<'_>) -> FromSqlResult<Self> {
|
fn column_result(value: ValueRef<'_>) -> FromSqlResult<Self> {
|
||||||
value.as_str().and_then(|s| {
|
value.as_str().and_then(|s| {
|
||||||
PrimitiveDateTime::parse(s, &PRIMITIVE_DATE_TIME_FORMAT)
|
Self::parse(s, &PRIMITIVE_DATE_TIME_FORMAT)
|
||||||
.map_err(|err| FromSqlError::Other(err.into()))
|
.map_err(|err| FromSqlError::Other(err.into()))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -18,7 +18,7 @@ impl FromSql for Url {
|
|||||||
match value {
|
match value {
|
||||||
ValueRef::Text(s) => {
|
ValueRef::Text(s) => {
|
||||||
let s = std::str::from_utf8(s).map_err(|e| FromSqlError::Other(Box::new(e)))?;
|
let s = std::str::from_utf8(s).map_err(|e| FromSqlError::Other(Box::new(e)))?;
|
||||||
Url::parse(s).map_err(|e| FromSqlError::Other(Box::new(e)))
|
Self::parse(s).map_err(|e| FromSqlError::Other(Box::new(e)))
|
||||||
}
|
}
|
||||||
_ => Err(FromSqlError::InvalidType),
|
_ => Err(FromSqlError::InvalidType),
|
||||||
}
|
}
|
||||||
|
@ -21,22 +21,22 @@ pub enum Value {
|
|||||||
|
|
||||||
impl From<Null> for Value {
|
impl From<Null> for Value {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn from(_: Null) -> Value {
|
fn from(_: Null) -> Self {
|
||||||
Value::Null
|
Self::Null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<bool> for Value {
|
impl From<bool> for Value {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn from(i: bool) -> Value {
|
fn from(i: bool) -> Self {
|
||||||
Value::Integer(i as i64)
|
Self::Integer(i as i64)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<isize> for Value {
|
impl From<isize> for Value {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn from(i: isize) -> Value {
|
fn from(i: isize) -> Self {
|
||||||
Value::Integer(i as i64)
|
Self::Integer(i as i64)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -44,10 +44,10 @@ impl From<isize> for Value {
|
|||||||
#[cfg_attr(docsrs, doc(cfg(feature = "i128_blob")))]
|
#[cfg_attr(docsrs, doc(cfg(feature = "i128_blob")))]
|
||||||
impl From<i128> for Value {
|
impl From<i128> for Value {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn from(i: i128) -> Value {
|
fn from(i: i128) -> Self {
|
||||||
// We store these biased (e.g. with the most significant bit flipped)
|
// We store these biased (e.g. with the most significant bit flipped)
|
||||||
// so that comparisons with negative numbers work properly.
|
// so that comparisons with negative numbers work properly.
|
||||||
Value::Blob(i128::to_be_bytes(i ^ (1_i128 << 127)).to_vec())
|
Self::Blob(i128::to_be_bytes(i ^ (1_i128 << 127)).to_vec())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -55,8 +55,8 @@ impl From<i128> for Value {
|
|||||||
#[cfg_attr(docsrs, doc(cfg(feature = "uuid")))]
|
#[cfg_attr(docsrs, doc(cfg(feature = "uuid")))]
|
||||||
impl From<uuid::Uuid> for Value {
|
impl From<uuid::Uuid> for Value {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn from(id: uuid::Uuid) -> Value {
|
fn from(id: uuid::Uuid) -> Self {
|
||||||
Value::Blob(id.as_bytes().to_vec())
|
Self::Blob(id.as_bytes().to_vec())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -80,48 +80,48 @@ from_i64!(u32);
|
|||||||
|
|
||||||
impl From<i64> for Value {
|
impl From<i64> for Value {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn from(i: i64) -> Value {
|
fn from(i: i64) -> Self {
|
||||||
Value::Integer(i)
|
Self::Integer(i)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<f32> for Value {
|
impl From<f32> for Value {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn from(f: f32) -> Value {
|
fn from(f: f32) -> Self {
|
||||||
Value::Real(f.into())
|
Self::Real(f.into())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<f64> for Value {
|
impl From<f64> for Value {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn from(f: f64) -> Value {
|
fn from(f: f64) -> Self {
|
||||||
Value::Real(f)
|
Self::Real(f)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<String> for Value {
|
impl From<String> for Value {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn from(s: String) -> Value {
|
fn from(s: String) -> Self {
|
||||||
Value::Text(s)
|
Self::Text(s)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<Vec<u8>> for Value {
|
impl From<Vec<u8>> for Value {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn from(v: Vec<u8>) -> Value {
|
fn from(v: Vec<u8>) -> Self {
|
||||||
Value::Blob(v)
|
Self::Blob(v)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T> From<Option<T>> for Value
|
impl<T> From<Option<T>> for Value
|
||||||
where
|
where
|
||||||
T: Into<Value>,
|
T: Into<Self>,
|
||||||
{
|
{
|
||||||
#[inline]
|
#[inline]
|
||||||
fn from(v: Option<T>) -> Value {
|
fn from(v: Option<T>) -> Self {
|
||||||
match v {
|
match v {
|
||||||
Some(x) => x.into(),
|
Some(x) => x.into(),
|
||||||
None => Value::Null,
|
None => Self::Null,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -132,11 +132,11 @@ impl Value {
|
|||||||
#[must_use]
|
#[must_use]
|
||||||
pub fn data_type(&self) -> Type {
|
pub fn data_type(&self) -> Type {
|
||||||
match *self {
|
match *self {
|
||||||
Value::Null => Type::Null,
|
Self::Null => Type::Null,
|
||||||
Value::Integer(_) => Type::Integer,
|
Self::Integer(_) => Type::Integer,
|
||||||
Value::Real(_) => Type::Real,
|
Self::Real(_) => Type::Real,
|
||||||
Value::Text(_) => Type::Text,
|
Self::Text(_) => Type::Text,
|
||||||
Value::Blob(_) => Type::Blob,
|
Self::Blob(_) => Type::Blob,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -153,16 +153,16 @@ impl<'a> ValueRef<'a> {
|
|||||||
impl From<ValueRef<'_>> for Value {
|
impl From<ValueRef<'_>> for Value {
|
||||||
#[inline]
|
#[inline]
|
||||||
#[track_caller]
|
#[track_caller]
|
||||||
fn from(borrowed: ValueRef<'_>) -> Value {
|
fn from(borrowed: ValueRef<'_>) -> Self {
|
||||||
match borrowed {
|
match borrowed {
|
||||||
ValueRef::Null => Value::Null,
|
ValueRef::Null => Self::Null,
|
||||||
ValueRef::Integer(i) => Value::Integer(i),
|
ValueRef::Integer(i) => Self::Integer(i),
|
||||||
ValueRef::Real(r) => Value::Real(r),
|
ValueRef::Real(r) => Self::Real(r),
|
||||||
ValueRef::Text(s) => {
|
ValueRef::Text(s) => {
|
||||||
let s = std::str::from_utf8(s).expect("invalid UTF-8");
|
let s = std::str::from_utf8(s).expect("invalid UTF-8");
|
||||||
Value::Text(s.to_string())
|
Self::Text(s.to_string())
|
||||||
}
|
}
|
||||||
ValueRef::Blob(b) => Value::Blob(b.to_vec()),
|
ValueRef::Blob(b) => Self::Blob(b.to_vec()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -183,7 +183,7 @@ impl<'a> From<&'a [u8]> for ValueRef<'a> {
|
|||||||
|
|
||||||
impl<'a> From<&'a Value> for ValueRef<'a> {
|
impl<'a> From<&'a Value> for ValueRef<'a> {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn from(value: &'a Value) -> ValueRef<'a> {
|
fn from(value: &'a Value) -> Self {
|
||||||
match *value {
|
match *value {
|
||||||
Value::Null => ValueRef::Null,
|
Value::Null => ValueRef::Null,
|
||||||
Value::Integer(i) => ValueRef::Integer(i),
|
Value::Integer(i) => ValueRef::Integer(i),
|
||||||
@ -196,10 +196,10 @@ impl<'a> From<&'a Value> for ValueRef<'a> {
|
|||||||
|
|
||||||
impl<'a, T> From<Option<T>> for ValueRef<'a>
|
impl<'a, T> From<Option<T>> for ValueRef<'a>
|
||||||
where
|
where
|
||||||
T: Into<ValueRef<'a>>,
|
T: Into<Self>,
|
||||||
{
|
{
|
||||||
#[inline]
|
#[inline]
|
||||||
fn from(s: Option<T>) -> ValueRef<'a> {
|
fn from(s: Option<T>) -> Self {
|
||||||
match s {
|
match s {
|
||||||
Some(x) => x.into(),
|
Some(x) => x.into(),
|
||||||
None => ValueRef::Null,
|
None => ValueRef::Null,
|
||||||
@ -214,7 +214,7 @@ where
|
|||||||
feature = "preupdate_hook"
|
feature = "preupdate_hook"
|
||||||
))]
|
))]
|
||||||
impl<'a> ValueRef<'a> {
|
impl<'a> ValueRef<'a> {
|
||||||
pub(crate) unsafe fn from_value(value: *mut crate::ffi::sqlite3_value) -> ValueRef<'a> {
|
pub(crate) unsafe fn from_value(value: *mut crate::ffi::sqlite3_value) -> Self {
|
||||||
use crate::ffi;
|
use crate::ffi;
|
||||||
use std::slice::from_raw_parts;
|
use std::slice::from_raw_parts;
|
||||||
|
|
||||||
|
@ -14,8 +14,8 @@ struct UnlockNotification {
|
|||||||
|
|
||||||
#[allow(clippy::mutex_atomic)]
|
#[allow(clippy::mutex_atomic)]
|
||||||
impl UnlockNotification {
|
impl UnlockNotification {
|
||||||
fn new() -> UnlockNotification {
|
fn new() -> Self {
|
||||||
UnlockNotification {
|
Self {
|
||||||
cond: Condvar::new(),
|
cond: Condvar::new(),
|
||||||
mutex: Mutex::new(false),
|
mutex: Mutex::new(false),
|
||||||
}
|
}
|
||||||
|
@ -81,8 +81,8 @@ unsafe impl<'vtab> VTab<'vtab> for ArrayTab {
|
|||||||
_: &mut VTabConnection,
|
_: &mut VTabConnection,
|
||||||
_aux: Option<&()>,
|
_aux: Option<&()>,
|
||||||
_args: &[&[u8]],
|
_args: &[&[u8]],
|
||||||
) -> Result<(String, ArrayTab)> {
|
) -> Result<(String, Self)> {
|
||||||
let vtab = ArrayTab {
|
let vtab = Self {
|
||||||
base: ffi::sqlite3_vtab::default(),
|
base: ffi::sqlite3_vtab::default(),
|
||||||
};
|
};
|
||||||
Ok(("CREATE TABLE x(value,pointer hidden)".to_owned(), vtab))
|
Ok(("CREATE TABLE x(value,pointer hidden)".to_owned(), vtab))
|
||||||
|
@ -91,12 +91,12 @@ unsafe impl<'vtab> VTab<'vtab> for CsvTab {
|
|||||||
db: &mut VTabConnection,
|
db: &mut VTabConnection,
|
||||||
_aux: Option<&()>,
|
_aux: Option<&()>,
|
||||||
args: &[&[u8]],
|
args: &[&[u8]],
|
||||||
) -> Result<(String, CsvTab)> {
|
) -> Result<(String, Self)> {
|
||||||
if args.len() < 4 {
|
if args.len() < 4 {
|
||||||
return Err(Error::ModuleError("no CSV file specified".to_owned()));
|
return Err(Error::ModuleError("no CSV file specified".to_owned()));
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut vtab = CsvTab {
|
let mut vtab = Self {
|
||||||
base: ffi::sqlite3_vtab::default(),
|
base: ffi::sqlite3_vtab::default(),
|
||||||
filename: "".to_owned(),
|
filename: "".to_owned(),
|
||||||
has_headers: false,
|
has_headers: false,
|
||||||
@ -148,7 +148,7 @@ unsafe impl<'vtab> VTab<'vtab> for CsvTab {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
"delimiter" => {
|
"delimiter" => {
|
||||||
if let Some(b) = CsvTab::parse_byte(value) {
|
if let Some(b) = Self::parse_byte(value) {
|
||||||
vtab.delimiter = b;
|
vtab.delimiter = b;
|
||||||
} else {
|
} else {
|
||||||
return Err(Error::ModuleError(format!(
|
return Err(Error::ModuleError(format!(
|
||||||
@ -157,7 +157,7 @@ unsafe impl<'vtab> VTab<'vtab> for CsvTab {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
"quote" => {
|
"quote" => {
|
||||||
if let Some(b) = CsvTab::parse_byte(value) {
|
if let Some(b) = Self::parse_byte(value) {
|
||||||
if b == b'0' {
|
if b == b'0' {
|
||||||
vtab.quote = 0;
|
vtab.quote = 0;
|
||||||
} else {
|
} else {
|
||||||
@ -335,8 +335,8 @@ unsafe impl VTabCursor for CsvTabCursor<'_> {
|
|||||||
|
|
||||||
impl From<csv::Error> for Error {
|
impl From<csv::Error> for Error {
|
||||||
#[cold]
|
#[cold]
|
||||||
fn from(err: csv::Error) -> Error {
|
fn from(err: csv::Error) -> Self {
|
||||||
Error::ModuleError(err.to_string())
|
Self::ModuleError(err.to_string())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -345,25 +345,25 @@ pub enum IndexConstraintOp {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl From<u8> for IndexConstraintOp {
|
impl From<u8> for IndexConstraintOp {
|
||||||
fn from(code: u8) -> IndexConstraintOp {
|
fn from(code: u8) -> Self {
|
||||||
match code {
|
match code {
|
||||||
2 => IndexConstraintOp::SQLITE_INDEX_CONSTRAINT_EQ,
|
2 => Self::SQLITE_INDEX_CONSTRAINT_EQ,
|
||||||
4 => IndexConstraintOp::SQLITE_INDEX_CONSTRAINT_GT,
|
4 => Self::SQLITE_INDEX_CONSTRAINT_GT,
|
||||||
8 => IndexConstraintOp::SQLITE_INDEX_CONSTRAINT_LE,
|
8 => Self::SQLITE_INDEX_CONSTRAINT_LE,
|
||||||
16 => IndexConstraintOp::SQLITE_INDEX_CONSTRAINT_LT,
|
16 => Self::SQLITE_INDEX_CONSTRAINT_LT,
|
||||||
32 => IndexConstraintOp::SQLITE_INDEX_CONSTRAINT_GE,
|
32 => Self::SQLITE_INDEX_CONSTRAINT_GE,
|
||||||
64 => IndexConstraintOp::SQLITE_INDEX_CONSTRAINT_MATCH,
|
64 => Self::SQLITE_INDEX_CONSTRAINT_MATCH,
|
||||||
65 => IndexConstraintOp::SQLITE_INDEX_CONSTRAINT_LIKE,
|
65 => Self::SQLITE_INDEX_CONSTRAINT_LIKE,
|
||||||
66 => IndexConstraintOp::SQLITE_INDEX_CONSTRAINT_GLOB,
|
66 => Self::SQLITE_INDEX_CONSTRAINT_GLOB,
|
||||||
67 => IndexConstraintOp::SQLITE_INDEX_CONSTRAINT_REGEXP,
|
67 => Self::SQLITE_INDEX_CONSTRAINT_REGEXP,
|
||||||
68 => IndexConstraintOp::SQLITE_INDEX_CONSTRAINT_NE,
|
68 => Self::SQLITE_INDEX_CONSTRAINT_NE,
|
||||||
69 => IndexConstraintOp::SQLITE_INDEX_CONSTRAINT_ISNOT,
|
69 => Self::SQLITE_INDEX_CONSTRAINT_ISNOT,
|
||||||
70 => IndexConstraintOp::SQLITE_INDEX_CONSTRAINT_ISNOTNULL,
|
70 => Self::SQLITE_INDEX_CONSTRAINT_ISNOTNULL,
|
||||||
71 => IndexConstraintOp::SQLITE_INDEX_CONSTRAINT_ISNULL,
|
71 => Self::SQLITE_INDEX_CONSTRAINT_ISNULL,
|
||||||
72 => IndexConstraintOp::SQLITE_INDEX_CONSTRAINT_IS,
|
72 => Self::SQLITE_INDEX_CONSTRAINT_IS,
|
||||||
73 => IndexConstraintOp::SQLITE_INDEX_CONSTRAINT_LIMIT,
|
73 => Self::SQLITE_INDEX_CONSTRAINT_LIMIT,
|
||||||
74 => IndexConstraintOp::SQLITE_INDEX_CONSTRAINT_OFFSET,
|
74 => Self::SQLITE_INDEX_CONSTRAINT_OFFSET,
|
||||||
v => IndexConstraintOp::SQLITE_INDEX_CONSTRAINT_FUNCTION(v),
|
v => Self::SQLITE_INDEX_CONSTRAINT_FUNCTION(v),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -60,8 +60,8 @@ unsafe impl<'vtab> VTab<'vtab> for SeriesTab {
|
|||||||
db: &mut VTabConnection,
|
db: &mut VTabConnection,
|
||||||
_aux: Option<&()>,
|
_aux: Option<&()>,
|
||||||
_args: &[&[u8]],
|
_args: &[&[u8]],
|
||||||
) -> Result<(String, SeriesTab)> {
|
) -> Result<(String, Self)> {
|
||||||
let vtab = SeriesTab {
|
let vtab = Self {
|
||||||
base: ffi::sqlite3_vtab::default(),
|
base: ffi::sqlite3_vtab::default(),
|
||||||
};
|
};
|
||||||
db.config(VTabConfig::Innocuous)?;
|
db.config(VTabConfig::Innocuous)?;
|
||||||
|
@ -36,7 +36,7 @@ impl VTabLog {
|
|||||||
_: Option<&()>,
|
_: Option<&()>,
|
||||||
args: &[&[u8]],
|
args: &[&[u8]],
|
||||||
is_create: bool,
|
is_create: bool,
|
||||||
) -> Result<(String, VTabLog)> {
|
) -> Result<(String, Self)> {
|
||||||
static N_INST: AtomicUsize = AtomicUsize::new(1);
|
static N_INST: AtomicUsize = AtomicUsize::new(1);
|
||||||
let i_inst = N_INST.fetch_add(1, Ordering::SeqCst);
|
let i_inst = N_INST.fetch_add(1, Ordering::SeqCst);
|
||||||
println!(
|
println!(
|
||||||
@ -80,7 +80,7 @@ impl VTabLog {
|
|||||||
if schema.is_none() {
|
if schema.is_none() {
|
||||||
return Err(Error::ModuleError("no schema defined".to_owned()));
|
return Err(Error::ModuleError("no schema defined".to_owned()));
|
||||||
}
|
}
|
||||||
let vtab = VTabLog {
|
let vtab = Self {
|
||||||
base: ffi::sqlite3_vtab::default(),
|
base: ffi::sqlite3_vtab::default(),
|
||||||
n_row: n_row.unwrap_or(10),
|
n_row: n_row.unwrap_or(10),
|
||||||
i_inst,
|
i_inst,
|
||||||
@ -105,7 +105,7 @@ unsafe impl<'vtab> VTab<'vtab> for VTabLog {
|
|||||||
aux: Option<&Self::Aux>,
|
aux: Option<&Self::Aux>,
|
||||||
args: &[&[u8]],
|
args: &[&[u8]],
|
||||||
) -> Result<(String, Self)> {
|
) -> Result<(String, Self)> {
|
||||||
VTabLog::connect_create(db, aux, args, false)
|
Self::connect_create(db, aux, args, false)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn best_index(&self, info: &mut IndexInfo) -> Result<()> {
|
fn best_index(&self, info: &mut IndexInfo) -> Result<()> {
|
||||||
@ -138,7 +138,7 @@ impl<'vtab> CreateVTab<'vtab> for VTabLog {
|
|||||||
aux: Option<&Self::Aux>,
|
aux: Option<&Self::Aux>,
|
||||||
args: &[&[u8]],
|
args: &[&[u8]],
|
||||||
) -> Result<(String, Self)> {
|
) -> Result<(String, Self)> {
|
||||||
VTabLog::connect_create(db, aux, args, true)
|
Self::connect_create(db, aux, args, true)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn destroy(&self) -> Result<()> {
|
fn destroy(&self) -> Result<()> {
|
||||||
|
@ -27,8 +27,8 @@ fn test_dummy_module() -> rusqlite::Result<()> {
|
|||||||
_: &mut VTabConnection,
|
_: &mut VTabConnection,
|
||||||
_aux: Option<&()>,
|
_aux: Option<&()>,
|
||||||
_args: &[&[u8]],
|
_args: &[&[u8]],
|
||||||
) -> Result<(String, DummyTab)> {
|
) -> Result<(String, Self)> {
|
||||||
let vtab = DummyTab {
|
let vtab = Self {
|
||||||
base: sqlite3_vtab::default(),
|
base: sqlite3_vtab::default(),
|
||||||
};
|
};
|
||||||
Ok(("CREATE TABLE x(value)".to_owned(), vtab))
|
Ok(("CREATE TABLE x(value)".to_owned(), vtab))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user