Do not assume sqlite3_column_text is valid UTF-8.

Fix Statement::value_ref
This commit is contained in:
gwenn
2019-07-22 21:07:53 +02:00
parent b7882380b2
commit f78ac1f2cf
2 changed files with 6 additions and 7 deletions

View File

@@ -601,10 +601,10 @@ impl Statement<'_> {
Statement { conn, stmt }
}
pub(crate) fn value_ref(&self, col: usize) -> ValueRef<'_> {
pub(crate) fn value_ref(&self, col: usize) -> Result<ValueRef<'_>> {
let raw = unsafe { self.stmt.ptr() };
match self.stmt.column_type(col) {
Ok(match self.stmt.column_type(col) {
ffi::SQLITE_NULL => ValueRef::Null,
ffi::SQLITE_INTEGER => {
ValueRef::Integer(unsafe { ffi::sqlite3_column_int64(raw, col as c_int) })
@@ -624,8 +624,7 @@ impl Statement<'_> {
// sqlite3_column_text returns UTF8 data, so our unwrap here should be fine.
let s = s
.to_str()
.expect("sqlite3_column_text returned invalid UTF-8");
.to_str()?;
ValueRef::Text(s)
}
ffi::SQLITE_BLOB => {
@@ -653,7 +652,7 @@ impl Statement<'_> {
}
}
_ => unreachable!("sqlite3_column_type returned invalid value"),
}
})
}
pub(crate) fn step(&self) -> Result<bool> {