Add messages to all our assertions.

This commit is contained in:
John Gallagher 2015-05-04 20:02:33 -04:00
parent 98e7994251
commit 120f0cbb65
2 changed files with 13 additions and 4 deletions

View File

@ -592,7 +592,10 @@ impl<'conn> SqliteStatement<'conn> {
self.reset_if_needed(); self.reset_if_needed();
unsafe { unsafe {
assert_eq!(params.len() as c_int, ffi::sqlite3_bind_parameter_count(self.stmt)); assert!(params.len() as c_int == ffi::sqlite3_bind_parameter_count(self.stmt),
"incorrect number of parameters to execute(): expected {}, got {}",
ffi::sqlite3_bind_parameter_count(self.stmt),
params.len());
for (i, p) in params.iter().enumerate() { for (i, p) in params.iter().enumerate() {
try!(self.conn.decode_result(p.bind_parameter(self.stmt, (i + 1) as c_int))); try!(self.conn.decode_result(p.bind_parameter(self.stmt, (i + 1) as c_int)));
@ -632,7 +635,10 @@ impl<'conn> SqliteStatement<'conn> {
self.reset_if_needed(); self.reset_if_needed();
unsafe { unsafe {
assert_eq!(params.len() as c_int, ffi::sqlite3_bind_parameter_count(self.stmt)); assert!(params.len() as c_int == ffi::sqlite3_bind_parameter_count(self.stmt),
"incorrect number of parameters to query(): expected {}, got {}",
ffi::sqlite3_bind_parameter_count(self.stmt),
params.len());
for (i, p) in params.iter().enumerate() { for (i, p) in params.iter().enumerate() {
try!(self.conn.decode_result(p.bind_parameter(self.stmt, (i + 1) as c_int))); try!(self.conn.decode_result(p.bind_parameter(self.stmt, (i + 1) as c_int)));
@ -844,7 +850,7 @@ mod test {
END;"; END;";
db.execute_batch(sql).unwrap(); db.execute_batch(sql).unwrap();
} }
let path_string = path.to_str().unwrap(); let path_string = path.to_str().unwrap();
let db = SqliteConnection::open(&path_string).unwrap(); let db = SqliteConnection::open(&path_string).unwrap();
let the_answer = db.query_row_safe("SELECT x FROM foo", let the_answer = db.query_row_safe("SELECT x FROM foo",

View File

@ -195,7 +195,10 @@ impl FromSql for Vec<u8> {
let c_blob = ffi::sqlite3_column_blob(stmt, col); let c_blob = ffi::sqlite3_column_blob(stmt, col);
let len = ffi::sqlite3_column_bytes(stmt, col); let len = ffi::sqlite3_column_bytes(stmt, col);
assert!(len >= 0); let len = len as usize; // The documentation for sqlite3_column_bytes indicates it is always non-negative,
// but we should assert here just to be sure.
assert!(len >= 0, "unexpected negative return from sqlite3_column_bytes");
let len = len as usize;
Ok(from_raw_parts(mem::transmute(c_blob), len).to_vec()) Ok(from_raw_parts(mem::transmute(c_blob), len).to_vec())
} }