From d83a7296e228cf0af74992020f51c566a03108c9 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Thu, 27 Oct 2011 15:16:49 +0200 Subject: Add support for persistent classes without object ids New pragma id (object). New test: common/no-id. --- odb/sqlite/object-result.txx | 115 ++++++++++++++++++++++++++++++++++++++----- 1 file changed, 102 insertions(+), 13 deletions(-) (limited to 'odb/sqlite/object-result.txx') diff --git a/odb/sqlite/object-result.txx b/odb/sqlite/object-result.txx index 6e3a0c9..dc258cc 100644 --- a/odb/sqlite/object-result.txx +++ b/odb/sqlite/object-result.txx @@ -12,17 +12,21 @@ namespace odb { namespace sqlite { + // + // object_result_impl + // + template - result_impl:: - ~result_impl () + object_result_impl:: + ~object_result_impl () { } template - result_impl:: - result_impl (const query& q, - details::shared_ptr statement, - object_statements& statements) + object_result_impl:: + object_result_impl (const query& q, + details::shared_ptr statement, + object_statements& statements) : base_type (statements.connection ().database ()), result_impl_base (q, statement), statements_ (statements) @@ -30,7 +34,7 @@ namespace odb } template - void result_impl:: + void object_result_impl:: load (object_type& obj) { load_image (); @@ -67,8 +71,8 @@ namespace odb } template - typename result_impl::id_type - result_impl:: + typename object_result_impl::id_type + object_result_impl:: load_id () { load_image (); @@ -76,7 +80,7 @@ namespace odb } template - void result_impl:: + void object_result_impl:: next () { this->current (pointer_type ()); @@ -86,7 +90,7 @@ namespace odb } template - void result_impl:: + void object_result_impl:: load_image () { // The image can grow between calls to load() as a result of other @@ -121,13 +125,98 @@ namespace odb } template - void result_impl:: + void object_result_impl:: + cache () + { + } + + template + std::size_t object_result_impl:: + size () + { + throw result_not_cached (); + } + + // + // object_result_impl_no_id + // + + template + object_result_impl_no_id:: + ~object_result_impl_no_id () + { + } + + template + object_result_impl_no_id:: + object_result_impl_no_id (const query& q, + details::shared_ptr statement, + object_statements_no_id& statements) + : base_type (statements.connection ().database ()), + result_impl_base (q, statement), + statements_ (statements) + { + } + + template + void object_result_impl_no_id:: + load (object_type& obj) + { + // The image can grow between calls to load() as a result of other + // statements execution. + // + typename object_traits::image_type& im (statements_.image ()); + + if (im.version != statements_.select_image_version ()) + { + binding& b (statements_.select_image_binding ()); + object_traits::bind (b.bind, im, statement_select); + statements_.select_image_version (im.version); + b.version++; + } + + select_statement::result r (statement_->load ()); + + if (r == select_statement::truncated) + { + if (object_traits::grow (im, statements_.select_image_truncated ())) + im.version++; + + if (im.version != statements_.select_image_version ()) + { + binding& b (statements_.select_image_binding ()); + object_traits::bind (b.bind, im, statement_select); + statements_.select_image_version (im.version); + b.version++; + statement_->reload (); + } + } + + odb::database& db (this->database ()); + + object_traits::callback (db, obj, callback_event::pre_load); + object_traits::init (obj, im, db); + object_traits::callback (db, obj, callback_event::post_load); + } + + template + void object_result_impl_no_id:: + next () + { + this->current (pointer_type ()); + + if (!statement_->next ()) + this->end_ = true; + } + + template + void object_result_impl_no_id:: cache () { } template - std::size_t result_impl:: + std::size_t object_result_impl_no_id:: size () { throw result_not_cached (); -- cgit v1.1