mirror of
https://github.com/isar/rusqlite.git
synced 2024-11-26 11:31:37 +08:00
Introduce ZeoBlob struct.
This commit is contained in:
parent
0d317d2e23
commit
f488277373
@ -17,6 +17,7 @@
|
||||
//! extern crate rusqlite;
|
||||
//!
|
||||
//! use rusqlite::{Connection, DatabaseName};
|
||||
//! use rusqlite::types::ZeroBlob;
|
||||
//! use std::io::{Read, Write, Seek, SeekFrom};
|
||||
//!
|
||||
//! fn main() {
|
||||
@ -38,7 +39,7 @@
|
||||
//! let bytes_read = blob.read(&mut buf[..]).unwrap();
|
||||
//! assert_eq!(bytes_read, 10); // note we read 10 bytes because the blob has size 10
|
||||
//!
|
||||
//! db.execute("INSERT INTO test (content) VALUES (ZEROBLOB(64))", &[]).unwrap();
|
||||
//! db.execute("INSERT INTO test (content) VALUES (?)", &[&ZeroBlob(64)]).unwrap();
|
||||
//!
|
||||
//! // given a new row ID, we can reopen the blob on that row
|
||||
//! let rowid = db.last_insert_rowid();
|
||||
|
15
src/types.rs
15
src/types.rs
@ -194,6 +194,21 @@ impl ToSql for Null {
|
||||
}
|
||||
}
|
||||
|
||||
/// BLOB of length N that is filled with zeroes.
|
||||
/// Zeroblobs are intended to serve as placeholders for BLOBs whose content is later written using incremental BLOB I/O routines.
|
||||
/// A negative value for the zeroblob results in a zero-length BLOB.
|
||||
#[cfg(feature = "blob")]
|
||||
#[derive(Copy,Clone)]
|
||||
pub struct ZeroBlob(pub i32);
|
||||
|
||||
#[cfg(feature = "blob")]
|
||||
impl ToSql for ZeroBlob {
|
||||
unsafe fn bind_parameter(&self, stmt: *mut sqlite3_stmt, col: c_int) -> c_int {
|
||||
let ZeroBlob(length) = *self;
|
||||
ffi::sqlite3_bind_zeroblob(stmt, col, length)
|
||||
}
|
||||
}
|
||||
|
||||
macro_rules! raw_from_impl(
|
||||
($t:ty, $f:ident, $c:expr) => (
|
||||
impl FromSql for $t {
|
||||
|
Loading…
Reference in New Issue
Block a user