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
sourceimpl<'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
sourceimpl Blob for BlobSlice<'_>
impl Blob for BlobSlice<'_>
sourcefn c_data_type(&self) -> CDataType
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
. Read more
sourcefn size_hint(&self) -> Option<usize>
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
. Read more
sourcefn next_batch(&mut self) -> Result<Option<&[u8]>>
fn next_batch(&mut self) -> Result<Option<&[u8]>>
Retrieve the netxt batch of data from the source. Batches may not be empty. None
indicates
the last batch has been reached. Read more
sourcefn as_blob_param(&mut self) -> BlobParam<'_> where
Self: Sized,
fn as_blob_param(&mut self) -> BlobParam<'_> where
Self: Sized,
Convinience function. Same as calling self::BlobParam::new
.
Auto Trait Implementations
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
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more