pub struct VarCell<B, K> { /* private fields */ }
Expand description
Binds a byte array as Variadic sized character 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::VarCharSlice
- immutable borrowed narrow character stringsself::VarCharSliceMut
- mutable borrowed input / output narrow character stringsself::VarCharArray
- stack allocated owned input / output narrow character stringsself::VarCharBox
- heap allocated owned input /output narrow character stringsself::VarWCharSlice
- immutable borrowed wide character stringself::VarWCharSliceMut
- mutable borrowed input / output wide character stringself::VarWCharArray
- stack allocated owned input / output wide character stringself::VarWCharBox
- heap allocated owned input /output wide character stringself::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<K> VarCell<Box<[u8]>, K>
impl<K> VarCell<Box<[u8]>, K>
Sourcepub fn from_string(val: String) -> Self
pub fn from_string(val: String) -> Self
Create an owned parameter containing the character data from the passed string.
Source§impl<K> VarCell<Box<[u16]>, K>
impl<K> VarCell<Box<[u16]>, K>
Sourcepub fn from_u16_string(val: U16String) -> Self
pub fn from_u16_string(val: U16String) -> Self
Create an owned parameter containing the character data from the passed string.
Sourcepub fn from_str_slice(val: &str) -> Self
pub fn from_str_slice(val: &str) -> Self
Create an owned parameter containing the character data from the passed string. Converts it to UTF-16 and allocates it.
Source§impl<B, K> VarCell<B, K>
impl<B, K> VarCell<B, K>
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. For text should the indicator be NoTotal
or indicate a length longer than buffer, the last element in the buffer must be nul (\0
).
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::VarCharArray, Error, handles::Statement};
fn process_large_text(
col_index: u16,
row: &mut CursorRow<'_>
) -> Result<(), Error>{
let mut buf = VarCharArray::<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_text_slice(buf.as_bytes().unwrap());
}
Ok(())
}
fn process_text_slice(text: &[u8]) { /*...*/}
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.
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. Otherwise the behaviour of databases
in this situation is driver specific. Some drivers insert up to the terminating zero, others
detect the truncation and throw an error.
Sourcepub fn len_in_bytes(&self) -> Option<usize>
pub fn len_in_bytes(&self) -> Option<usize>
Length of the (potentially truncated) value within the cell in bytes. Excluding terminating zero.
Sourcepub fn capacity_in_bytes(&self) -> usize
pub fn capacity_in_bytes(&self) -> usize
The payload in bytes the buffer can hold including terminating zeroes
Source§impl<'a, K> VarCell<&'a [K::Element], K>where
K: VarKind,
impl<'a, K> VarCell<&'a [K::Element], K>where
K: VarKind,
Sourcepub fn new(value: &'a [K::Element]) -> Self
pub fn new(value: &'a [K::Element]) -> Self
Constructs a new VarChar containing the text in the specified buffer.
Caveat: This constructor is going to create a truncated value in case the input slice ends
with nul
. Should you want to insert an actual string those payload ends with nul
into
the database you need a buffer one byte longer than the string. You can instantiate such a
value using Self::from_buffer
.
Trait Implementations§
Source§impl<B, K> CData for VarCell<B, K>
impl<B, K> CData for VarCell<B, K>
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.Source§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
.Source§impl<B, K> CDataMut for VarCell<B, K>
impl<B, K> CDataMut for VarCell<B, K>
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
.Source§impl<K: VarKind> CElement for VarCell<&[K::Element], K>
impl<K: VarKind> CElement for VarCell<&[K::Element], K>
Source§fn assert_completness(&self)
fn assert_completness(&self)
Source§impl<K: VarKind> CElement for VarCell<&mut [K::Element], K>
impl<K: VarKind> CElement for VarCell<&mut [K::Element], K>
Source§fn assert_completness(&self)
fn assert_completness(&self)
Source§impl<const LENGTH: usize, K: VarKind> CElement for VarCell<[K::Element; LENGTH], K>
impl<const LENGTH: usize, K: VarKind> CElement for VarCell<[K::Element; LENGTH], K>
Source§fn assert_completness(&self)
fn assert_completness(&self)
Source§impl<K: VarKind> CElement for VarCell<Box<[K::Element]>, K>
impl<K: VarKind> CElement for VarCell<Box<[K::Element]>, K>
Source§fn assert_completness(&self)
fn assert_completness(&self)
Source§impl<B, K> HasDataType for VarCell<B, K>
impl<B, K> HasDataType for VarCell<B, K>
impl<B: Copy, K: Copy> Copy for VarCell<B, K>
impl<K: VarKind> OutputParameter for VarCell<&mut [K::Element], K>
impl<const LENGTH: usize, K: VarKind> OutputParameter for VarCell<[K::Element; LENGTH], K>
impl<K: VarKind> OutputParameter for VarCell<Box<[K::Element]>, K>
Auto Trait Implementations§
impl<B, K> Freeze for VarCell<B, K>where
B: Freeze,
impl<B, K> RefUnwindSafe for VarCell<B, K>where
B: RefUnwindSafe,
K: RefUnwindSafe,
impl<B, K> Send for VarCell<B, K>
impl<B, K> Sync for VarCell<B, K>
impl<B, K> Unpin for VarCell<B, K>
impl<B, K> UnwindSafe for VarCell<B, K>where
B: UnwindSafe,
K: UnwindSafe,
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)Source§impl<T> IntoParameter for Twhere
T: InputParameter,
impl<T> IntoParameter for Twhere
T: InputParameter,
type Parameter = T
fn into_parameter(self) -> <T as IntoParameter>::Parameter
Source§impl<T> ParameterCollection for Twhere
T: InputParameterCollection + ?Sized,
impl<T> ParameterCollection for Twhere
T: InputParameterCollection + ?Sized,
Source§fn parameter_set_size(&self) -> usize
fn parameter_set_size(&self) -> usize
0
will cause the the query not to be
executed.