Type Alias odbc_api::parameter::VarCharBox

source ·
pub type VarCharBox = VarChar<Box<[u8]>>;
Expand description

Parameter type for owned, variable sized narrow character data.

We use Box<[u8]> rather than Vec<u8> as a buffer type since the indicator pointer already has the role of telling us how many bytes in the buffer are part of the payload.

Aliased Type§

struct VarCharBox { /* private fields */ }

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<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 characters. 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<[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.

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<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<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<K: VarKind> CElement for VarCell<Box<[K::Element]>, K>

source§

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

source§

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