Struct rusqlite::SqliteStatement [] [src]

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

A prepared statement.

Methods

impl<'conn> SqliteStatement<'conn>

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(())
}

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)
}

fn query_map<'a, T, F>(&'a mut self, params: &[&ToSql], f: F) -> SqliteResult<MappedRows<'a, F>> where T: 'static, 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.

fn query_and_then<'a, T, E, F>(&'a mut self, params: &[&ToSql], f: F) -> SqliteResult<AndThenRows<'a, F>> where T: 'static, 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.

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

Consumes the statement.

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

Trait Implementations

impl<'conn> Debug for SqliteStatement<'conn>

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

impl<'conn> Drop for SqliteStatement<'conn>

fn drop(&mut self)