Modify Rows::next to tie its lifetime to the returned Row.

This means Rows no longer implements Iterator, but it is no longer
possible to misuse it by accessing a stale Row handle.
This commit is contained in:
John Gallagher
2016-05-18 11:33:58 -05:00
parent e695ed8f03
commit 30733a3688
4 changed files with 64 additions and 135 deletions

View File

@@ -90,7 +90,7 @@ impl<'conn> Statement<'conn> {
unsafe { self.execute_() }
}
/// Execute the prepared statement with named parameter(s), returning an iterator over the
/// Execute the prepared statement with named parameter(s), returning a handle for the
/// resulting rows. If any parameters that were in the prepared statement are not included in
/// `params`, they will continue to use the most-recently bound value from a previous call to
/// `query_named`, or `NULL` if they have never been bound.
@@ -102,7 +102,7 @@ impl<'conn> Statement<'conn> {
/// fn query(conn: &Connection) -> Result<()> {
/// let mut stmt = try!(conn.prepare("SELECT * FROM test where name = :name"));
/// let mut rows = try!(stmt.query_named(&[(":name", &"one")]));
/// for row in rows {
/// while let Some(row) = rows.next() {
/// // ...
/// }
/// Ok(())
@@ -117,6 +117,8 @@ impl<'conn> Statement<'conn> {
Ok(Rows::new(self))
}
// TODO: add query_map_named and query_and_then_named
fn bind_parameters_named(&mut self, params: &[(&str, &ToSql)]) -> Result<()> {
for &(name, value) in params {
if let Some(i) = try!(self.parameter_index(name)) {