Struct odbc_api::parameter::VarCell

source ·
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:

Implementations§

source§

impl<K> VarCell<Box<[K::Element]>, K>
where K: VarKind,

source

pub fn null() -> Self

Constructs a ‘missing’ value.

source

pub fn from_vec(val: Vec<K::Element>) -> Self

Create a VarChar box from a Vec.

source§

impl<K> VarCell<Box<[u8]>, K>
where K: VarKind<Element = u8>,

source

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>
where K: VarKind<Element = u16>,

source

pub fn from_u16_string(val: U16String) -> Self

Create an owned parameter containing the character data from the passed string.

source

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>
where K: VarKind, B: Borrow<[K::Element]>,

source

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).

source

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]) { /*...*/}
source

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

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.

source

pub fn len_in_bytes(&self) -> Option<usize>

Length of the (potentially truncated) value within the cell in bytes. Excluding terminating zero.

source

pub fn capacity_in_bytes(&self) -> usize

The payload in bytes the buffer can hold including terminating zeroes

source§

impl<B, K> VarCell<B, K>
where B: Borrow<[K::Element]>, K: VarKind,

source

pub fn as_slice(&self) -> Option<&[K::Element]>

Valid payload of the buffer (excluding terminating zeroes) returned as slice or None in case the indicator is NULL_DATA.

source§

impl<B, K> VarCell<B, K>
where B: Borrow<[u8]>, K: VarKind<Element = u8>,

source

pub fn as_bytes(&self) -> Option<&[u8]>

Valid payload of the buffer (excluding terminating zeroes) returned as slice or None in case the indicator is NULL_DATA.

source§

impl<B> VarCell<B, Text>
where B: Borrow<[u8]>,

source

pub fn as_str(&self) -> Result<Option<&str>, Utf8Error>

source§

impl<B> VarCell<B, WideText>
where B: Borrow<[u16]>,

source

pub fn as_utf16(&self) -> Option<&U16Str>

source§

impl<'a, K> VarCell<&'a [u8], K>

source

pub const NULL: Self = _

Indicates missing data

source§

impl<'a, K> VarCell<&'a [u16], K>

source

pub const NULL: Self = _

Indicates missing data

source§

impl<'a, K> VarCell<&'a [K::Element], K>
where K: VarKind,

source

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.

source§

impl<const LENGTH: usize, K: VarKind> VarCell<[K::Element; LENGTH], K>

source

pub const NULL: Self = _

Indicates a missing value.

source

pub fn new(elements: &[K::Element]) -> Self

Construct from a slice. If value is longer than LENGTH it will be truncated. In that case the last byte will be set to 0.

Trait Implementations§

source§

impl<B, K> CData for VarCell<B, K>
where B: Borrow<[K::Element]>, K: VarKind,

source§

fn cdata_type(&self) -> CDataType

The identifier of the C data type of the value buffer. When it is retrieving data from the data source with 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

Indicates the length of variable sized types. May be zero for fixed sized types. Used to determine the size or existence of input parameters.
source§

fn value_ptr(&self) -> *const c_void

Pointer to a value corresponding to the one described by cdata_type.
source§

fn buffer_length(&self) -> isize

Maximum length of the type in bytes (not characters). It is required to index values in bound buffers, if more than one parameter is bound. Can be set to zero for types not bound as parameter arrays, i.e. CStr.
source§

impl<B, K> CDataMut for VarCell<B, K>
where B: BorrowMut<[K::Element]>, K: VarKind,

source§

fn mut_indicator_ptr(&mut self) -> *mut isize

Indicates the length of variable sized types. May be zero for fixed sized types.
source§

fn mut_value_ptr(&mut self) -> *mut c_void

Pointer to a value corresponding to the one described by cdata_type.
source§

impl<K: VarKind> CElement for VarCell<&[K::Element], K>

source§

fn assert_completness(&self)

Must panic if the parameter is not complete. I.e. the indicator of a variable length parameter indicates a value larger than what is present in the value buffer. Read more
source§

impl<K: VarKind> CElement for VarCell<&mut [K::Element], K>

source§

fn assert_completness(&self)

Must panic if the parameter is not complete. I.e. the indicator of a variable length parameter indicates a value larger than what is present in the value buffer. Read more
source§

impl<const LENGTH: usize, K: VarKind> CElement for VarCell<[K::Element; LENGTH], K>

source§

fn assert_completness(&self)

Must panic if the parameter is not complete. I.e. the indicator of a variable length parameter indicates a value larger than what is present in the value buffer. Read more
source§

impl<K: VarKind> CElement for VarCell<Box<[K::Element]>, K>

source§

fn assert_completness(&self)

Must panic if the parameter is not complete. I.e. the indicator of a variable length parameter indicates a value larger than what is present in the value buffer. Read more
source§

impl<B: Clone, K: Clone> Clone for VarCell<B, K>

source§

fn clone(&self) -> VarCell<B, K>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<B: Debug, K: Debug> Debug for VarCell<B, K>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<const LENGTH: usize, K, E> Default for VarCell<[E; LENGTH], K>
where E: Default + Copy,

source§

fn default() -> Self

Returns the “default value” for a type. Read more
source§

impl<B, K> HasDataType for VarCell<B, K>
where B: Borrow<[K::Element]>, K: VarKind,

source§

fn data_type(&self) -> DataType

The SQL data as which the parameter is bound to ODBC.
source§

impl<B: Copy, K: Copy> Copy for VarCell<B, K>

source§

impl<K: VarKind> OutputParameter for VarCell<&mut [K::Element], K>

source§

impl<const LENGTH: usize, K: VarKind> OutputParameter for VarCell<[K::Element; LENGTH], K>

source§

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>

§

impl<B, K> Send for VarCell<B, K>
where B: Send, K: Send,

§

impl<B, K> Sync for VarCell<B, K>
where B: Sync, K: Sync,

§

impl<B, K> Unpin for VarCell<B, K>
where B: Unpin, K: Unpin,

§

impl<B, K> UnwindSafe for VarCell<B, K>
where B: UnwindSafe, K: UnwindSafe,

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

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

source§

impl<T> IntoParameter for T
where T: InputParameter,

source§

impl<T> ParameterCollection for T
where T: InputParameterCollection + ?Sized,

source§

fn parameter_set_size(&self) -> usize

Number of values per parameter in the collection. This can be different from the maximum batch size a buffer may be able to hold. Returning 0 will cause the the query not to be executed.
source§

unsafe fn bind_parameters_to( &mut self, stmt: &mut impl Statement ) -> Result<(), Error>

Bind the parameters to a statement Read more
source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<T> InputParameter for T
where T: CElement + HasDataType,