pub struct VarBinary<B> { /* private fields */ }
Expand description
Binds a byte array as Variadic sized binary data. It can not be used for columnar bulk fetches, but if the buffer type is stack allocated it can be utilized in row wise bulk fetches.
Meaningful instantiations of this type are:
self::VarBinarySlice
- immutable borrowed parameter.self::VarBinarySliceMut
- mutable borrowed input / output parameterself::VarBinaryArray
- stack allocated owned input / output parameterself::VarBinaryBox
- heap allocated owned input /output parameter
Implementations§
source§impl<B> VarBinary<B>where
B: Borrow<[u8]>,
impl<B> VarBinary<B>where
B: Borrow<[u8]>,
sourcepub fn from_buffer(buffer: B, indicator: Indicator) -> Self
pub fn from_buffer(buffer: B, indicator: Indicator) -> Self
Creates a new instance from an existing buffer.
sourcepub fn as_bytes(&self) -> Option<&[u8]>
pub fn as_bytes(&self) -> Option<&[u8]>
Valid payload of the buffer returned as slice or None
in case the indicator is
NULL_DATA
.
sourcepub fn is_complete(&self) -> bool
pub fn is_complete(&self) -> bool
Call this method to ensure that the entire field content did fit into the buffer. If you
retrieve a field using crate::CursorRow::get_data
, you can repeat the call until this
method is false to read all the data.
use odbc_api::{CursorRow, parameter::VarBinaryArray, Error, handles::Statement};
fn process_large_binary(
col_index: u16,
row: &mut CursorRow<'_>
) -> Result<(), Error>{
let mut buf = VarBinaryArray::<512>::NULL;
row.get_data(col_index, &mut buf)?;
while !buf.is_complete() {
// Process bytes in stream without allocation. We can assume repeated calls to
// get_data do not return `None` since it would have done so on the first call.
process_slice(buf.as_bytes().unwrap());
}
Ok(())
}
fn process_slice(text: &[u8]) { /*...*/}
sourcepub fn indicator(&self) -> Indicator
pub fn indicator(&self) -> Indicator
Read access to the underlying ODBC indicator. After data has been fetched the indicator
value is set to the length the buffer should have had to hold the entire value. It may also
be Indicator::Null
to indicate NULL
or Indicator::NoTotal
which tells us the data
source does not know how big the buffer must be to hold the complete value.
Indicator::NoTotal
implies that the content of the current buffer is valid up to its
maximum capacity.
source§impl<B> VarBinary<B>where
B: Borrow<[u8]>,
impl<B> VarBinary<B>where
B: Borrow<[u8]>,
sourcepub fn hide_truncation(&mut self)
pub fn hide_truncation(&mut self)
Call this method to reset the indicator to a value which matches the length returned by the
Self::as_bytes
method. This is useful if you want to insert values into the database
despite the fact, that they might have been truncated.
Trait Implementations§
source§impl<B> CData for VarBinary<B>where
B: Borrow<[u8]>,
impl<B> CData for VarBinary<B>where
B: Borrow<[u8]>,
source§fn cdata_type(&self) -> CDataType
fn cdata_type(&self) -> CDataType
fetch
, the driver converts the data to this type. When it sends data to
the source, the driver converts the data from this type. Read moresource§fn indicator_ptr(&self) -> *const isize
fn indicator_ptr(&self) -> *const isize
source§fn value_ptr(&self) -> *const c_void
fn value_ptr(&self) -> *const c_void
cdata_type
.source§fn buffer_length(&self) -> isize
fn buffer_length(&self) -> isize
CStr
. Read moresource§impl<B> CDataMut for VarBinary<B>where
B: BorrowMut<[u8]>,
impl<B> CDataMut for VarBinary<B>where
B: BorrowMut<[u8]>,
source§fn mut_indicator_ptr(&mut self) -> *mut isize
fn mut_indicator_ptr(&mut self) -> *mut isize
source§fn mut_value_ptr(&mut self) -> *mut c_void
fn mut_value_ptr(&mut self) -> *mut c_void
cdata_type
.