Struct postgres::stmt::Statement
[−]
[src]
pub struct Statement<'conn> { /* fields omitted */ }
A prepared statement.
Methods
impl<'conn> Statement<'conn>
[src]
fn param_types(&self) -> &[Type]
[src]
Returns a slice containing the expected parameter types.
fn columns(&self) -> &[Column]
[src]
Returns a slice describing the columns of the result of the query.
fn execute(&self, params: &[&ToSql]) -> Result<u64>
[src]
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);
fn query(&self, params: &[&ToSql]) -> Result<Rows>
[src]
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); }
fn lazy_query<'trans, 'stmt>(
&'stmt self,
trans: &'trans Transaction,
params: &[&ToSql],
row_limit: i32
) -> Result<LazyRows<'trans, 'stmt>>
[src]
&'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 copy_in<R: ReadWithInfo>(&self, params: &[&ToSql], r: &mut R) -> Result<u64>
[src]
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();
fn copy_out<'a, W: WriteWithInfo>(
&'a self,
params: &[&ToSql],
w: &mut W
) -> Result<u64>
[src]
&'a self,
params: &[&ToSql],
w: &mut W
) -> Result<u64>
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");
fn finish(self) -> Result<()>
[src]
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.