odbc_api::parameter

Struct 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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. 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,

Source§

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>,

Source§

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>,

Source§

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,