Struct DatabaseConnection

Source
pub struct DatabaseConnection { /* private fields */ }
Expand description

A connection to a sqlite3 database.

Implementations§

Source§

impl DatabaseConnection

Source

pub fn new<A: Access>(access: A) -> SqliteResult<DatabaseConnection>

Given explicit access to a database, attempt to connect to it.

Note SqliteError code is accompanied by (copy) of sqlite3_errmsg().

Source

pub fn ignore_detail(&mut self)

Opt out of copies of error message details.

Source

pub fn in_memory() -> SqliteResult<DatabaseConnection>

Create connection to an in-memory database.

  • TODO: integrate sqlite3_errmsg()
Source

pub fn prepare<'db: 'st, 'st>( &'db self, sql: &str, ) -> SqliteResult<PreparedStatement>

Prepare/compile an SQL statement.

Source

pub fn prepare_with_offset<'db: 'st, 'st>( &'db self, sql: &str, ) -> SqliteResult<(PreparedStatement, usize)>

Prepare/compile an SQL statement and give offset to remaining text.

TODO: give caller a safe way to use the offset. Perhaps return a &’x str?

Source

pub fn errmsg(&mut self) -> String

Return a copy of the latest error message.

Return "" in case of ill-formed utf-8 or null.

TODO: represent error state in types: “If a prior API call failed but the most recent API call succeeded, the return value from sqlite3_errcode() is undefined.”

cf ffi::sqlite3_errmsg.

Source

pub fn exec(&mut self, sql: &str) -> SqliteResult<()>

One-Step Query Execution Interface

cf [sqlite3_exec][exec] [exec]: http://www.sqlite.org/c3ref/exec.html

  • TODO: callback support?
  • TODO: errmsg support
Source

pub fn changes(&self) -> u64

Return the number of database rows that were changed or inserted or deleted by the most recently completed SQL statement.

cf sqlite3_changes.

Source

pub fn busy_timeout(&mut self, d: Duration) -> SqliteResult<()>

Set a busy timeout and clear any previously set handler. If duration is zero or negative, turns off busy handler.

Source

pub fn last_insert_rowid(&self) -> i64

Return the rowid of the most recent successful INSERT into a rowid table or virtual table.

cf sqlite3_last_insert_rowid

Source

pub unsafe fn expose(&mut self) -> *mut sqlite3

Expose the underlying sqlite3 struct pointer for use with the ffi module.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.