aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2010-11-26 15:48:28 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2010-11-26 15:48:28 +0200
commit1477f5d2ea334a4b57ac3720c30e4b29d10eec98 (patch)
treeb57a9125703568361e0ea14c7401eb8b7a52b911
parent537873ae76666b201e6b9ee15e5172f2772f655a (diff)
Postpone fetching of the data for cached results
This way if an object of the same type is loaded in between iteration, the fetched image won't be messed up.
-rw-r--r--odb/result.hxx22
1 files changed, 20 insertions, 2 deletions
diff --git a/odb/result.hxx b/odb/result.hxx
index 54c369d..0ca7db1 100644
--- a/odb/result.hxx
+++ b/odb/result.hxx
@@ -45,7 +45,7 @@ namespace odb
typedef odb::object_traits<object_type> object_traits;
result_impl (database_type& db)
- : end_ (false), db_ (db), current_ ()
+ : begin_ (true), end_ (false), db_ (db), current_ ()
{
}
@@ -69,6 +69,16 @@ namespace odb
guard_.release ();
}
+ void
+ begin ()
+ {
+ if (begin_)
+ {
+ next ();
+ begin_ = false;
+ }
+ }
+
bool
end () const
{
@@ -99,6 +109,7 @@ namespace odb
guard_.reset (current_);
}
+ bool begin_;
bool end_;
private:
@@ -269,6 +280,9 @@ namespace odb
iterator
begin ()
{
+ if (impl_)
+ impl_->begin ();
+
return iterator (impl_.get ());
}
@@ -294,7 +308,11 @@ namespace odb
bool
empty () const
{
- return impl_ == 0 || impl_->end ();
+ if (impl_ == 0)
+ return true;
+
+ impl_->begin ();
+ return impl_->end ();
}
// Size is only known in cached results.