mirror of
https://github.com/isar/rusqlite.git
synced 2024-11-23 09:09:19 +08:00
commit
bf8c495b69
@ -1123,12 +1123,17 @@ impl<'a> ValueRef<'a> {
|
|||||||
}
|
}
|
||||||
ffi::SQLITE_BLOB => {
|
ffi::SQLITE_BLOB => {
|
||||||
let blob = ffi::sqlite3_column_blob(raw, col);
|
let blob = ffi::sqlite3_column_blob(raw, col);
|
||||||
assert!(!blob.is_null(), "unexpected SQLITE_BLOB column type with NULL data");
|
|
||||||
|
|
||||||
let len = ffi::sqlite3_column_bytes(raw, col);
|
let len = ffi::sqlite3_column_bytes(raw, col);
|
||||||
assert!(len >= 0, "unexpected negative return from sqlite3_column_bytes");
|
assert!(len >= 0, "unexpected negative return from sqlite3_column_bytes");
|
||||||
|
if len > 0 {
|
||||||
|
assert!(!blob.is_null(), "unexpected SQLITE_BLOB column type with NULL data");
|
||||||
|
ValueRef::Blob(from_raw_parts(blob as *const u8, len as usize))
|
||||||
|
} else {
|
||||||
|
// The return value from sqlite3_column_blob() for a zero-length BLOB is a NULL pointer.
|
||||||
|
ValueRef::Blob(&[])
|
||||||
|
}
|
||||||
|
|
||||||
ValueRef::Blob(from_raw_parts(blob as *const u8, len as usize))
|
|
||||||
}
|
}
|
||||||
_ => unreachable!("sqlite3_column_type returned invalid value")
|
_ => unreachable!("sqlite3_column_type returned invalid value")
|
||||||
}
|
}
|
||||||
|
@ -129,6 +129,17 @@ mod test {
|
|||||||
assert_eq!(v, v1234);
|
assert_eq!(v, v1234);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_empty_blob() {
|
||||||
|
let db = checked_memory_handle();
|
||||||
|
|
||||||
|
let empty = vec![];
|
||||||
|
db.execute("INSERT INTO foo(b) VALUES (?)", &[&empty]).unwrap();
|
||||||
|
|
||||||
|
let v: Vec<u8> = db.query_row("SELECT b FROM foo", &[], |r| r.get(0)).unwrap();
|
||||||
|
assert_eq!(v, empty);
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_str() {
|
fn test_str() {
|
||||||
let db = checked_memory_handle();
|
let db = checked_memory_handle();
|
||||||
|
Loading…
Reference in New Issue
Block a user