Struct odbc_api::RowSetCursor
source · pub struct RowSetCursor<C: AsStatementRef, B> { /* private fields */ }
Expand description
Iterates in blocks (called row sets) over a result set, filling a buffers with a lot of rows at once, instead of iterating the result set row by row. This is usually much faster.
Implementations
sourceimpl<C, B> RowSetCursor<C, B>where
C: Cursor,
impl<C, B> RowSetCursor<C, B>where
C: Cursor,
sourcepub fn fetch(&mut self) -> Result<Option<&B>, Error>
pub fn fetch(&mut self) -> Result<Option<&B>, Error>
Fills the bound buffer with the next row set.
Return
None
if the result set is empty and all row sets have been extracted. Some
with a
reference to the internal buffer otherwise.
use odbc_api::{buffers::TextRowSet, Cursor};
fn print_all_values(mut cursor: impl Cursor) {
let batch_size = 100;
let max_string_len = 4000;
let buffer = TextRowSet::for_cursor(batch_size, &mut cursor, Some(4000)).unwrap();
let mut cursor = cursor.bind_buffer(buffer).unwrap();
// Iterate over batches
while let Some(batch) = cursor.fetch().unwrap() {
// ... print values in batch ...
}
}
sourcepub fn fetch_with_truncation_check(
&mut self,
error_for_truncation: bool
) -> Result<Option<&B>, Error>
pub fn fetch_with_truncation_check(
&mut self,
error_for_truncation: bool
) -> Result<Option<&B>, Error>
Fills the bound buffer with the next row set. Should error_for_truncation
be true
and any
diagnostic indicate truncation of a value an error is returned.
Return
None
if the result set is empty and all row sets have been extracted. Some
with a
reference to the internal buffer otherwise.
Call this method to find out wether there are any truncated values in the batch, without inspecting all its rows and columns.
use odbc_api::{buffers::TextRowSet, Cursor};
fn print_all_values(mut cursor: impl Cursor) {
let batch_size = 100;
let max_string_len = 4000;
let buffer = TextRowSet::for_cursor(batch_size, &mut cursor, Some(4000)).unwrap();
let mut cursor = cursor.bind_buffer(buffer).unwrap();
// Iterate over batches
while let Some(batch) = cursor.fetch_with_truncation_check(true).unwrap() {
// ... print values in batch ...
}
}