odbc_api

Struct PreallocatedPolling

Source
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 use cases.

Auto Trait Implementations§

§

impl<'open_connection> Freeze for PreallocatedPolling<'open_connection>

§

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 T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

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

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 T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

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

Performs the conversion.
Source§

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

Source§

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

The type returned in the event of a conversion error.
Source§

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

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more