odbc_api::parameter

Struct BlobSlice

Source
pub struct BlobSlice<'a> {
    pub is_binary: bool,
    pub batch_size: usize,
    pub blob: &'a [u8],
}
Expand description

Wraps borrowed bytes with a batch_size and implements self::Blob. Use this type to send long array of bytes to the database.

Fields§

§is_binary: bool

If true the blob is going to be bound as DataType::LongVarbinary and the bytes are interpreted as CDataType::Binary. If false the blob is going to be bound as DataType::LongVarchar and the bytes are interpreted as CDataType::Char.

§batch_size: usize

Maximum number of bytes transferred to the database in one go. May be largere than the remaining blob size.

§blob: &'a [u8]

Remaining bytes to transfer to the database.

Implementations§

Source§

impl<'a> BlobSlice<'a>

Source

pub fn from_byte_slice(blob: &'a [u8]) -> Self

Construct a Blob from a byte slice. The blob is going to be bound as a LongVarbinary and will be transmitted in one batch.

§Example
use odbc_api::{Connection, parameter::{Blob, BlobSlice}, IntoParameter, Error};

fn insert_image(
    conn: &Connection<'_>,
    id: &str,
    image_data: &[u8]
) -> Result<(), Error>
{
    let mut blob = BlobSlice::from_byte_slice(image_data);

    let insert = "INSERT INTO Images (id, image_data) VALUES (?,?)";
    let parameters = (&id.into_parameter(), &mut blob.as_blob_param());
    conn.execute(&insert, parameters)?;
    Ok(())
}
Source

pub fn from_text(text: &'a str) -> Self

Construct a Blob from a text slice. The blob is going to be bound as a LongVarchar and will be transmitted in one batch.

§Example

This example insert title as a normal input parameter but streams the potentially much longer String in text to the database as a large text blob. This allows to circumvent the size restrictions for String arguments of many drivers (usually around 4 or 8 KiB).

use odbc_api::{Connection, parameter::{Blob, BlobSlice}, IntoParameter, Error};

fn insert_book(
    conn: &Connection<'_>,
    title: &str,
    text: &str
) -> Result<(), Error>
{
    let mut blob = BlobSlice::from_text(&text);

    let insert = "INSERT INTO Books (title, text) VALUES (?,?)";
    let parameters = (&title.into_parameter(), &mut blob.as_blob_param());
    conn.execute(&insert, parameters)?;
    Ok(())
}

Trait Implementations§

Source§

impl Blob for BlobSlice<'_>

Source§

fn c_data_type(&self) -> CDataType

CData type of the binary data returned in the batches. Likely to be either crate::sys::CDataType::Binary, crate::sys::CDataType::Char or crate::sys::CDataType::WChar.
Source§

fn size_hint(&self) -> Option<usize>

Hint passed on to the driver regarding the combined size of all the batches. This hint is passed then the parameter is bound to the statement, so its meaning is only defined before the first call to next_batch. If None no hint about the total length of the batches is passed to the driver and the indicator will be set to crate::sys::DATA_AT_EXEC.
Source§

fn next_batch(&mut self) -> Result<Option<&[u8]>>

Retrieve the next batch of data from the source. Batches may not be empty. None indicates the last batch has been reached.
Source§

fn as_blob_param(&mut self) -> BlobParam<'_>
where Self: Sized,

Convinience function. Same as calling self::BlobParam::new.
Source§

impl HasDataType for BlobSlice<'_>

Source§

fn data_type(&self) -> DataType

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

Auto Trait Implementations§

§

impl<'a> Freeze for BlobSlice<'a>

§

impl<'a> RefUnwindSafe for BlobSlice<'a>

§

impl<'a> Send for BlobSlice<'a>

§

impl<'a> Sync for BlobSlice<'a>

§

impl<'a> Unpin for BlobSlice<'a>

§

impl<'a> UnwindSafe for BlobSlice<'a>

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> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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, 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> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more