Struct postgres::stmt::Statement [] [src]

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

A prepared statement.

Methods

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

Returns a slice containing the expected parameter types.

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

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();
let rows_updated = stmt.execute(&[&bar, &baz]).unwrap();
println!("{} rows updated", rows_updated);

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();
for row in &stmt.query(&[&baz]).unwrap() {
    let foo: i32 = row.get("foo");
    println!("foo: {}", foo);
}

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.

Executes a COPY FROM STDIN statement, returning the number of rows added.

The contents of the provided reader are passed to the Postgres server verbatim; it is the caller's responsibility to ensure it uses the proper format. See the Postgres documentation for details.

If the statement is not a COPY FROM STDIN statement it will still be executed and this method will return an error.

Examples

conn.batch_execute("CREATE TABLE people (id INT PRIMARY KEY, name VARCHAR)").unwrap();
let stmt = conn.prepare("COPY people FROM STDIN").unwrap();
stmt.copy_in(&[], &mut "1\tjohn\n2\tjane\n".as_bytes()).unwrap();

Executes a COPY TO STDOUT statement, passing the resulting data to the provided writer and returning the number of rows received.

See the Postgres documentation for details on the data format.

If the statement is not a COPY TO STDOUT statement it will still be executed and this method will return an error.

Examples

conn.batch_execute("
        CREATE TABLE people (id INT PRIMARY KEY, name VARCHAR);
        INSERT INTO people (id, name) VALUES (1, 'john'), (2, 'jane');").unwrap();
let stmt = conn.prepare("COPY people TO STDOUT").unwrap();
let mut buf = vec![];
stmt.copy_out(&[], &mut buf).unwrap();
assert_eq!(buf, b"1\tjohn\n2\tjane\n");

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]

Formats the value using the given formatter.

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

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