Reset the state after Cursor’s bind

This commit is contained in:
Ivan Ukhov 2015-08-03 17:28:48 -04:00
parent 0e41f32222
commit c5efaedc73
2 changed files with 6 additions and 2 deletions

View File

@ -11,6 +11,7 @@ pub struct Cursor<'l> {
impl<'l> Cursor<'l> {
/// Bind values to all parameters.
pub fn bind(&mut self, values: &[Value]) -> Result<()> {
self.state = None;
try!(self.statement.reset());
for (i, value) in values.iter().enumerate() {
try!(self.statement.bind(i + 1, value));

View File

@ -76,8 +76,11 @@ fn cursor() {
let mut cursor = ok!(connection.prepare(statement)).cursor().unwrap();
ok!(cursor.bind(&[Value::Integer(1)]));
assert_eq!(ok!(ok!(cursor.next())), &[Value::Integer(1),
Value::String("Alice".to_string())]);
assert_eq!(ok!(ok!(cursor.next())), &[Value::Integer(1), Value::String("Alice".to_string())]);
assert_eq!(ok!(cursor.next()), None);
ok!(cursor.bind(&[Value::Integer(1)]));
assert_eq!(ok!(ok!(cursor.next())), &[Value::Integer(1), Value::String("Alice".to_string())]);
assert_eq!(ok!(cursor.next()), None);
ok!(cursor.bind(&[Value::Integer(42)]));