Struct rusqlite::SqliteStatement [] [src]

pub struct SqliteStatement<'conn> {
    // some fields omitted
}

A prepared statement.

Methods

impl<'conn> SqliteStatement<'conn>
[src]

fn column_names(&self) -> Vec<&str>

Get all the column names in the result set of the prepared statement.

fn execute(&mut self, params: &[&ToSql]) -> SqliteResult<c_int>

Execute the prepared statement.

On success, returns the number of rows that were changed or inserted or deleted (via sqlite3_changes).

Example

fn update_rows(conn: &SqliteConnection) -> SqliteResult<()> {
    let mut stmt = try!(conn.prepare("UPDATE foo SET bar = 'baz' WHERE qux = ?"));

    try!(stmt.execute(&[&1i32]));
    try!(stmt.execute(&[&2i32]));

    Ok(())
}

Failure

Will return Err if binding parameters fails, the executed statement returns rows (in which case query should be used instead), or the underling SQLite call fails.

fn query<'a>(&'a mut self, params: &[&ToSql]) -> SqliteResult<SqliteRows<'a>>

Execute the prepared statement, returning an iterator over the resulting rows.

Example

fn get_names(conn: &SqliteConnection) -> SqliteResult<Vec<String>> {
    let mut stmt = try!(conn.prepare("SELECT name FROM people"));
    let mut rows = try!(stmt.query(&[]));

    let mut names = Vec::new();
    for result_row in rows {
        let row = try!(result_row);
        names.push(row.get(0));
    }

    Ok(names)
}

Failure

Will return Err if binding parameters fails.

fn query_map<'a, T, F>(&'a mut self, params: &[&ToSql], f: F) -> SqliteResult<MappedRows<'a, F>> where F: FnMut(&SqliteRow) -> T

Executes the prepared statement and maps a function over the resulting rows.

Unlike the iterator produced by query, the returned iterator does not expose the possibility for accessing stale rows.

Failure

Will return Err if binding parameters fails.

fn query_and_then<'a, T, E, F>(&'a mut self, params: &[&ToSql], f: F) -> SqliteResult<AndThenRows<'a, F>> where E: From<SqliteError>, F: FnMut(&SqliteRow) -> Result<T, E>

Executes the prepared statement and maps a function over the resulting rows, where the function returns a Result with Error type implementing std::convert::From<SqliteError> (so errors can be unified).

Unlike the iterator produced by query, the returned iterator does not expose the possibility for accessing stale rows.

Failure

Will return Err if binding parameters fails.

fn finalize(self) -> SqliteResult<()>

Consumes the statement.

Functionally equivalent to the Drop implementation, but allows callers to see any errors that occur.

Failure

Will return Err if the underlying SQLite call fails.

Trait Implementations

impl<'conn> Debug for SqliteStatement<'conn>
[src]

fn fmt(&self, f: &mut Formatter) -> Result

Formats the value using the given formatter.

impl<'conn> Drop for SqliteStatement<'conn>
[src]

fn drop(&mut self)

A method called when the value goes out of scope. Read more