mirror of
https://github.com/isar/rusqlite.git
synced 2024-11-25 02:21:37 +08:00
Fix some clipy warnings
This commit is contained in:
parent
714ce2e171
commit
e2e47de863
@ -90,6 +90,8 @@ impl Statement<'_> {
|
|||||||
/// Returns an `Error::InvalidColumnIndex` if `idx` is outside the valid
|
/// Returns an `Error::InvalidColumnIndex` if `idx` is outside the valid
|
||||||
/// column range for this row.
|
/// column range for this row.
|
||||||
///
|
///
|
||||||
|
/// # Panics
|
||||||
|
///
|
||||||
/// Panics when column name is not valid UTF-8.
|
/// Panics when column name is not valid UTF-8.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn column_name(&self, col: usize) -> Result<&str> {
|
pub fn column_name(&self, col: usize) -> Result<&str> {
|
||||||
|
@ -367,6 +367,7 @@ impl error::Error for Error {
|
|||||||
impl Error {
|
impl Error {
|
||||||
/// Returns the underlying SQLite error if this is [`Error::SqliteFailure`].
|
/// Returns the underlying SQLite error if this is [`Error::SqliteFailure`].
|
||||||
#[inline]
|
#[inline]
|
||||||
|
#[must_use]
|
||||||
pub fn sqlite_error(&self) -> Option<&ffi::Error> {
|
pub fn sqlite_error(&self) -> Option<&ffi::Error> {
|
||||||
match self {
|
match self {
|
||||||
Self::SqliteFailure(error, _) => Some(error),
|
Self::SqliteFailure(error, _) => Some(error),
|
||||||
@ -377,6 +378,7 @@ impl Error {
|
|||||||
/// Returns the underlying SQLite error code if this is
|
/// Returns the underlying SQLite error code if this is
|
||||||
/// [`Error::SqliteFailure`].
|
/// [`Error::SqliteFailure`].
|
||||||
#[inline]
|
#[inline]
|
||||||
|
#[must_use]
|
||||||
pub fn sqlite_error_code(&self) -> Option<ffi::ErrorCode> {
|
pub fn sqlite_error_code(&self) -> Option<ffi::ErrorCode> {
|
||||||
self.sqlite_error().map(|error| error.code)
|
self.sqlite_error().map(|error| error.code)
|
||||||
}
|
}
|
||||||
@ -439,10 +441,7 @@ pub fn check(code: c_int) -> Result<()> {
|
|||||||
/// Transform Rust error to SQLite error (message and code).
|
/// Transform Rust error to SQLite error (message and code).
|
||||||
/// # Safety
|
/// # Safety
|
||||||
/// This function is unsafe because it uses raw pointer
|
/// This function is unsafe because it uses raw pointer
|
||||||
pub unsafe fn to_sqlite_error(
|
pub unsafe fn to_sqlite_error(e: &Error, err_msg: *mut *mut std::os::raw::c_char) -> c_int {
|
||||||
e: &Error,
|
|
||||||
err_msg: *mut *mut std::os::raw::c_char,
|
|
||||||
) -> std::os::raw::c_int {
|
|
||||||
use crate::util::alloc;
|
use crate::util::alloc;
|
||||||
match e {
|
match e {
|
||||||
Error::SqliteFailure(err, s) => {
|
Error::SqliteFailure(err, s) => {
|
||||||
|
@ -568,7 +568,7 @@ impl Connection {
|
|||||||
#[inline]
|
#[inline]
|
||||||
pub fn execute<P: Params>(&self, sql: &str, params: P) -> Result<usize> {
|
pub fn execute<P: Params>(&self, sql: &str, params: P) -> Result<usize> {
|
||||||
self.prepare(sql)
|
self.prepare(sql)
|
||||||
.and_then(|mut stmt| stmt.check_no_tail().and_then(|_| stmt.execute(params)))
|
.and_then(|mut stmt| stmt.check_no_tail().and_then(|()| stmt.execute(params)))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the path to the database file, if one exists and is known.
|
/// Returns the path to the database file, if one exists and is known.
|
||||||
@ -651,7 +651,7 @@ impl Connection {
|
|||||||
|
|
||||||
// https://sqlite.org/tclsqlite.html#onecolumn
|
// https://sqlite.org/tclsqlite.html#onecolumn
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
pub(crate) fn one_column<T: crate::types::FromSql>(&self, sql: &str) -> Result<T> {
|
pub(crate) fn one_column<T: types::FromSql>(&self, sql: &str) -> Result<T> {
|
||||||
self.query_row(sql, [], |r| r.get(0))
|
self.query_row(sql, [], |r| r.get(0))
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -912,7 +912,7 @@ impl Connection {
|
|||||||
/// This function is unsafe because improper use may impact the Connection.
|
/// This function is unsafe because improper use may impact the Connection.
|
||||||
/// In particular, it should only be called on connections created
|
/// In particular, it should only be called on connections created
|
||||||
/// 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<Connection> {
|
||||||
let db = InnerConnection::new(db, true);
|
let db = InnerConnection::new(db, true);
|
||||||
|
@ -384,7 +384,6 @@ mod test {
|
|||||||
let mut rows = table_info.query(["sqlite_master"])?;
|
let mut rows = table_info.query(["sqlite_master"])?;
|
||||||
|
|
||||||
while let Some(row) = rows.next()? {
|
while let Some(row) = rows.next()? {
|
||||||
let row = row;
|
|
||||||
let column: String = row.get(1)?;
|
let column: String = row.get(1)?;
|
||||||
columns.push(column);
|
columns.push(column);
|
||||||
}
|
}
|
||||||
|
@ -29,8 +29,8 @@ impl<'stmt> Rows<'stmt> {
|
|||||||
/// This interface is not compatible with Rust's `Iterator` trait, because
|
/// This interface is not compatible with Rust's `Iterator` trait, because
|
||||||
/// the lifetime of the returned row is tied to the lifetime of `self`.
|
/// the lifetime of the returned row is tied to the lifetime of `self`.
|
||||||
/// This is a fallible "streaming iterator". For a more natural interface,
|
/// This is a fallible "streaming iterator". For a more natural interface,
|
||||||
/// consider using [`query_map`](crate::Statement::query_map) or
|
/// consider using [`query_map`](Statement::query_map) or
|
||||||
/// [`query_and_then`](crate::Statement::query_and_then) instead, which
|
/// [`query_and_then`](Statement::query_and_then) instead, which
|
||||||
/// return types that implement `Iterator`.
|
/// return types that implement `Iterator`.
|
||||||
#[allow(clippy::should_implement_trait)] // cannot implement Iterator
|
#[allow(clippy::should_implement_trait)] // cannot implement Iterator
|
||||||
#[inline]
|
#[inline]
|
||||||
@ -247,7 +247,7 @@ pub struct Row<'stmt> {
|
|||||||
impl<'stmt> Row<'stmt> {
|
impl<'stmt> Row<'stmt> {
|
||||||
/// Get the value of a particular column of the result row.
|
/// Get the value of a particular column of the result row.
|
||||||
///
|
///
|
||||||
/// ## Failure
|
/// # Panics
|
||||||
///
|
///
|
||||||
/// Panics if calling [`row.get(idx)`](Row::get) would return an error,
|
/// Panics if calling [`row.get(idx)`](Row::get) would return an error,
|
||||||
/// including:
|
/// including:
|
||||||
@ -330,7 +330,7 @@ impl<'stmt> Row<'stmt> {
|
|||||||
/// it can be difficult to use, and most callers will be better served by
|
/// it can be difficult to use, and most callers will be better served by
|
||||||
/// [`get`](Row::get) or [`get_unwrap`](Row::get_unwrap).
|
/// [`get`](Row::get) or [`get_unwrap`](Row::get_unwrap).
|
||||||
///
|
///
|
||||||
/// ## Failure
|
/// # Panics
|
||||||
///
|
///
|
||||||
/// Panics if calling [`row.get_ref(idx)`](Row::get_ref) would return an
|
/// Panics if calling [`row.get_ref(idx)`](Row::get_ref) would return an
|
||||||
/// error, including:
|
/// error, including:
|
||||||
|
@ -22,8 +22,9 @@ pub struct OwnedData {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl OwnedData {
|
impl OwnedData {
|
||||||
/// SAFETY: Caller must be certain that `ptr` is allocated by
|
/// # Safety
|
||||||
/// `sqlite3_malloc`.
|
///
|
||||||
|
/// Caller must be certain that `ptr` is allocated by `sqlite3_malloc`.
|
||||||
pub unsafe fn from_raw_nonnull(ptr: NonNull<u8>, sz: usize) -> Self {
|
pub unsafe fn from_raw_nonnull(ptr: NonNull<u8>, sz: usize) -> Self {
|
||||||
Self { ptr, sz }
|
Self { ptr, sz }
|
||||||
}
|
}
|
||||||
@ -65,7 +66,7 @@ impl<'conn> Deref for Data<'conn> {
|
|||||||
|
|
||||||
impl Connection {
|
impl Connection {
|
||||||
/// Serialize a database.
|
/// Serialize a database.
|
||||||
pub fn serialize<'conn>(&'conn self, schema: DatabaseName<'_>) -> Result<Data<'conn>> {
|
pub fn serialize(&self, schema: DatabaseName) -> Result<Data> {
|
||||||
let schema = schema.as_cstring()?;
|
let schema = schema.as_cstring()?;
|
||||||
let mut sz = 0;
|
let mut sz = 0;
|
||||||
let mut ptr: *mut u8 = unsafe {
|
let mut ptr: *mut u8 = unsafe {
|
||||||
|
@ -405,7 +405,7 @@ impl Drop for ChangesetIter<'_> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// An item passed to a conflict-handler by
|
/// An item passed to a conflict-handler by
|
||||||
/// [`Connection::apply`](crate::Connection::apply), or an item generated by
|
/// [`Connection::apply`](Connection::apply), or an item generated by
|
||||||
/// [`ChangesetIter::next`](ChangesetIter::next).
|
/// [`ChangesetIter::next`](ChangesetIter::next).
|
||||||
// TODO enum ? Delete, Insert, Update, ...
|
// TODO enum ? Delete, Insert, Update, ...
|
||||||
pub struct ChangesetItem {
|
pub struct ChangesetItem {
|
||||||
|
@ -435,6 +435,10 @@ impl Statement<'_> {
|
|||||||
///
|
///
|
||||||
/// Will return `None` if the column index is out of bounds or if the
|
/// Will return `None` if the column index is out of bounds or if the
|
||||||
/// parameter is positional.
|
/// parameter is positional.
|
||||||
|
///
|
||||||
|
/// # Panics
|
||||||
|
///
|
||||||
|
/// Panics when parameter name is not valid UTF-8.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn parameter_name(&self, index: usize) -> Option<&'_ str> {
|
pub fn parameter_name(&self, index: usize) -> Option<&'_ str> {
|
||||||
self.stmt.bind_parameter_name(index as i32).map(|name| {
|
self.stmt.bind_parameter_name(index as i32).map(|name| {
|
||||||
@ -450,7 +454,7 @@ impl Statement<'_> {
|
|||||||
{
|
{
|
||||||
let expected = self.stmt.bind_parameter_count();
|
let expected = self.stmt.bind_parameter_count();
|
||||||
let mut index = 0;
|
let mut index = 0;
|
||||||
for p in params.into_iter() {
|
for p in params {
|
||||||
index += 1; // The leftmost SQL parameter has an index of 1.
|
index += 1; // The leftmost SQL parameter has an index of 1.
|
||||||
if index > expected {
|
if index > expected {
|
||||||
break;
|
break;
|
||||||
@ -744,7 +748,7 @@ impl Statement<'_> {
|
|||||||
|
|
||||||
/// Reset all bindings
|
/// Reset all bindings
|
||||||
pub fn clear_bindings(&mut self) {
|
pub fn clear_bindings(&mut self) {
|
||||||
self.stmt.clear_bindings()
|
self.stmt.clear_bindings();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -122,7 +122,7 @@ impl Transaction<'_> {
|
|||||||
TransactionBehavior::Immediate => "BEGIN IMMEDIATE",
|
TransactionBehavior::Immediate => "BEGIN IMMEDIATE",
|
||||||
TransactionBehavior::Exclusive => "BEGIN EXCLUSIVE",
|
TransactionBehavior::Exclusive => "BEGIN EXCLUSIVE",
|
||||||
};
|
};
|
||||||
conn.execute_batch(query).map(move |_| Transaction {
|
conn.execute_batch(query).map(move |()| Transaction {
|
||||||
conn,
|
conn,
|
||||||
drop_behavior: DropBehavior::Rollback,
|
drop_behavior: DropBehavior::Rollback,
|
||||||
})
|
})
|
||||||
@ -251,7 +251,7 @@ impl Savepoint<'_> {
|
|||||||
fn with_name_<T: Into<String>>(conn: &Connection, name: T) -> Result<Savepoint<'_>> {
|
fn with_name_<T: Into<String>>(conn: &Connection, name: T) -> Result<Savepoint<'_>> {
|
||||||
let name = name.into();
|
let name = name.into();
|
||||||
conn.execute_batch(&format!("SAVEPOINT {name}"))
|
conn.execute_batch(&format!("SAVEPOINT {name}"))
|
||||||
.map(|_| Savepoint {
|
.map(|()| Savepoint {
|
||||||
conn,
|
conn,
|
||||||
name,
|
name,
|
||||||
drop_behavior: DropBehavior::Rollback,
|
drop_behavior: DropBehavior::Rollback,
|
||||||
@ -346,8 +346,8 @@ impl Savepoint<'_> {
|
|||||||
match self.drop_behavior() {
|
match self.drop_behavior() {
|
||||||
DropBehavior::Commit => self
|
DropBehavior::Commit => self
|
||||||
.commit_()
|
.commit_()
|
||||||
.or_else(|_| self.rollback().and_then(|_| self.commit_())),
|
.or_else(|_| self.rollback().and_then(|()| self.commit_())),
|
||||||
DropBehavior::Rollback => self.rollback().and_then(|_| self.commit_()),
|
DropBehavior::Rollback => self.rollback().and_then(|()| self.commit_()),
|
||||||
DropBehavior::Ignore => Ok(()),
|
DropBehavior::Ignore => Ok(()),
|
||||||
DropBehavior::Panic => panic!("Savepoint dropped unexpectedly."),
|
DropBehavior::Panic => panic!("Savepoint dropped unexpectedly."),
|
||||||
}
|
}
|
||||||
@ -471,8 +471,7 @@ impl Connection {
|
|||||||
///
|
///
|
||||||
/// The savepoint defaults to rolling back when it is dropped. If you want
|
/// The savepoint defaults to rolling back when it is dropped. If you want
|
||||||
/// the savepoint to commit, you must call [`commit`](Savepoint::commit) or
|
/// the savepoint to commit, you must call [`commit`](Savepoint::commit) or
|
||||||
/// [`set_drop_behavior(DropBehavior::Commit)`](Savepoint::
|
/// [`set_drop_behavior(DropBehavior::Commit)`](Savepoint::set_drop_behavior).
|
||||||
/// set_drop_behavior).
|
|
||||||
///
|
///
|
||||||
/// ## Example
|
/// ## Example
|
||||||
///
|
///
|
||||||
|
@ -36,8 +36,7 @@ impl ValueRef<'_> {
|
|||||||
|
|
||||||
impl<'a> ValueRef<'a> {
|
impl<'a> ValueRef<'a> {
|
||||||
/// If `self` is case `Integer`, returns the integral value. Otherwise,
|
/// If `self` is case `Integer`, returns the integral value. Otherwise,
|
||||||
/// returns [`Err(Error::InvalidColumnType)`](crate::Error::
|
/// returns [`Err(Error::InvalidColumnType)`](crate::Error::InvalidColumnType).
|
||||||
/// InvalidColumnType).
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn as_i64(&self) -> FromSqlResult<i64> {
|
pub fn as_i64(&self) -> FromSqlResult<i64> {
|
||||||
match *self {
|
match *self {
|
||||||
@ -48,8 +47,7 @@ impl<'a> ValueRef<'a> {
|
|||||||
|
|
||||||
/// If `self` is case `Null` returns None.
|
/// If `self` is case `Null` returns None.
|
||||||
/// If `self` is case `Integer`, returns the integral value.
|
/// If `self` is case `Integer`, returns the integral value.
|
||||||
/// Otherwise returns [`Err(Error::InvalidColumnType)`](crate::Error::
|
/// Otherwise returns [`Err(Error::InvalidColumnType)`](crate::Error::InvalidColumnType).
|
||||||
/// InvalidColumnType).
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn as_i64_or_null(&self) -> FromSqlResult<Option<i64>> {
|
pub fn as_i64_or_null(&self) -> FromSqlResult<Option<i64>> {
|
||||||
match *self {
|
match *self {
|
||||||
@ -60,8 +58,7 @@ impl<'a> ValueRef<'a> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// If `self` is case `Real`, returns the floating point value. Otherwise,
|
/// If `self` is case `Real`, returns the floating point value. Otherwise,
|
||||||
/// returns [`Err(Error::InvalidColumnType)`](crate::Error::
|
/// returns [`Err(Error::InvalidColumnType)`](crate::Error::InvalidColumnType).
|
||||||
/// InvalidColumnType).
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn as_f64(&self) -> FromSqlResult<f64> {
|
pub fn as_f64(&self) -> FromSqlResult<f64> {
|
||||||
match *self {
|
match *self {
|
||||||
@ -72,8 +69,7 @@ impl<'a> ValueRef<'a> {
|
|||||||
|
|
||||||
/// If `self` is case `Null` returns None.
|
/// If `self` is case `Null` returns None.
|
||||||
/// If `self` is case `Real`, returns the floating point value.
|
/// If `self` is case `Real`, returns the floating point value.
|
||||||
/// Otherwise returns [`Err(Error::InvalidColumnType)`](crate::Error::
|
/// Otherwise returns [`Err(Error::InvalidColumnType)`](crate::Error::InvalidColumnType).
|
||||||
/// InvalidColumnType).
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn as_f64_or_null(&self) -> FromSqlResult<Option<f64>> {
|
pub fn as_f64_or_null(&self) -> FromSqlResult<Option<f64>> {
|
||||||
match *self {
|
match *self {
|
||||||
@ -97,8 +93,7 @@ impl<'a> ValueRef<'a> {
|
|||||||
|
|
||||||
/// If `self` is case `Null` returns None.
|
/// If `self` is case `Null` returns None.
|
||||||
/// If `self` is case `Text`, returns the string value.
|
/// If `self` is case `Text`, returns the string value.
|
||||||
/// Otherwise returns [`Err(Error::InvalidColumnType)`](crate::Error::
|
/// Otherwise returns [`Err(Error::InvalidColumnType)`](crate::Error::InvalidColumnType).
|
||||||
/// InvalidColumnType).
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn as_str_or_null(&self) -> FromSqlResult<Option<&'a str>> {
|
pub fn as_str_or_null(&self) -> FromSqlResult<Option<&'a str>> {
|
||||||
match *self {
|
match *self {
|
||||||
@ -122,8 +117,7 @@ impl<'a> ValueRef<'a> {
|
|||||||
|
|
||||||
/// If `self` is case `Null` returns None.
|
/// If `self` is case `Null` returns None.
|
||||||
/// If `self` is case `Blob`, returns the byte slice.
|
/// If `self` is case `Blob`, returns the byte slice.
|
||||||
/// Otherwise returns [`Err(Error::InvalidColumnType)`](crate::Error::
|
/// Otherwise returns [`Err(Error::InvalidColumnType)`](crate::Error::InvalidColumnType).
|
||||||
/// InvalidColumnType).
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn as_blob_or_null(&self) -> FromSqlResult<Option<&'a [u8]>> {
|
pub fn as_blob_or_null(&self) -> FromSqlResult<Option<&'a [u8]>> {
|
||||||
match *self {
|
match *self {
|
||||||
@ -133,7 +127,7 @@ impl<'a> ValueRef<'a> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the byte slice that makes up this ValueRef if it's either
|
/// Returns the byte slice that makes up this `ValueRef` if it's either
|
||||||
/// [`ValueRef::Blob`] or [`ValueRef::Text`].
|
/// [`ValueRef::Blob`] or [`ValueRef::Text`].
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn as_bytes(&self) -> FromSqlResult<&'a [u8]> {
|
pub fn as_bytes(&self) -> FromSqlResult<&'a [u8]> {
|
||||||
|
@ -14,6 +14,10 @@ pub fn version_number() -> i32 {
|
|||||||
/// Returns the SQLite version as a string; e.g., `"3.16.2"` for version 3.16.2.
|
/// Returns the SQLite version as a string; e.g., `"3.16.2"` for version 3.16.2.
|
||||||
///
|
///
|
||||||
/// See [`sqlite3_libversion()`](https://www.sqlite.org/c3ref/libversion.html).
|
/// See [`sqlite3_libversion()`](https://www.sqlite.org/c3ref/libversion.html).
|
||||||
|
///
|
||||||
|
/// # Panics
|
||||||
|
///
|
||||||
|
/// Panics when version is not valid UTF-8.
|
||||||
#[inline]
|
#[inline]
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub fn version() -> &'static str {
|
pub fn version() -> &'static str {
|
||||||
|
Loading…
Reference in New Issue
Block a user