diff options
author | Boris Kolpackov <boris@codesynthesis.com> | 2012-09-28 14:42:23 +0200 |
---|---|---|
committer | Boris Kolpackov <boris@codesynthesis.com> | 2012-09-28 14:42:23 +0200 |
commit | ecfffbc56def1cfc87d34a70c0fb9f9241459e54 (patch) | |
tree | de559cf9bea8ed8454cdf145bfee495eb777400c | |
parent | 050e97d3a7f34ce4a278e0c9788f65651bc2a34c (diff) |
Make sure size() can still be called once we reached the end of result set
-rw-r--r-- | odb/mysql/no-id-object-result.txx | 15 | ||||
-rw-r--r-- | odb/mysql/polymorphic-object-result.txx | 15 | ||||
-rw-r--r-- | odb/mysql/simple-object-result.txx | 15 | ||||
-rw-r--r-- | odb/mysql/view-result.txx | 15 |
4 files changed, 44 insertions, 16 deletions
diff --git a/odb/mysql/no-id-object-result.txx b/odb/mysql/no-id-object-result.txx index 864b49d..6418987 100644 --- a/odb/mysql/no-id-object-result.txx +++ b/odb/mysql/no-id-object-result.txx @@ -133,7 +133,7 @@ namespace odb void no_id_object_result_impl<T>:: cache () { - if (!statement_->cached ()) + if (!this->end_ && !statement_->cached ()) { statement_->cache (); @@ -149,10 +149,17 @@ namespace odb std::size_t no_id_object_result_impl<T>:: size () { - if (!statement_->cached ()) - throw result_not_cached (); + if (!this->end_) + { + if (!statement_->cached ()) + throw result_not_cached (); - return statement_->result_size (); + return statement_->result_size (); + } + else + // If count is not zero, then it is one past the result size. + // + return count_ == 0 ? 0 : count_ - 1; } } } diff --git a/odb/mysql/polymorphic-object-result.txx b/odb/mysql/polymorphic-object-result.txx index 221060b..5fe5b48 100644 --- a/odb/mysql/polymorphic-object-result.txx +++ b/odb/mysql/polymorphic-object-result.txx @@ -318,7 +318,7 @@ namespace odb void polymorphic_object_result_impl<T>:: cache () { - if (!statement_->cached ()) + if (!this->end_ && !statement_->cached ()) { statement_->cache (); @@ -334,10 +334,17 @@ namespace odb std::size_t polymorphic_object_result_impl<T>:: size () { - if (!statement_->cached ()) - throw result_not_cached (); + if (!this->end_) + { + if (!statement_->cached ()) + throw result_not_cached (); - return statement_->result_size (); + return statement_->result_size (); + } + else + // If count is not zero, then it is one past the result size. + // + return count_ == 0 ? 0 : count_ - 1; } } } diff --git a/odb/mysql/simple-object-result.txx b/odb/mysql/simple-object-result.txx index f77f83e..f67827c 100644 --- a/odb/mysql/simple-object-result.txx +++ b/odb/mysql/simple-object-result.txx @@ -189,7 +189,7 @@ namespace odb void object_result_impl<T>:: cache () { - if (!statement_->cached ()) + if (!this->end_ && !statement_->cached ()) { statement_->cache (); @@ -205,10 +205,17 @@ namespace odb std::size_t object_result_impl<T>:: size () { - if (!statement_->cached ()) - throw result_not_cached (); + if (!this->end_) + { + if (!statement_->cached ()) + throw result_not_cached (); - return statement_->result_size (); + return statement_->result_size (); + } + else + // If count is not zero, then it is one past the result size. + // + return count_ == 0 ? 0 : count_ - 1; } } } diff --git a/odb/mysql/view-result.txx b/odb/mysql/view-result.txx index f6060ea..cc5178e 100644 --- a/odb/mysql/view-result.txx +++ b/odb/mysql/view-result.txx @@ -132,7 +132,7 @@ namespace odb void view_result_impl<T>:: cache () { - if (!statement_->cached ()) + if (!this->end_ && !statement_->cached ()) { statement_->cache (); @@ -148,10 +148,17 @@ namespace odb std::size_t view_result_impl<T>:: size () { - if (!statement_->cached ()) - throw result_not_cached (); + if (!this->end_) + { + if (!statement_->cached ()) + throw result_not_cached (); - return statement_->result_size (); + return statement_->result_size (); + } + else + // If count is not zero, then it is one past the result size. + // + return count_ == 0 ? 0 : count_ - 1; } } } |