Only check column count when DONE.

This commit is contained in:
gwenn 2015-08-01 09:11:31 +02:00
parent 1dc144c8c1
commit c31c68d5e3

View File

@ -625,13 +625,18 @@ impl<'conn> SqliteStatement<'conn> {
self.needs_reset = true; self.needs_reset = true;
let r = ffi::sqlite3_step(self.stmt); let r = ffi::sqlite3_step(self.stmt);
if r == ffi::SQLITE_ROW || self.column_count() != 0 { match r {
Err(SqliteError{ code: r, ffi::SQLITE_DONE => {
message: "Unexpected row result - did you mean to call query?".to_string() }) if self.column_count() != 0 {
} else if r == ffi::SQLITE_DONE { Err(SqliteError{ code: ffi::SQLITE_MISUSE,
Ok(self.conn.changes()) message: "Unexpected column count - did you mean to call query?".to_string() })
} else { } else {
Err(self.conn.decode_result(r).unwrap_err()) Ok(self.conn.changes())
}
},
ffi::SQLITE_ROW => Err(SqliteError{ code: r,
message: "Unexpected row result - did you mean to call query?".to_string() }),
_ => Err(self.conn.decode_result(r).unwrap_err()),
} }
} }
} }
@ -1003,8 +1008,8 @@ mod test {
fn test_execute_select() { fn test_execute_select() {
let db = checked_memory_handle(); let db = checked_memory_handle();
let err = db.execute("SELECT 1 WHERE 1 < ?", &[&1i32]).unwrap_err(); let err = db.execute("SELECT 1 WHERE 1 < ?", &[&1i32]).unwrap_err();
assert!(err.code == ffi::SQLITE_DONE); assert!(err.code == ffi::SQLITE_MISUSE);
assert!(err.message == "Unexpected row result - did you mean to call query?"); assert!(err.message == "Unexpected column count - did you mean to call query?");
} }
#[test] #[test]