mirror of
https://github.com/isar/rusqlite.git
synced 2024-11-26 11:31:37 +08:00
Add messages to all our assertions.
This commit is contained in:
parent
98e7994251
commit
120f0cbb65
12
src/lib.rs
12
src/lib.rs
@ -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",
|
||||||
|
@ -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())
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user