Struct odbc_api::parameter::VarChar[][src]

pub struct VarChar<B> { /* fields omitted */ }

Binds a byte arrary as Variadic sized characater 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

impl VarChar<Box<[u8], Global>>[src]

pub fn null() -> Self[src]

Constucts a ‘missing’ value.

pub fn from_string(val: String) -> Self[src]

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

pub fn from_vec(val: Vec<u8>) -> Self[src]

Create a VarChar box from a Vec.

impl<B> VarChar<B> where
    B: Borrow<[u8]>, 
[src]

pub fn from_buffer(buffer: B, indicator: Indicator) -> Self[src]

Creates a new instance from an existing buffer. Shoud the indicator be NoTotal or indicate a length longer than buffer, the last element in the buffer must be nul (\0).

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

Returns the binary representation of the string, excluding the terminating zero or None in case the indicator is NULL_DATA.

pub fn is_complete(&self) -> bool[src]

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<S: Statement>(
    col_index: u16,
    row: &mut CursorRow<S>
) -> 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]) { /*...*/}

pub fn indicator(&self) -> Indicator[src]

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, excluding the terminating zero. It may also be NULL_DATA to indicate NULL or NO_TOTAL which tells us the data source does not know how big the buffer must be to hold the complete value. NO_TOTAL implies that the content of the current buffer is valid up to its maximum capacity.

impl<B> VarChar<B> where
    B: Borrow<[u8]>, 
[src]

pub fn hide_truncation(&mut self)[src]

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.

impl<'a> VarChar<&'a [u8]>[src]

pub const NULL: Self[src]

Indicates missing data

pub fn new(value: &'a [u8]) -> Self[src]

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.

impl<const LENGTH: usize> VarChar<[u8; LENGTH]>[src]

pub const NULL: Self[src]

Indicates a missing value.

pub fn new(text: &[u8]) -> Self[src]

Construct from a slice. If value is longer than LENGTH it will be truncated and a a terminating zero is placed at the end.

Trait Implementations

impl<B> CData for VarChar<B> where
    B: Borrow<[u8]>, 
[src]

impl<B> CDataMut for VarChar<B> where
    B: BorrowMut<[u8]>, 
[src]

impl<B: Clone> Clone for VarChar<B>[src]

impl<B: Copy> Copy for VarChar<B>[src]

impl<B: Debug> Debug for VarChar<B>[src]

impl<B> HasDataType for VarChar<B> where
    B: Borrow<[u8]>, 
[src]

Auto Trait Implementations

impl<B> RefUnwindSafe for VarChar<B> where
    B: RefUnwindSafe

impl<B> Send for VarChar<B> where
    B: Send

impl<B> Sync for VarChar<B> where
    B: Sync

impl<B> Unpin for VarChar<B> where
    B: Unpin

impl<B> UnwindSafe for VarChar<B> where
    B: UnwindSafe

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.