Struct odbc_api::Preallocated[][src]

pub struct Preallocated<'open_connection> { /* fields omitted */ }
Expand description

A preallocated SQL statement handle intended for sequential execution of different queries. See crate::Connection::preallocate.

Example

use odbc_api::{Connection, Error};
use std::io::{self, stdin, Read};

fn interactive(conn: &Connection) -> io::Result<()>{
    let mut statement = conn.preallocate().unwrap();
    let mut query = String::new();
    stdin().read_line(&mut query)?;
    while !query.is_empty() {
        match statement.execute(&query, ()) {
            Err(e) => println!("{}", e),
            Ok(None) => println!("No results set generated."),
            Ok(Some(cursor)) => {
                // ...print cursor contents...
            },
        }
        stdin().read_line(&mut query)?;
    }
    Ok(())
}

Implementations

impl<'o> Preallocated<'o>[src]

pub fn execute_utf16(
    &mut self,
    query: &U16Str,
    params: impl ParameterCollection
) -> Result<Option<CursorImpl<'o, &mut StatementImpl<'o>>>, Error>
[src]

Executes an sql statement using a wide string. See Self::execute.

pub fn execute(
    &mut self,
    query: &str,
    params: impl ParameterCollection
) -> Result<Option<CursorImpl<'o, &mut StatementImpl<'o>>>, Error>
[src]

Executes a statement. This is the fastest way to sequentially execute different SQL Statements.

Parameters

  • query: The text representation of the SQL statement. E.g. “SELECT * FROM my_table;”.
  • params: ? may be used as a placeholder in the statement text. You can use () to represent no parameters. Check the crate::parameter module level documentation for more information on how to pass parameters.

Return

Returns Some if a cursor is created. If None is returned no cursor has been created ( e.g. the query came back empty). Note that an empty query may also create a cursor with zero rows. Since we want to reuse the statement handle a returned cursor will not take ownership of it and instead burrow it.

Example

use odbc_api::{Connection, Error};
use std::io::{self, stdin, Read};

fn interactive(conn: &Connection) -> io::Result<()>{
    let mut statement = conn.preallocate().unwrap();
    let mut query = String::new();
    stdin().read_line(&mut query)?;
    while !query.is_empty() {
        match statement.execute(&query, ()) {
            Err(e) => println!("{}", e),
            Ok(None) => println!("No results set generated."),
            Ok(Some(cursor)) => {
                // ...print cursor contents...
            },
        }
        stdin().read_line(&mut query)?;
    }
    Ok(())
}

pub fn into_statement(self) -> StatementImpl<'o>[src]

Transfer ownership to the underlying statemet handle.

The resulting type is one level of indirection away from the raw pointer of the ODBC API. It no longer has any guarantees about bound buffers, but is still guaranteed to be a valid allocated statement handle. This serves together with crate::handles::StatementImpl::into_sys or crate::handles::StatementImpl::as_sys this serves as an escape hatch to access the functionality provided by crate::sys not yet accessible through safe abstractions.

Auto Trait Implementations

impl<'open_connection> RefUnwindSafe for Preallocated<'open_connection>

impl<'open_connection> !Send for Preallocated<'open_connection>

impl<'open_connection> !Sync for Preallocated<'open_connection>

impl<'open_connection> Unpin for Preallocated<'open_connection>

impl<'open_connection> UnwindSafe for Preallocated<'open_connection>

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

pub fn type_id(&self) -> TypeId[src]

Gets the TypeId of self. Read more

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

pub fn borrow(&self) -> &T[src]

Immutably borrows from an owned value. Read more

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

pub fn borrow_mut(&mut self) -> &mut T[src]

Mutably borrows from an owned value. Read more

impl<T> From<T> for T[src]

pub fn from(t: T) -> T[src]

Performs the conversion.

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

pub fn into(self) -> U[src]

Performs the conversion.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>[src]

Performs the conversion.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

pub fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>[src]

Performs the conversion.