Merge pull request #1158 from nvzqz/sqlite-error

Add `Error` methods to get SQLite error values
This commit is contained in:
gwenn 2022-04-07 07:16:34 +02:00 committed by GitHub
commit f54e550b2b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -335,6 +335,24 @@ impl error::Error for Error {
}
}
impl Error {
/// Returns the underlying SQLite error if this is [`Error::SqliteFailure`].
#[inline]
pub fn sqlite_error(&self) -> Option<&ffi::Error> {
match self {
Self::SqliteFailure(error, _) => Some(error),
_ => None,
}
}
/// Returns the underlying SQLite error code if this is
/// [`Error::SqliteFailure`].
#[inline]
pub fn sqlite_error_code(&self) -> Option<ffi::ErrorCode> {
self.sqlite_error().map(|error| error.code)
}
}
// These are public but not re-exported by lib.rs, so only visible within crate.
#[cold]