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§

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(())
}

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§

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. Read more
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. Read more
Retrieve the netxt batch of data from the source. Batches may not be empty. None indicates the last batch has been reached. Read more
Convinience function. Same as calling self::BlobParam::new.
The SQL data as which the parameter is bound to ODBC.

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

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

The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.