diff --git a/src/connection.rs b/src/connection.rs index 548924e..8fe3450 100644 --- a/src/connection.rs +++ b/src/connection.rs @@ -3,7 +3,7 @@ use libc::{c_char, c_int, c_void}; use std::marker::PhantomData; use std::path::Path; -use {Iterator, Result, Statement}; +use {Result, Statement}; /// A database connection. pub struct Connection { @@ -60,12 +60,6 @@ impl Connection { ::statement::new(self.raw, statement) } - /// Create an iterator over the resulting rows of a prepared statement. - #[inline] - pub fn iterate<'l, T: AsRef>(&'l self, statement: T) -> Result> { - ::iterator::new(try!(::statement::new(self.raw, statement))) - } - /// Set a callback for handling busy events. /// /// The callback is triggered when the database cannot perform an operation diff --git a/src/statement.rs b/src/statement.rs index f17c6f4..cc0b252 100644 --- a/src/statement.rs +++ b/src/statement.rs @@ -2,7 +2,7 @@ use ffi; use libc::{c_double, c_int}; use std::marker::PhantomData; -use {Result, Type, Value}; +use {Iterator, Result, Type, Value}; /// A prepared statement. pub struct Statement<'l> { @@ -100,6 +100,12 @@ impl<'l> Statement<'l> { self.state = None; Ok(()) } + + /// Upgrade the statement to an iterator. + #[inline] + pub fn into_iter(self) -> Result> { + ::iterator::new(self) + } } impl<'l> Drop for Statement<'l> { diff --git a/tests/lib.rs b/tests/lib.rs index f8d10ae..a6fb9b4 100644 --- a/tests/lib.rs +++ b/tests/lib.rs @@ -73,7 +73,7 @@ fn connection_set_busy_handler() { fn iterator() { let connection = setup(":memory:"); let statement = "SELECT id FROM users WHERE id = ?"; - let mut iterator = ok!(connection.iterate(statement)); + let mut iterator = ok!(connection.prepare(statement)).into_iter().unwrap(); ok!(iterator.start(&[Value::Integer(1)])); assert_eq!(ok!(ok!(iterator.next())), &[Value::Integer(1)]);