Struct postgres::Statement [] [src]

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

A prepared statement.

Methods

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

fn param_types(&self) -> &[Type]

Returns a slice containing the expected parameter types.

fn columns(&self) -> &[Column]

Returns a slice describing the columns of the result of the query.

fn execute(&self, params: &[&ToSql]) -> Result<u64>

Executes the prepared statement, returning the number of rows modified.

If the statement does not modify any rows (e.g. SELECT), 0 is returned.

Panics

Panics if the number of parameters provided does not match the number expected.

Example

let stmt = conn.prepare("UPDATE foo SET bar = $1 WHERE baz = $2").unwrap();
match stmt.execute(&[&bar, &baz]) {
    Ok(count) => println!("{} row(s) updated", count),
    Err(err) => println!("Error executing query: {:?}", err)
}

fn query<'a>(&'a self, params: &[&ToSql]) -> Result<Rows<'a>>

Executes the prepared statement, returning the resulting rows.

Panics

Panics if the number of parameters provided does not match the number expected.

Example

let stmt = conn.prepare("SELECT foo FROM bar WHERE baz = $1").unwrap();
let rows = match stmt.query(&[&baz]) {
    Ok(rows) => rows,
    Err(err) => panic!("Error running query: {:?}", err)
};
for row in &rows {
    let foo: i32 = row.get("foo");
    println!("foo: {}", foo);
}

fn lazy_query<'trans, 'stmt>(&'stmt self, trans: &'trans Transaction, params: &[&ToSql], row_limit: i32) -> Result<LazyRows<'trans, 'stmt>>

Executes the prepared statement, returning a lazily loaded iterator over the resulting rows.

No more than row_limit rows will be stored in memory at a time. Rows will be pulled from the database in batches of row_limit as needed. If row_limit is less than or equal to 0, lazy_query is equivalent to query.

This can only be called inside of a transaction, and the Transaction object representing the active transaction must be passed to lazy_query.

Panics

Panics if the provided Transaction is not associated with the same Connection as this Statement, if the Transaction is not active, or if the number of parameters provided does not match the number of parameters expected.

fn finish(self) -> Result<()>

Consumes the statement, clearing it from the Postgres session.

If this statement was created via the prepare_cached method, finish does nothing.

Functionally identical to the Drop implementation of the Statement except that it returns any error to the caller.

Trait Implementations

impl<'a> Debug for Statement<'a>
[src]

fn fmt(&self, fmt: &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