Merge pull request #261 from aidanhs/aphs-empty-blob-function

Fix functions for empty blobs
This commit is contained in:
John Gallagher 2017-05-29 10:02:22 -04:00 committed by GitHub
commit 33b7382ae7

View File

@ -158,15 +158,19 @@ impl<'a> ValueRef<'a> {
ValueRef::Text(s) ValueRef::Text(s)
} }
ffi::SQLITE_BLOB => { ffi::SQLITE_BLOB => {
let blob = ffi::sqlite3_value_blob(value); let (blob, len) = (ffi::sqlite3_value_blob(value), ffi::sqlite3_value_bytes(value));
assert!(!blob.is_null(),
"unexpected SQLITE_BLOB value type with NULL data");
let len = ffi::sqlite3_value_bytes(value);
assert!(len >= 0, assert!(len >= 0,
"unexpected negative return from sqlite3_value_bytes"); "unexpected negative return from sqlite3_value_bytes");
if len > 0 {
assert!(!blob.is_null(),
"unexpected SQLITE_BLOB value type with NULL data");
ValueRef::Blob(from_raw_parts(blob as *const u8, len as usize)) ValueRef::Blob(from_raw_parts(blob as *const u8, len as usize))
} else {
// The return value from sqlite3_value_blob() for a zero-length BLOB
// is a NULL pointer.
ValueRef::Blob(&[])
}
} }
_ => unreachable!("sqlite3_value_type returned invalid value"), _ => unreachable!("sqlite3_value_type returned invalid value"),
} }