Skip to content

Commit 49110b0

Browse files
committed
Fix handling of empty result sets
1 parent ff70d97 commit 49110b0

File tree

2 files changed

+27
-6
lines changed

2 files changed

+27
-6
lines changed

src/queryable/mod.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,9 @@ where
113113

114114
/// Returns future that performs query. Result will be dropped.
115115
fn drop_query<Q: AsRef<str>>(self, query: Q) -> BoxFuture<Self> {
116-
let fut = self.query(query).and_then(|result| result.drop_result());
116+
let fut = self
117+
.query(query)
118+
.and_then(|result| result.drop_result());
117119
Box::new(fut)
118120
}
119121

src/queryable/query_result/mod.rs

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -204,13 +204,27 @@ where
204204
/// One could use it to check if there is more than one result set in this query result.
205205
pub fn is_empty(&self) -> bool {
206206
match *self {
207-
QueryResult(Empty(..)) => {
208-
!self.get_status().contains(StatusFlags::SERVER_MORE_RESULTS_EXISTS)
209-
},
207+
QueryResult(Empty(..)) => !self.more_results_exists(),
210208
_ => false,
211209
}
212210
}
213211

212+
/// Returns `true` if the SERVER_MORE_RESULTS_EXISTS flag is contained in status flags
213+
/// of the connection.
214+
fn more_results_exists(&self) -> bool {
215+
self.get_status().contains(StatusFlags::SERVER_MORE_RESULTS_EXISTS)
216+
}
217+
218+
/// `true` if rows may exists for this query result.
219+
///
220+
/// If `false` then there is no rows possible (for example UPDATE query).
221+
fn has_rows(&self) -> bool {
222+
match *self {
223+
QueryResult(Empty(..)) => false,
224+
_ => true,
225+
}
226+
}
227+
214228
/// Returns future that collects result set of this query result.
215229
///
216230
/// It is parametrized by `R` and internally calls `R::from_row(Row)` on each row.
@@ -337,8 +351,13 @@ where
337351

338352
/// Returns future that will drop this query result end resolve to a wrapped `Queryable`.
339353
pub fn drop_result(self) -> BoxFuture<T> {
340-
let fut = loop_fn(self, |this| if this.is_empty() {
341-
A(ok(Loop::Break(this.into_inner())))
354+
let fut = loop_fn(self, |this| if !this.has_rows() {
355+
if this.more_results_exists() {
356+
let (inner, cached) = this.into_inner();
357+
A(A(inner.read_result_set(cached).map(|new_this| Loop::Continue(new_this))))
358+
} else {
359+
A(B(ok(Loop::Break(this.into_inner()))))
360+
}
342361
} else {
343362
B(this.get_row_raw().map(|(this, _)| Loop::Continue(this)))
344363
});

0 commit comments

Comments
 (0)