diff options
-rw-r--r-- | odb/mysql/result.hxx | 6 | ||||
-rw-r--r-- | odb/mysql/result.txx | 47 |
2 files changed, 29 insertions, 24 deletions
diff --git a/odb/mysql/result.hxx b/odb/mysql/result.hxx index 52d5b72..0f01ff9 100644 --- a/odb/mysql/result.hxx +++ b/odb/mysql/result.hxx @@ -31,8 +31,8 @@ namespace odb result_impl (shared_ptr<query_statement> statement, object_statements<T>& statements); - pointer_type - current (bool release); + virtual void + current (); virtual void current (T&); @@ -41,10 +41,8 @@ namespace odb next (); private: - pointer_type cur_; shared_ptr<query_statement> statement_; object_statements<T>& statements_; - query_statement::result state_; }; } } diff --git a/odb/mysql/result.txx b/odb/mysql/result.txx index 39100ab..debb725 100644 --- a/odb/mysql/result.txx +++ b/odb/mysql/result.txx @@ -23,26 +23,22 @@ namespace odb } template <typename T> - typename result_impl<T>::pointer_type result_impl<T>:: - current (bool release) + void result_impl<T>:: + current () { - if (!pointer_ops::null_ptr (cur_)) - return cur_; - - if (state_ == query_statement::success) + if (!this->end_) { - cur_ = traits::create (); - traits::init (pointer_ops::get_ref (cur_), statements_.image ()); + this->current_ = traits::create (); + traits::init (pointer_ops::get_ref (this->current_), + statements_.image ()); } - - return cur_; } template <typename T> void result_impl<T>:: current (T& x) { - if (state_ == query_statement::success) + if (!this->end_) traits::init (x, statements_.image ()); } @@ -50,20 +46,31 @@ namespace odb void result_impl<T>:: next () { - cur_ = pointer_type (); - state_ = statement_->fetch (); + this->current_ = pointer_type (); + query_statement::result r (statement_->fetch ()); - if (state_ == query_statement::truncated) + switch (r) { - typename traits::image_type& i (statements_.image ()); + case query_statement::truncated: + { + typename traits::image_type& i (statements_.image ()); - if (traits::grow (i, statements_.image_error ())) + if (traits::grow (i, statements_.image_error ())) + { + traits::bind (statements_.image_binding (), i); + statement_->refetch (); + } + // Fall throught. + } + case query_statement::success: { - traits::bind (statements_.image_binding (), i); - statement_->refetch (); + break; + } + case query_statement::no_data: + { + this->end_ = true; + break; } - - state_ == query_statement::success; } } } |