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: boolIf 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: usizeMaximum 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>
impl<'a> BlobSlice<'a>
sourcepub fn from_byte_slice(blob: &'a [u8]) -> Self
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(())
}sourcepub fn from_text(text: &'a str) -> Self
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<'_>
impl Blob for BlobSlice<'_>
source§fn c_data_type(&self) -> CDataType
fn c_data_type(&self) -> CDataType
crate::sys::CDataType::Binary, crate::sys::CDataType::Char or
crate::sys::CDataType::WChar.source§fn size_hint(&self) -> Option<usize>
fn size_hint(&self) -> Option<usize>
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]>>
fn next_batch(&mut self) -> Result<Option<&[u8]>>
None indicates
the last batch has been reached.source§fn as_blob_param(&mut self) -> BlobParam<'_>where
Self: Sized,
fn as_blob_param(&mut self) -> BlobParam<'_>where
Self: Sized,
self::BlobParam::new.