[−][src]Struct amadeus::prelude::postgres::_internal::stmt::Statement
A prepared statement.
Methods
impl<'conn> Statement<'conn>
[src]
pub fn param_types(&self) -> &[Type]
[src]
Returns a slice containing the expected parameter types.
pub fn columns(&self) -> &[Column]
[src]
Returns a slice describing the columns of the result of the query.
pub fn execute(&self, params: &[&dyn ToSql]) -> Result<u64, Error>
[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);
pub fn query(&self, params: &[&dyn ToSql]) -> Result<Rows, Error>
[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); }
pub fn lazy_query(
&'stmt self,
trans: &'trans Transaction,
params: &[&dyn ToSql],
row_limit: i32
) -> Result<LazyRows<'trans, 'stmt>, Error>
[src]
&'stmt self,
trans: &'trans Transaction,
params: &[&dyn ToSql],
row_limit: i32
) -> Result<LazyRows<'trans, 'stmt>, Error>
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.
Examples
extern crate fallible_iterator; extern crate postgres; use fallible_iterator::FallibleIterator; let stmt = conn.prepare("SELECT foo FROM bar WHERE baz = $1").unwrap(); let trans = conn.transaction().unwrap(); let mut rows = stmt.lazy_query(&trans, &[&baz], 100).unwrap(); while let Some(row) = rows.next().unwrap() { let foo: i32 = row.get("foo"); println!("foo: {}", foo); }
pub fn copy_in<R>(&self, params: &[&dyn ToSql], r: &mut R) -> Result<u64, Error> where
R: ReadWithInfo,
[src]
R: ReadWithInfo,
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();
pub fn copy_out<W>(
&'a self,
params: &[&dyn ToSql],
w: &mut W
) -> Result<u64, Error> where
W: WriteWithInfo,
[src]
&'a self,
params: &[&dyn ToSql],
w: &mut W
) -> Result<u64, Error> where
W: WriteWithInfo,
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");
pub fn finish(self) -> Result<(), Error>
[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.
Trait Implementations
Auto Trait Implementations
impl<'conn> !Send for Statement<'conn>
impl<'conn> !Sync for Statement<'conn>
impl<'conn> Unpin for Statement<'conn>
impl<'conn> !UnwindSafe for Statement<'conn>
impl<'conn> !RefUnwindSafe for Statement<'conn>
Blanket Implementations
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> From<T> for T
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Same<T> for T
type Output = T
Should always be Self
impl<A, B> Downcast<A> for B where
A: DowncastImpl<B>,
[src]
A: DowncastImpl<B>,
fn downcast(self) -> Result<A, DowncastError>
[src]
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
V: MultiLane<T>,
fn vzip(self) -> V
impl<T> IntersectPlusUnionIsPlus for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> FromCast<T> for T
fn from_cast(t: T) -> T
impl<T, U> Cast<U> for T where
U: FromCast<T>,
U: FromCast<T>,
fn cast(self) -> U
impl<T> FromBits<T> for T
fn from_bits(t: T) -> T
impl<T, U> IntoBits<U> for T where
U: FromBits<T>,
U: FromBits<T>,
fn into_bits(self) -> U
impl<T> Type for T
[src]
const METATYPE: MetaType
[src]
type Meta = Concrete
Type of metadata for type.
fn meta(&self) -> <T as Type>::Meta
[src]
fn data(&self) -> *const ()
[src]
fn data_mut(&mut self) -> *mut ()
[src]
unsafe fn uninitialized_box(<T as Type>::Meta) -> Box<T>
[src]
fn meta_type(&self) -> MetaType
[src]
impl<T> Type for T where
T: ?Sized,
[src]
T: ?Sized,
default fn meta(&self) -> <T as Type>::Meta
[src]
default fn data(&self) -> *const ()
[src]
default fn data_mut(&mut self) -> *mut ()
[src]
unsafe default fn uninitialized_box(t: <T as Type>::Meta) -> Box<T>
[src]
const METATYPE: MetaType
[src]
type Meta: 'static
fn meta_type(&self) -> MetaType
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
U: TryFrom<T>,