pub struct PreallocatedPolling<'open_connection> { /* private fields */ }
Expand description

Asynchronous sibling of Preallocated using polling mode for execution. Can be obtained using Preallocated::into_polling.

Implementations§

source§

impl<'o> PreallocatedPolling<'o>

source

pub async fn execute( &mut self, query: &str, params: impl ParameterCollectionRef, sleep: impl Sleep ) -> Result<Option<CursorPolling<&mut StatementImpl<'o>>>, Error>

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

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.
  • sleep: Governs the polling intervals
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}, time::Duration};

/// Execute many different queries sequentially.
async fn execute_all(conn: &Connection<'_>, queries: &[&str]) -> Result<(), Error>{
    let mut statement = conn.preallocate()?.into_polling()?;
    let sleep = || tokio::time::sleep(Duration::from_millis(20));
    for query in queries {
        println!("Executing {query}");
        match statement.execute(&query, (), sleep).await {
            Err(e) => println!("{}", e),
            Ok(None) => println!("No results set generated."),
            Ok(Some(cursor)) => {
                // ...print cursor contents...
            },
        }
    }
    Ok(())
}

Trait Implementations§

source§

impl<'o> AsStatementRef for PreallocatedPolling<'o>

source§

fn as_stmt_ref(&mut self) -> StatementRef<'_>

Get an exclusive reference to the underlying statement handle. This method is used to implement other more higher level methods on top of it. It is not intended to be called by users of this crate directly, yet it may serve as an escape hatch for low level usecases.

Auto Trait Implementations§

§

impl<'open_connection> RefUnwindSafe for PreallocatedPolling<'open_connection>

§

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

§

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

§

impl<'open_connection> Unpin for PreallocatedPolling<'open_connection>

§

impl<'open_connection> UnwindSafe for PreallocatedPolling<'open_connection>

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

const: unstable · source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

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

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

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

The type returned in the event of a conversion error.
const: unstable · source§

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

Performs the conversion.