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§

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§

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. Read more

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

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

The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.