Struct rusqlite::Statement [] [src]

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

A prepared statement.

Methods

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

fn parameter_index(&self, name: &str) -> Result<Option<i32>>

Return the index of an SQL parameter given its name.

Failure

Will return Err if name is invalid. Will return Ok(None) if the name is valid but not a bound parameter of this statement.

fn execute_named(&mut self, params: &[(&str, &ToSql)]) -> Result<c_int>

Execute the prepared statement with named parameter(s). If any parameters that were in the prepared statement are not included in params, they will continue to use the most-recently bound value from a previous call to execute_named, or NULL if they have never been bound.

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

Example

fn insert(conn: &Connection) -> Result<i32> {
    let mut stmt = try!(conn.prepare("INSERT INTO test (name) VALUES (:name)"));
    stmt.execute_named(&[(":name", &"one")])
}

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_named<'a>(&'a mut self, params: &[(&str, &ToSql)]) -> Result<Rows<'a>>

Execute the prepared statement with named parameter(s), returning an iterator over the resulting rows. If any parameters that were in the prepared statement are not included in params, they will continue to use the most-recently bound value from a previous call to query_named, or NULL if they have never been bound.

Example

fn query(conn: &Connection) -> Result<()> {
    let mut stmt = try!(conn.prepare("SELECT * FROM test where name = :name"));
    let mut rows = try!(stmt.query_named(&[(":name", &"one")]));
    for row in rows {
        // ...
    }
    Ok(())
}

Failure

Will return Err if binding parameters fails.

impl<'conn> Statement<'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]) -> Result<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: &Connection) -> Result<()> {
    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]) -> Result<Rows<'a>>

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

Example

fn get_names(conn: &Connection) -> Result<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) -> Result<MappedRows<'a, F>> where F: FnMut(&Row) -> 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) -> Result<AndThenRows<'a, F>> where E: From<Error>, F: FnMut(&Row) -> 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<Error> (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) -> Result<()>

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 Statement<'conn>
[src]

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

Formats the value using the given formatter.

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

fn drop(&mut self)

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