mirror of
https://github.com/isar/rusqlite.git
synced 2024-11-22 16:29:20 +08:00
commit
5f16886b61
@ -31,7 +31,7 @@ fn main() -> Result<()> {
|
||||
name TEXT NOT NULL,
|
||||
data BLOB
|
||||
)",
|
||||
params![],
|
||||
[],
|
||||
)?;
|
||||
let me = Person {
|
||||
id: 0,
|
||||
@ -44,7 +44,7 @@ fn main() -> Result<()> {
|
||||
)?;
|
||||
|
||||
let mut stmt = conn.prepare("SELECT id, name, data FROM person")?;
|
||||
let person_iter = stmt.query_map(params![], |row| {
|
||||
let person_iter = stmt.query_map([], |row| {
|
||||
Ok(Person {
|
||||
id: row.get(0)?,
|
||||
name: row.get(1)?,
|
||||
|
@ -1,11 +1,11 @@
|
||||
//! `feature = "backup"` Online SQLite backup API.
|
||||
//!
|
||||
//! To create a `Backup`, you must have two distinct `Connection`s - one
|
||||
//! To create a [`Backup`], you must have two distinct [`Connection`]s - one
|
||||
//! for the source (which can be used while the backup is running) and one for
|
||||
//! the destination (which cannot). A `Backup` handle exposes three methods:
|
||||
//! `step` will attempt to back up a specified number of pages, `progress` gets
|
||||
//! the current progress of the backup as of the last call to `step`, and
|
||||
//! `run_to_completion` will attempt to back up the entire source database,
|
||||
//! the destination (which cannot). A [`Backup`] handle exposes three methods:
|
||||
//! [`step`](Backup::step) will attempt to back up a specified number of pages, [`progress`](Backup::progress) gets
|
||||
//! the current progress of the backup as of the last call to [`step`](Backup::step), and
|
||||
//! [`run_to_completion`](Backup::run_to_completion) will attempt to back up the entire source database,
|
||||
//! allowing you to specify how many pages are backed up at a time and how long
|
||||
//! the thread should sleep between chunks of pages.
|
||||
//!
|
||||
@ -130,7 +130,7 @@ impl Connection {
|
||||
}
|
||||
}
|
||||
|
||||
/// `feature = "backup"` Possible successful results of calling `Backup::step`.
|
||||
/// `feature = "backup"` Possible successful results of calling [`Backup::step`].
|
||||
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
|
||||
#[non_exhaustive]
|
||||
pub enum StepResult {
|
||||
@ -152,8 +152,8 @@ pub enum StepResult {
|
||||
|
||||
/// `feature = "backup"` Struct specifying the progress of a backup. The
|
||||
/// percentage completion can be calculated as `(pagecount - remaining) /
|
||||
/// pagecount`. The progress of a backup is as of the last call to `step` - if
|
||||
/// the source database is modified after a call to `step`, the progress value
|
||||
/// pagecount`. The progress of a backup is as of the last call to [`step`](Backup::step) - if
|
||||
/// the source database is modified after a call to [`step`](Backup::step), the progress value
|
||||
/// will become outdated and potentially incorrect.
|
||||
#[derive(Copy, Clone, Debug)]
|
||||
pub struct Progress {
|
||||
@ -225,7 +225,7 @@ impl Backup<'_, '_> {
|
||||
})
|
||||
}
|
||||
|
||||
/// Gets the progress of the backup as of the last call to `step`.
|
||||
/// Gets the progress of the backup as of the last call to [`step`](Backup::step).
|
||||
#[inline]
|
||||
pub fn progress(&self) -> Progress {
|
||||
unsafe {
|
||||
@ -240,7 +240,7 @@ impl Backup<'_, '_> {
|
||||
/// negative, will attempt to back up all remaining pages. This will hold a
|
||||
/// lock on the source database for the duration, so it is probably not
|
||||
/// what you want for databases that are currently active (see
|
||||
/// `run_to_completion` for a better alternative).
|
||||
/// [`run_to_completion`](Backup::run_to_completion) for a better alternative).
|
||||
///
|
||||
/// # Failure
|
||||
///
|
||||
@ -262,7 +262,7 @@ impl Backup<'_, '_> {
|
||||
}
|
||||
}
|
||||
|
||||
/// Attempts to run the entire backup. Will call `step(pages_per_step)` as
|
||||
/// Attempts to run the entire backup. Will call [`step(pages_per_step)`](Backup::step) as
|
||||
/// many times as necessary, sleeping for `pause_between_pages` between
|
||||
/// each call to give the source database time to process any pending
|
||||
/// queries. This is a direct implementation of "Example 2: Online Backup
|
||||
@ -276,7 +276,7 @@ impl Backup<'_, '_> {
|
||||
///
|
||||
/// # Failure
|
||||
///
|
||||
/// Will return `Err` if any of the calls to `step` return `Err`.
|
||||
/// Will return `Err` if any of the calls to [`step`](Backup::step) return `Err`.
|
||||
pub fn run_to_completion(
|
||||
&self,
|
||||
pages_per_step: c_int,
|
||||
|
@ -47,7 +47,7 @@
|
||||
//! functions take a `&mut [MaybeUninit<u8>]` as the destination buffer,
|
||||
//! where the "normal" functions take a `&mut [u8]`.
|
||||
//!
|
||||
//! Using `MaybeUninit` here can be more efficient in some cases, but is
|
||||
//! Using `MaybeUninit` here can be more efficient in some cases, but is
|
||||
//! often inconvenient, so both are provided.
|
||||
//!
|
||||
//! 2. Exact/inexact refers to to whether or not the entire buffer must be
|
||||
|
@ -19,7 +19,7 @@ impl Connection {
|
||||
///
|
||||
/// There can only be a single busy handler for a particular database
|
||||
/// connection at any given moment. If another busy handler was defined
|
||||
/// (using `busy_handler`) prior to calling this routine, that other
|
||||
/// (using [`busy_handler`](Connection::busy_handler)) prior to calling this routine, that other
|
||||
/// busy handler is cleared.
|
||||
pub fn busy_timeout(&self, timeout: Duration) -> Result<()> {
|
||||
let ms: i32 = timeout
|
||||
@ -45,7 +45,7 @@ impl Connection {
|
||||
///
|
||||
/// There can only be a single busy handler defined for each database
|
||||
/// connection. Setting a new busy handler clears any previously set
|
||||
/// handler. Note that calling `busy_timeout()` or evaluating `PRAGMA
|
||||
/// handler. Note that calling [`busy_timeout()`](Connection::busy_timeout) or evaluating `PRAGMA
|
||||
/// busy_timeout=N` will change the busy handler and thus
|
||||
/// clear any previously set busy handler.
|
||||
pub fn busy_handler(&self, callback: Option<fn(i32) -> bool>) -> Result<()> {
|
||||
|
@ -11,7 +11,7 @@ impl Connection {
|
||||
/// Prepare a SQL statement for execution, returning a previously prepared
|
||||
/// (but not currently in-use) statement if one is available. The
|
||||
/// returned statement will be cached for reuse by future calls to
|
||||
/// `prepare_cached` once it is dropped.
|
||||
/// [`prepare_cached`](Connection::prepare_cached) once it is dropped.
|
||||
///
|
||||
/// ```rust,no_run
|
||||
/// # use rusqlite::{Connection, Result};
|
||||
@ -63,7 +63,7 @@ pub struct StatementCache(RefCell<LruCache<Arc<str>, RawStatement>>);
|
||||
/// Cacheable statement.
|
||||
///
|
||||
/// Statement will return automatically to the cache by default.
|
||||
/// If you want the statement to be discarded, call `discard()` on it.
|
||||
/// If you want the statement to be discarded, call [`discard()`](CachedStatement::discard) on it.
|
||||
pub struct CachedStatement<'conn> {
|
||||
stmt: Option<Statement<'conn>>,
|
||||
cache: &'conn StatementCache,
|
||||
@ -105,7 +105,7 @@ impl CachedStatement<'_> {
|
||||
}
|
||||
|
||||
/// Discard the statement, preventing it from being returned to its
|
||||
/// `Connection`'s collection of cached statements.
|
||||
/// [`Connection`]'s collection of cached statements.
|
||||
#[inline]
|
||||
pub fn discard(mut self) {
|
||||
self.stmt = None;
|
||||
|
18
src/error.rs
18
src/error.rs
@ -43,11 +43,11 @@ pub enum Error {
|
||||
/// Error converting a file path to a string.
|
||||
InvalidPath(PathBuf),
|
||||
|
||||
/// Error returned when an `execute` call returns rows.
|
||||
/// Error returned when an [`execute`](crate::Connection::execute) call returns rows.
|
||||
ExecuteReturnedResults,
|
||||
|
||||
/// Error when a query that was expected to return at least one row (e.g.,
|
||||
/// for `query_row`) did not return any.
|
||||
/// for [`query_row`](crate::Connection::query_row)) did not return any.
|
||||
QueryReturnedNoRows,
|
||||
|
||||
/// Error when the value of a particular column is requested, but the index
|
||||
@ -67,29 +67,29 @@ pub enum Error {
|
||||
/// any or insert many.
|
||||
StatementChangedRows(usize),
|
||||
|
||||
/// Error returned by `functions::Context::get` when the function argument
|
||||
/// Error returned by [`functions::Context::get`](crate::functions::Context::get) when the function argument
|
||||
/// cannot be converted to the requested type.
|
||||
#[cfg(feature = "functions")]
|
||||
InvalidFunctionParameterType(usize, Type),
|
||||
/// Error returned by `vtab::Values::get` when the filter argument cannot
|
||||
/// Error returned by [`vtab::Values::get`](crate::vtab::Values::get) when the filter argument cannot
|
||||
/// be converted to the requested type.
|
||||
#[cfg(feature = "vtab")]
|
||||
InvalidFilterParameterType(usize, Type),
|
||||
|
||||
/// An error case available for implementors of custom user functions (e.g.,
|
||||
/// `create_scalar_function`).
|
||||
/// [`create_scalar_function`](crate::Connection::create_scalar_function)).
|
||||
#[cfg(feature = "functions")]
|
||||
#[allow(dead_code)]
|
||||
UserFunctionError(Box<dyn error::Error + Send + Sync + 'static>),
|
||||
|
||||
/// Error available for the implementors of the `ToSql` trait.
|
||||
/// Error available for the implementors of the [`ToSql`](crate::types::ToSql) trait.
|
||||
ToSqlConversionFailure(Box<dyn error::Error + Send + Sync + 'static>),
|
||||
|
||||
/// Error when the SQL is not a `SELECT`, is not read-only.
|
||||
InvalidQuery,
|
||||
|
||||
/// An error case available for implementors of custom modules (e.g.,
|
||||
/// `create_module`).
|
||||
/// [`create_module`](crate::Connection::create_module)).
|
||||
#[cfg(feature = "vtab")]
|
||||
#[allow(dead_code)]
|
||||
ModuleError(String),
|
||||
@ -98,8 +98,8 @@ pub enum Error {
|
||||
#[cfg(feature = "functions")]
|
||||
UnwindingPanic,
|
||||
|
||||
/// An error returned when `Context::get_aux` attempts to retrieve data
|
||||
/// of a different type than what had been stored using `Context::set_aux`.
|
||||
/// An error returned when [`Context::get_aux`](crate::functions::Context::get_aux) attempts to retrieve data
|
||||
/// of a different type than what had been stored using [`Context::set_aux`](crate::functions::Context::set_aux).
|
||||
#[cfg(feature = "functions")]
|
||||
GetAuxWrongType,
|
||||
|
||||
|
@ -126,7 +126,7 @@ impl Context<'_> {
|
||||
///
|
||||
/// # Failure
|
||||
///
|
||||
/// Will panic if `idx` is greater than or equal to `self.len()`.
|
||||
/// Will panic if `idx` is greater than or equal to [`self.len()`](Context::len).
|
||||
///
|
||||
/// Will return Err if the underlying SQLite type cannot be converted to a
|
||||
/// `T`.
|
||||
@ -156,16 +156,16 @@ impl Context<'_> {
|
||||
///
|
||||
/// # Failure
|
||||
///
|
||||
/// Will panic if `idx` is greater than or equal to `self.len()`.
|
||||
/// Will panic if `idx` is greater than or equal to [`self.len()`](Context::len).
|
||||
#[inline]
|
||||
pub fn get_raw(&self, idx: usize) -> ValueRef<'_> {
|
||||
let arg = self.args[idx];
|
||||
unsafe { ValueRef::from_value(arg) }
|
||||
}
|
||||
|
||||
/// Fetch or insert the the auxilliary data associated with a particular
|
||||
/// Fetch or insert the auxilliary data associated with a particular
|
||||
/// parameter. This is intended to be an easier-to-use way of fetching it
|
||||
/// compared to calling `get_aux` and `set_aux` separately.
|
||||
/// compared to calling [`get_aux`](Context::get_aux) and [`set_aux`](Context::set_aux) separately.
|
||||
///
|
||||
/// See `https://www.sqlite.org/c3ref/get_auxdata.html` for a discussion of
|
||||
/// this feature, or the unit tests of this module for an example.
|
||||
@ -206,7 +206,7 @@ impl Context<'_> {
|
||||
}
|
||||
|
||||
/// Gets the auxilliary data that was associated with a given parameter via
|
||||
/// `set_aux`. Returns `Ok(None)` if no data has been associated, and
|
||||
/// [`set_aux`](Context::set_aux). Returns `Ok(None)` if no data has been associated, and
|
||||
/// Ok(Some(v)) if it has. Returns an error if the requested type does not
|
||||
/// match.
|
||||
pub fn get_aux<T: Send + Sync + 'static>(&self, arg: c_int) -> Result<Option<Arc<T>>> {
|
||||
@ -235,7 +235,7 @@ where
|
||||
T: ToSql,
|
||||
{
|
||||
/// Initializes the aggregation context. Will be called prior to the first
|
||||
/// call to `step()` to set up the context for an invocation of the
|
||||
/// call to [`step()`](Aggregate::step) to set up the context for an invocation of the
|
||||
/// function. (Note: `init()` will not be called if there are no rows.)
|
||||
fn init(&self) -> A;
|
||||
|
||||
@ -244,9 +244,9 @@ where
|
||||
fn step(&self, _: &mut Context<'_>, _: &mut A) -> Result<()>;
|
||||
|
||||
/// Computes and returns the final result. Will be called exactly once for
|
||||
/// each invocation of the function. If `step()` was called at least
|
||||
/// each invocation of the function. If [`step()`](Aggregate::step) was called at least
|
||||
/// once, will be given `Some(A)` (the same `A` as was created by
|
||||
/// `init` and given to `step`); if `step()` was not called (because
|
||||
/// [`init`](Aggregate::init) and given to [`step`](Aggregate::step)); if [`step()`](Aggregate::step) was not called (because
|
||||
/// the function is running against 0 rows), will be given `None`.
|
||||
fn finalize(&self, _: Option<A>) -> Result<T>;
|
||||
}
|
||||
@ -309,7 +309,7 @@ impl Connection {
|
||||
/// given the same input, `deterministic` should be `true`.
|
||||
///
|
||||
/// The function will remain available until the connection is closed or
|
||||
/// until it is explicitly removed via `remove_function`.
|
||||
/// until it is explicitly removed via [`remove_function`](Connection::remove_function).
|
||||
///
|
||||
/// # Example
|
||||
///
|
||||
@ -405,7 +405,7 @@ impl Connection {
|
||||
/// database connection.
|
||||
///
|
||||
/// `fn_name` and `n_arg` should match the name and number of arguments
|
||||
/// given to `create_scalar_function` or `create_aggregate_function`.
|
||||
/// given to [`create_scalar_function`](Connection::create_scalar_function) or [`create_aggregate_function`](Connection::create_aggregate_function).
|
||||
///
|
||||
/// # Failure
|
||||
///
|
||||
|
11
src/lib.rs
11
src/lib.rs
@ -20,7 +20,7 @@
|
||||
//! name TEXT NOT NULL,
|
||||
//! data BLOB
|
||||
//! )",
|
||||
//! params![],
|
||||
//! [],
|
||||
//! )?;
|
||||
//! let me = Person {
|
||||
//! id: 0,
|
||||
@ -33,7 +33,7 @@
|
||||
//! )?;
|
||||
//!
|
||||
//! let mut stmt = conn.prepare("SELECT id, name, data FROM person")?;
|
||||
//! let person_iter = stmt.query_map(params![], |row| {
|
||||
//! let person_iter = stmt.query_map([], |row| {
|
||||
//! Ok(Person {
|
||||
//! id: row.get(0)?,
|
||||
//! name: row.get(1)?,
|
||||
@ -455,8 +455,7 @@ impl Connection {
|
||||
/// ```rust,no_run
|
||||
/// # use rusqlite::{Connection, Result};
|
||||
/// fn create_tables(conn: &Connection) -> Result<()> {
|
||||
/// conn.execute_batch(
|
||||
/// "BEGIN;
|
||||
/// conn.execute_batch("BEGIN;
|
||||
/// CREATE TABLE foo(x INTEGER);
|
||||
/// CREATE TABLE bar(y TEXT);
|
||||
/// COMMIT;",
|
||||
@ -859,7 +858,7 @@ impl fmt::Debug for Connection {
|
||||
|
||||
/// Batch iterator
|
||||
/// ```rust
|
||||
/// use rusqlite::{Batch, Connection, Result, NO_PARAMS};
|
||||
/// use rusqlite::{Batch, Connection, Result};
|
||||
///
|
||||
/// fn main() -> Result<()> {
|
||||
/// let conn = Connection::open_in_memory()?;
|
||||
@ -869,7 +868,7 @@ impl fmt::Debug for Connection {
|
||||
/// ";
|
||||
/// let mut batch = Batch::new(&conn, sql);
|
||||
/// while let Some(mut stmt) = batch.next()? {
|
||||
/// stmt.execute(NO_PARAMS)?;
|
||||
/// stmt.execute([])?;
|
||||
/// }
|
||||
/// Ok(())
|
||||
/// }
|
||||
|
@ -21,7 +21,7 @@ use sealed::Sealed;
|
||||
///
|
||||
/// Many functions in this library let you pass parameters to SQLite. Doing this
|
||||
/// lets you avoid any risk of SQL injection, and is simpler than escaping
|
||||
/// things manually. Aside from deprecated functions and a few helpers, this is
|
||||
/// things manually. Aside from deprecated functions and a few helpers, this is
|
||||
/// indicated by the function taking a generic argument that implements `Params`
|
||||
/// (this trait).
|
||||
///
|
||||
|
@ -29,7 +29,7 @@ impl<'stmt> Rows<'stmt> {
|
||||
/// This interface is not compatible with Rust's `Iterator` trait, because
|
||||
/// the lifetime of the returned row is tied to the lifetime of `self`.
|
||||
/// This is a fallible "streaming iterator". For a more natural interface,
|
||||
/// consider using `query_map` or `query_and_then` instead, which
|
||||
/// consider using [`query_map`](crate::Statement::query_map) or [`query_and_then`](crate::Statement::query_and_then) instead, which
|
||||
/// return types that implement `Iterator`.
|
||||
#[allow(clippy::should_implement_trait)] // cannot implement Iterator
|
||||
#[inline]
|
||||
|
@ -411,7 +411,7 @@ impl Drop for ChangesetIter<'_> {
|
||||
}
|
||||
|
||||
/// `feature = "session"` An item passed to a conflict-handler by
|
||||
/// `Connection::apply`, or an item generated by `ChangesetIter::next`.
|
||||
/// [`Connection::apply`](crate::Connection::apply), or an item generated by [`ChangesetIter::next`](ChangesetIter::next).
|
||||
// TODO enum ? Delete, Insert, Update, ...
|
||||
pub struct ChangesetItem {
|
||||
it: *mut ffi::sqlite3_changeset_iter,
|
||||
|
@ -114,7 +114,7 @@ impl Statement<'_> {
|
||||
///
|
||||
/// # Note
|
||||
///
|
||||
/// This function is a convenience wrapper around `execute()` intended for
|
||||
/// This function is a convenience wrapper around [`execute()`](Statement::execute) intended for
|
||||
/// queries that insert a single item. It is possible to misuse this
|
||||
/// function in a way that it cannot detect, such as by calling it on a
|
||||
/// statement which _updates_ a single
|
||||
@ -136,8 +136,8 @@ impl Statement<'_> {
|
||||
/// rows.
|
||||
///
|
||||
/// Due to lifetime restricts, the rows handle returned by `query` does not
|
||||
/// implement the `Iterator` trait. Consider using `query_map` or
|
||||
/// `query_and_then` instead, which do.
|
||||
/// implement the `Iterator` trait. Consider using [`query_map`](Statement::query_map) or
|
||||
/// [`query_and_then`](Statement::query_and_then) instead, which do.
|
||||
///
|
||||
/// ## Example
|
||||
///
|
||||
@ -437,7 +437,7 @@ impl Statement<'_> {
|
||||
/// ignored.
|
||||
///
|
||||
/// Returns `Err(QueryReturnedNoRows)` if no results are returned. If the
|
||||
/// query truly is optional, you can call `.optional()` on the result of
|
||||
/// query truly is optional, you can call [`.optional()`](crate::OptionalExtension::optional) on the result of
|
||||
/// this to get a `Result<Option<T>>` (requires that the trait `rusqlite::OptionalExtension`
|
||||
/// is imported).
|
||||
///
|
||||
@ -464,7 +464,7 @@ impl Statement<'_> {
|
||||
/// ignored.
|
||||
///
|
||||
/// Returns `Err(QueryReturnedNoRows)` if no results are returned. If the
|
||||
/// query truly is optional, you can call `.optional()` on the result of
|
||||
/// query truly is optional, you can call [`.optional()`](crate::OptionalExtension::optional) on the result of
|
||||
/// this to get a `Result<Option<T>>` (requires that the trait `rusqlite::OptionalExtension`
|
||||
/// is imported).
|
||||
///
|
||||
@ -493,7 +493,7 @@ impl Statement<'_> {
|
||||
self.finalize_()
|
||||
}
|
||||
|
||||
/// Return the (one-based) index of an SQL parameter given its name.
|
||||
/// Return the (one-based) index of an SQL parameter given its name.
|
||||
///
|
||||
/// Note that the initial ":" or "$" or "@" or "?" used to specify the
|
||||
/// parameter is included as part of the name.
|
||||
@ -563,7 +563,7 @@ impl Statement<'_> {
|
||||
|
||||
/// Low level API to directly bind a parameter to a given index.
|
||||
///
|
||||
/// Note that the index is one-based, that is, the first parameter index is
|
||||
/// Note that the index is one-based, that is, the first parameter index is
|
||||
/// 1 and not 0. This is consistent with the SQLite API and the values given
|
||||
/// to parameters bound as `?NNN`.
|
||||
///
|
||||
|
@ -377,8 +377,8 @@ impl Connection {
|
||||
/// Begin a new transaction with the default behavior (DEFERRED).
|
||||
///
|
||||
/// The transaction defaults to rolling back when it is dropped. If you
|
||||
/// want the transaction to commit, you must call `commit` or
|
||||
/// `set_drop_behavior(DropBehavior::Commit)`.
|
||||
/// want the transaction to commit, you must call [`commit`](Transaction::commit) or
|
||||
/// [`set_drop_behavior(DropBehavior::Commit)`](Transaction::set_drop_behavior).
|
||||
///
|
||||
/// ## Example
|
||||
///
|
||||
@ -406,7 +406,7 @@ impl Connection {
|
||||
|
||||
/// Begin a new transaction with a specified behavior.
|
||||
///
|
||||
/// See `transaction`.
|
||||
/// See [`transaction`](Connection::transaction).
|
||||
///
|
||||
/// # Failure
|
||||
///
|
||||
@ -457,8 +457,8 @@ impl Connection {
|
||||
/// Begin a new savepoint with the default behavior (DEFERRED).
|
||||
///
|
||||
/// The savepoint defaults to rolling back when it is dropped. If you want
|
||||
/// the savepoint to commit, you must call `commit` or
|
||||
/// `set_drop_behavior(DropBehavior::Commit)`.
|
||||
/// the savepoint to commit, you must call [`commit`](Savepoint::commit) or
|
||||
/// [`set_drop_behavior(DropBehavior::Commit)`](Savepoint::set_drop_behavior).
|
||||
///
|
||||
/// ## Example
|
||||
///
|
||||
@ -486,7 +486,7 @@ impl Connection {
|
||||
|
||||
/// Begin a new savepoint with a specified name.
|
||||
///
|
||||
/// See `savepoint`.
|
||||
/// See [`savepoint`](Connection::savepoint).
|
||||
///
|
||||
/// # Failure
|
||||
///
|
||||
|
@ -3,7 +3,7 @@ use std::convert::TryInto;
|
||||
use std::error::Error;
|
||||
use std::fmt;
|
||||
|
||||
/// Enum listing possible errors from `FromSql` trait.
|
||||
/// Enum listing possible errors from [`FromSql`] trait.
|
||||
#[derive(Debug)]
|
||||
#[non_exhaustive]
|
||||
pub enum FromSqlError {
|
||||
@ -26,7 +26,7 @@ pub enum FromSqlError {
|
||||
#[cfg(feature = "uuid")]
|
||||
InvalidUuidSize(usize),
|
||||
|
||||
/// An error case available for implementors of the `FromSql` trait.
|
||||
/// An error case available for implementors of the [`FromSql`] trait.
|
||||
Other(Box<dyn Error + Send + Sync + 'static>),
|
||||
}
|
||||
|
||||
@ -72,20 +72,10 @@ impl Error for FromSqlError {
|
||||
}
|
||||
}
|
||||
|
||||
/// Result type for implementors of the `FromSql` trait.
|
||||
/// Result type for implementors of the [`FromSql`] trait.
|
||||
pub type FromSqlResult<T> = Result<T, FromSqlError>;
|
||||
|
||||
/// A trait for types that can be created from a SQLite value.
|
||||
///
|
||||
/// Note that `FromSql` and `ToSql` are defined for most integral types, but
|
||||
/// not `u64` or `usize`. This is intentional; SQLite returns integers as
|
||||
/// signed 64-bit values, which cannot fully represent the range of these
|
||||
/// types. Rusqlite would have to
|
||||
/// decide how to handle negative values: return an error or reinterpret as a
|
||||
/// very large postive numbers, neither of which
|
||||
/// is guaranteed to be correct for everyone. Callers can work around this by
|
||||
/// fetching values as i64 and then doing the interpretation themselves or by
|
||||
/// defining a newtype and implementing `FromSql`/`ToSql` for it.
|
||||
pub trait FromSql: Sized {
|
||||
/// Converts SQLite value into Rust value.
|
||||
fn column_result(value: ValueRef<'_>) -> FromSqlResult<Self>;
|
||||
|
@ -1,7 +1,7 @@
|
||||
//! Traits dealing with SQLite data types.
|
||||
//!
|
||||
//! SQLite uses a [dynamic type system](https://www.sqlite.org/datatype3.html). Implementations of
|
||||
//! the `ToSql` and `FromSql` traits are provided for the basic types that
|
||||
//! the [`ToSql`] and [`FromSql`] traits are provided for the basic types that
|
||||
//! SQLite provides methods for:
|
||||
//!
|
||||
//! * Strings (`String` and `&str`)
|
||||
@ -11,17 +11,17 @@
|
||||
//! The number situation is a little complicated due to the fact that all
|
||||
//! numbers in SQLite are stored as `INTEGER` (`i64`) or `REAL` (`f64`).
|
||||
//!
|
||||
//! `ToSql` and `FromSql` are implemented for all primitive number types.
|
||||
//! `FromSql` has different behaviour depending on the SQL and Rust types, and
|
||||
//! [`ToSql`] and [`FromSql`] are implemented for all primitive number types.
|
||||
//! [`FromSql`] has different behaviour depending on the SQL and Rust types, and
|
||||
//! the value.
|
||||
//!
|
||||
//! * `INTEGER` to integer: returns an `Error::IntegralValueOutOfRange` error if
|
||||
//! * `INTEGER` to integer: returns an [`Error::IntegralValueOutOfRange`](crate::Error::IntegralValueOutOfRange) error if
|
||||
//! the value does not fit in the Rust type.
|
||||
//! * `REAL` to integer: always returns an `Error::InvalidColumnType` error.
|
||||
//! * `REAL` to integer: always returns an [`Error::InvalidColumnType`](crate::Error::InvalidColumnType) error.
|
||||
//! * `INTEGER` to float: casts using `as` operator. Never fails.
|
||||
//! * `REAL` to float: casts using `as` operator. Never fails.
|
||||
//!
|
||||
//! `ToSql` always succeeds except when storing a `u64` or `usize` value that
|
||||
//! [`ToSql`] always succeeds except when storing a `u64` or `usize` value that
|
||||
//! cannot fit in an `INTEGER` (`i64`). Also note that SQLite ignores column
|
||||
//! types, so if you store an `i64` in a column with type `REAL` it will be
|
||||
//! stored as an `INTEGER`, not a `REAL`.
|
||||
@ -61,8 +61,8 @@ impl ToSql for DateTimeSql {
|
||||
|
||||
"##
|
||||
)]
|
||||
//! `ToSql` and `FromSql` are also implemented for `Option<T>` where `T`
|
||||
//! implements `ToSql` or `FromSql` for the cases where you want to know if a
|
||||
//! [`ToSql`] and [`FromSql`] are also implemented for `Option<T>` where `T`
|
||||
//! implements [`ToSql`] or [`FromSql`] for the cases where you want to know if a
|
||||
//! value was NULL (which gets translated to `None`).
|
||||
|
||||
pub use self::from_sql::{FromSql, FromSqlError, FromSqlResult};
|
||||
|
@ -1,4 +1,4 @@
|
||||
//! `ToSql` and `FromSql` implementation for JSON `Value`.
|
||||
//! [`ToSql`] and [`FromSql`] implementation for JSON `Value`.
|
||||
|
||||
use serde_json::Value;
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
//! `ToSql` and `FromSql` implementation for [`time::OffsetDateTime`].
|
||||
//! [`ToSql`] and [`FromSql`] implementation for [`time::OffsetDateTime`].
|
||||
use crate::types::{FromSql, FromSqlError, FromSqlResult, ToSql, ToSqlOutput, ValueRef};
|
||||
use crate::Result;
|
||||
use time::{OffsetDateTime, PrimitiveDateTime, UtcOffset};
|
||||
|
@ -6,7 +6,7 @@ use std::borrow::Cow;
|
||||
use std::convert::TryFrom;
|
||||
|
||||
/// `ToSqlOutput` represents the possible output types for implementers of the
|
||||
/// `ToSql` trait.
|
||||
/// [`ToSql`] trait.
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
#[non_exhaustive]
|
||||
pub enum ToSqlOutput<'a> {
|
||||
@ -91,7 +91,7 @@ impl ToSql for ToSqlOutput<'_> {
|
||||
}
|
||||
|
||||
/// A trait for types that can be converted into SQLite values. Returns
|
||||
/// `Error::ToSqlConversionFailure` if the conversion fails.
|
||||
/// [`Error::ToSqlConversionFailure`] if the conversion fails.
|
||||
pub trait ToSql {
|
||||
/// Converts Rust value to SQLite value
|
||||
fn to_sql(&self) -> Result<ToSqlOutput<'_>>;
|
||||
|
@ -1,4 +1,4 @@
|
||||
//! `ToSql` and `FromSql` implementation for [`url::Url`].
|
||||
//! [`ToSql`] and [`FromSql`] implementation for [`url::Url`].
|
||||
use crate::types::{FromSql, FromSqlError, FromSqlResult, ToSql, ToSqlOutput, ValueRef};
|
||||
use crate::Result;
|
||||
use url::Url;
|
||||
|
@ -3,7 +3,7 @@ use super::{Null, Type};
|
||||
/// Owning [dynamic type value](http://sqlite.org/datatype3.html). Value's type is typically
|
||||
/// dictated by SQLite (not by the caller).
|
||||
///
|
||||
/// See [`ValueRef`](enum.ValueRef.html) for a non-owning dynamic type value.
|
||||
/// See [`ValueRef`](crate::types::ValueRef) for a non-owning dynamic type value.
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
pub enum Value {
|
||||
/// The value is a `NULL` value.
|
||||
|
@ -4,7 +4,7 @@ use crate::types::{FromSqlError, FromSqlResult};
|
||||
/// A non-owning [dynamic type value](http://sqlite.org/datatype3.html). Typically the
|
||||
/// memory backing this value is owned by SQLite.
|
||||
///
|
||||
/// See [`Value`](enum.Value.html) for an owning dynamic type value.
|
||||
/// See [`Value`](Value) for an owning dynamic type value.
|
||||
#[derive(Copy, Clone, Debug, PartialEq)]
|
||||
pub enum ValueRef<'a> {
|
||||
/// The value is a `NULL` value.
|
||||
@ -35,7 +35,7 @@ impl ValueRef<'_> {
|
||||
|
||||
impl<'a> ValueRef<'a> {
|
||||
/// If `self` is case `Integer`, returns the integral value. Otherwise,
|
||||
/// returns `Err(Error::InvalidColumnType)`.
|
||||
/// returns [`Err(Error::InvalidColumnType)`](crate::Error::InvalidColumnType).
|
||||
#[inline]
|
||||
pub fn as_i64(&self) -> FromSqlResult<i64> {
|
||||
match *self {
|
||||
@ -45,7 +45,7 @@ impl<'a> ValueRef<'a> {
|
||||
}
|
||||
|
||||
/// If `self` is case `Real`, returns the floating point value. Otherwise,
|
||||
/// returns `Err(Error::InvalidColumnType)`.
|
||||
/// returns [`Err(Error::InvalidColumnType)`](crate::Error::InvalidColumnType).
|
||||
#[inline]
|
||||
pub fn as_f64(&self) -> FromSqlResult<f64> {
|
||||
match *self {
|
||||
@ -55,7 +55,7 @@ impl<'a> ValueRef<'a> {
|
||||
}
|
||||
|
||||
/// If `self` is case `Text`, returns the string value. Otherwise, returns
|
||||
/// `Err(Error::InvalidColumnType)`.
|
||||
/// [`Err(Error::InvalidColumnType)`](crate::Error::InvalidColumnType).
|
||||
#[inline]
|
||||
pub fn as_str(&self) -> FromSqlResult<&'a str> {
|
||||
match *self {
|
||||
@ -67,7 +67,7 @@ impl<'a> ValueRef<'a> {
|
||||
}
|
||||
|
||||
/// If `self` is case `Blob`, returns the byte slice. Otherwise, returns
|
||||
/// `Err(Error::InvalidColumnType)`.
|
||||
/// [`Err(Error::InvalidColumnType)`](crate::Error::InvalidColumnType).
|
||||
#[inline]
|
||||
pub fn as_blob(&self) -> FromSqlResult<&'a [u8]> {
|
||||
match *self {
|
||||
|
@ -1,10 +1,10 @@
|
||||
//! `feature = "vtab"` Create virtual tables.
|
||||
//!
|
||||
//! Follow these steps to create your own virtual table:
|
||||
//! 1. Write implemenation of `VTab` and `VTabCursor` traits.
|
||||
//! 2. Create an instance of the `Module` structure specialized for `VTab` impl.
|
||||
//! 1. Write implemenation of [`VTab`] and [`VTabCursor`] traits.
|
||||
//! 2. Create an instance of the [`Module`] structure specialized for [`VTab`] impl.
|
||||
//! from step 1.
|
||||
//! 3. Register your `Module` structure using `Connection.create_module`.
|
||||
//! 3. Register your [`Module`] structure using [`Connection::create_module`].
|
||||
//! 4. Run a `CREATE VIRTUAL TABLE` command that specifies the new module in the
|
||||
//! `USING` clause.
|
||||
//!
|
||||
@ -205,7 +205,7 @@ impl VTabConnection {
|
||||
///
|
||||
/// (See [SQLite doc](https://sqlite.org/c3ref/vtab.html))
|
||||
pub unsafe trait VTab<'vtab>: Sized {
|
||||
/// Client data passed to `Connection::create_module`.
|
||||
/// Client data passed to [`Connection::create_module`].
|
||||
type Aux;
|
||||
/// Specific cursor implementation
|
||||
type Cursor: VTabCursor;
|
||||
@ -237,7 +237,7 @@ pub trait CreateVTab<'vtab>: VTab<'vtab> {
|
||||
/// database connection that is executing the CREATE VIRTUAL TABLE
|
||||
/// statement.
|
||||
///
|
||||
/// Call `connect` by default.
|
||||
/// Call [`connect`](VTab::connect) by default.
|
||||
/// (See [SQLite doc](https://sqlite.org/vtab.html#the_xcreate_method))
|
||||
fn create(
|
||||
db: &mut VTabConnection,
|
||||
@ -248,7 +248,7 @@ pub trait CreateVTab<'vtab>: VTab<'vtab> {
|
||||
}
|
||||
|
||||
/// Destroy the underlying table implementation. This method undoes the work
|
||||
/// of `create`.
|
||||
/// of [`create`](CreateVTab::create).
|
||||
///
|
||||
/// Do nothing by default.
|
||||
/// (See [SQLite doc](https://sqlite.org/vtab.html#the_xdestroy_method))
|
||||
@ -302,7 +302,7 @@ impl From<u8> for IndexConstraintOp {
|
||||
}
|
||||
|
||||
/// `feature = "vtab"` Pass information into and receive the reply from the
|
||||
/// `VTab.best_index` method.
|
||||
/// [`VTab::best_index`] method.
|
||||
///
|
||||
/// (See [SQLite doc](http://sqlite.org/c3ref/index_info.html))
|
||||
pub struct IndexInfo(*mut ffi::sqlite3_index_info);
|
||||
@ -334,7 +334,7 @@ impl IndexInfo {
|
||||
unsafe { (*self.0).nOrderBy as usize }
|
||||
}
|
||||
|
||||
/// Information about what parameters to pass to `VTabCursor.filter`.
|
||||
/// Information about what parameters to pass to [`VTabCursor::filter`].
|
||||
#[inline]
|
||||
pub fn constraint_usage(&mut self, constraint_idx: usize) -> IndexConstraintUsage<'_> {
|
||||
let constraint_usages = unsafe {
|
||||
@ -425,11 +425,11 @@ impl IndexConstraint<'_> {
|
||||
}
|
||||
|
||||
/// `feature = "vtab"` Information about what parameters to pass to
|
||||
/// `VTabCursor.filter`.
|
||||
/// [`VTabCursor::filter`].
|
||||
pub struct IndexConstraintUsage<'a>(&'a mut ffi::sqlite3_index_constraint_usage);
|
||||
|
||||
impl IndexConstraintUsage<'_> {
|
||||
/// if `argv_index` > 0, constraint is part of argv to `VTabCursor.filter`
|
||||
/// if `argv_index` > 0, constraint is part of argv to [`VTabCursor::filter`]
|
||||
#[inline]
|
||||
pub fn set_argv_index(&mut self, argv_index: c_int) {
|
||||
self.0.argvIndex = argv_index;
|
||||
@ -495,7 +495,7 @@ pub unsafe trait VTabCursor: Sized {
|
||||
/// Begin a search of a virtual table.
|
||||
/// (See [SQLite doc](https://sqlite.org/vtab.html#the_xfilter_method))
|
||||
fn filter(&mut self, idx_num: c_int, idx_str: Option<&str>, args: &Values<'_>) -> Result<()>;
|
||||
/// Advance cursor to the next row of a result set initiated by `filter`.
|
||||
/// Advance cursor to the next row of a result set initiated by [`filter`](VTabCursor::filter).
|
||||
/// (See [SQLite doc](https://sqlite.org/vtab.html#the_xnext_method))
|
||||
fn next(&mut self) -> Result<()>;
|
||||
/// Must return `false` if the cursor currently points to a valid row of
|
||||
@ -512,7 +512,7 @@ pub unsafe trait VTabCursor: Sized {
|
||||
fn rowid(&self) -> Result<i64>;
|
||||
}
|
||||
|
||||
/// `feature = "vtab"` Context is used by `VTabCursor.column` to specify the
|
||||
/// `feature = "vtab"` Context is used by [`VTabCursor::column`] to specify the
|
||||
/// cell value.
|
||||
pub struct Context(*mut ffi::sqlite3_context);
|
||||
|
||||
@ -528,8 +528,8 @@ impl Context {
|
||||
// TODO sqlite3_vtab_nochange (http://sqlite.org/c3ref/vtab_nochange.html)
|
||||
}
|
||||
|
||||
/// `feature = "vtab"` Wrapper to `VTabCursor.filter` arguments, the values
|
||||
/// requested by `VTab.best_index`.
|
||||
/// `feature = "vtab"` Wrapper to [`VTabCursor::filter`] arguments, the values
|
||||
/// requested by [`VTab::best_index`].
|
||||
pub struct Values<'a> {
|
||||
args: &'a [*mut ffi::sqlite3_value],
|
||||
}
|
||||
@ -606,7 +606,7 @@ impl<'a> IntoIterator for &'a Values<'a> {
|
||||
}
|
||||
}
|
||||
|
||||
/// `Values` iterator.
|
||||
/// [`Values`] iterator.
|
||||
pub struct ValueIter<'a> {
|
||||
iter: slice::Iter<'a, *mut ffi::sqlite3_value>,
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user