aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2010-08-10 18:00:27 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2010-08-10 18:00:27 +0200
commit859d870ec5d44139bbe256a245424211bb813b73 (patch)
tree2848a3f17c0f1be97c80b537f8512e0aa5969763
parent19d689b4757f4d52c60032076b2023fa6aa30837 (diff)
Rework result/result_iterator interaction
-rw-r--r--odb/mysql/result.hxx6
-rw-r--r--odb/mysql/result.txx47
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;
}
}
}