From 1477f5d2ea334a4b57ac3720c30e4b29d10eec98 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Fri, 26 Nov 2010 15:48:28 +0200 Subject: 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. --- odb/result.hxx | 22 ++++++++++++++++++++-- 1 file 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_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. -- cgit v1.1