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>
impl<'o> PreallocatedPolling<'o>
Sourcepub async fn execute(
&mut self,
query: &str,
params: impl ParameterCollectionRef,
sleep: impl Sleep,
) -> Result<Option<CursorPolling<&mut StatementImpl<'o>>>, Error>
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 thecrate::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>
impl<'o> AsStatementRef for PreallocatedPolling<'o>
Source§fn as_stmt_ref(&mut self) -> StatementRef<'_>
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more