mirror of
https://github.com/isar/rusqlite.git
synced 2025-09-15 12:12:18 +08:00
Add Connection::extension_init2
This commit is contained in:
18
src/error.rs
18
src/error.rs
@@ -141,6 +141,10 @@ pub enum Error {
|
||||
/// byte offset of the start of invalid token
|
||||
offset: c_int,
|
||||
},
|
||||
/// Loadable extension initialization error
|
||||
#[cfg(feature = "loadable_extension")]
|
||||
#[cfg_attr(docsrs, doc(cfg(feature = "loadable_extension")))]
|
||||
InitError(ffi::InitError),
|
||||
}
|
||||
|
||||
impl PartialEq for Error {
|
||||
@@ -200,6 +204,8 @@ impl PartialEq for Error {
|
||||
offset: o2,
|
||||
},
|
||||
) => e1 == e2 && m1 == m2 && s1 == s2 && o1 == o2,
|
||||
#[cfg(feature = "loadable_extension")]
|
||||
(Error::InitError(e1), Error::InitError(e2)) => e1 == e2,
|
||||
(..) => false,
|
||||
}
|
||||
}
|
||||
@@ -241,6 +247,14 @@ impl From<FromSqlError> for Error {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "loadable_extension")]
|
||||
impl From<ffi::InitError> for Error {
|
||||
#[cold]
|
||||
fn from(err: ffi::InitError) -> Error {
|
||||
Error::InitError(err)
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Display for Error {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
match *self {
|
||||
@@ -311,6 +325,8 @@ impl fmt::Display for Error {
|
||||
ref sql,
|
||||
..
|
||||
} => write!(f, "{msg} in {sql} at offset {offset}"),
|
||||
#[cfg(feature = "loadable_extension")]
|
||||
Error::InitError(ref err) => err.fmt(f),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -360,6 +376,8 @@ impl error::Error for Error {
|
||||
Error::BlobSizeError => None,
|
||||
#[cfg(feature = "modern_sqlite")]
|
||||
Error::SqlInputError { ref error, .. } => Some(error),
|
||||
#[cfg(feature = "loadable_extension")]
|
||||
Error::InitError(ref err) => Some(err),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
11
src/lib.rs
11
src/lib.rs
@@ -898,6 +898,17 @@ impl Connection {
|
||||
})
|
||||
}
|
||||
|
||||
/// Like SQLITE_EXTENSION_INIT2 macro
|
||||
#[cfg(feature = "loadable_extension")]
|
||||
#[cfg_attr(docsrs, doc(cfg(feature = "loadable_extension")))]
|
||||
pub unsafe fn extension_init2(
|
||||
db: *mut ffi::sqlite3,
|
||||
p_api: *mut ffi::sqlite3_api_routines,
|
||||
) -> Result<Connection> {
|
||||
ffi::rusqlite_extension_init2(p_api)?;
|
||||
Connection::from_handle(db)
|
||||
}
|
||||
|
||||
/// Create a `Connection` from a raw owned handle.
|
||||
///
|
||||
/// The returned connection will attempt to close the inner connection
|
||||
|
Reference in New Issue
Block a user