diff options
-rw-r--r-- | odb/exceptions.cxx | 6 | ||||
-rw-r--r-- | odb/exceptions.hxx | 6 | ||||
-rw-r--r-- | odb/result.hxx | 40 |
3 files changed, 46 insertions, 6 deletions
diff --git a/odb/exceptions.cxx b/odb/exceptions.cxx index b27cc37..597f40d 100644 --- a/odb/exceptions.cxx +++ b/odb/exceptions.cxx @@ -37,6 +37,12 @@ namespace odb return "object not persistent"; } + const char* result_not_cached:: + what () const throw () + { + return "query result in not cached"; + } + const char* object_already_persistent:: what () const throw () { diff --git a/odb/exceptions.hxx b/odb/exceptions.hxx index 8c9e826..8c0fe27 100644 --- a/odb/exceptions.hxx +++ b/odb/exceptions.hxx @@ -50,6 +50,12 @@ namespace odb what () const throw (); }; + struct LIBODB_EXPORT result_not_cached: odb::exception + { + virtual const char* + what () const throw (); + }; + struct LIBODB_EXPORT database_exception: odb::exception { }; diff --git a/odb/result.hxx b/odb/result.hxx index eb7f370..9f7dcb0 100644 --- a/odb/result.hxx +++ b/odb/result.hxx @@ -76,6 +76,9 @@ namespace odb virtual void cache () = 0; + virtual std::size_t + size () = 0; + protected: void current (pointer_type p) @@ -233,6 +236,29 @@ namespace odb return *this; } + void + swap (result& r) + { + // @@ add swap() to shared_ptr. + // + details::shared_ptr<result_impl<T> > p (impl_); + impl_ = r.impl_; + r.impl_ = p; + } + + public: + iterator + begin () + { + return iterator (impl_.get ()); + } + + iterator + end () + { + return iterator (); + } + // Cache the result instead of fetching the data from the database // one object at a time. This is necessary if you plan on performing // database operations while iterating over the result. @@ -246,16 +272,18 @@ namespace odb } public: - iterator - begin () + bool + empty () const { - return iterator (impl_.get ()); + return impl_ == 0 || impl_->end (); } - iterator - end () + // Size is only known in cached results. + // + size_type + size () const { - return iterator (); + return impl_ ? impl_->size () : 0; } private: |