From 2895ad78dbdb43e57fc34558b4530b4e105fc72d Mon Sep 17 00:00:00 2001 From: Karen Arutyunov Date: Thu, 1 Feb 2024 18:10:29 +0300 Subject: Turn libodb-mssql repository into package for muti-package repository --- libodb-mssql/odb/mssql/no-id-object-result.txx | 154 +++++++++++++++++++++++++ 1 file changed, 154 insertions(+) create mode 100644 libodb-mssql/odb/mssql/no-id-object-result.txx (limited to 'libodb-mssql/odb/mssql/no-id-object-result.txx') diff --git a/libodb-mssql/odb/mssql/no-id-object-result.txx b/libodb-mssql/odb/mssql/no-id-object-result.txx new file mode 100644 index 0000000..06b7d15 --- /dev/null +++ b/libodb-mssql/odb/mssql/no-id-object-result.txx @@ -0,0 +1,154 @@ +// file : odb/mssql/no-id-object-result.txx +// license : ODB NCUEL; see accompanying LICENSE file + +#include +#include // result_not_cached + +#include // long_data_reload +#include + +namespace odb +{ + namespace mssql + { + template + no_id_object_result_impl:: + ~no_id_object_result_impl () + { + invalidate (); + } + + template + void no_id_object_result_impl:: + invalidate () + { + change_callback_type& cc (statements_.image ().change_callback_); + + if (cc.context == this) + { + cc.callback = 0; + cc.context = 0; + } + + delete image_copy_; + image_copy_ = 0; + + if (!this->end_) + { + statement_->free_result (); + this->end_ = true; + } + + statement_.reset (); + } + + template + no_id_object_result_impl:: + no_id_object_result_impl (const query_base&, + details::shared_ptr statement, + statements_type& statements, + const schema_version_migration* svm) + : base_type (statements.connection ()), + statement_ (statement), + statements_ (statements), + tc_ (svm), + use_copy_ (false), + image_copy_ (0) + { + } + + template + void no_id_object_result_impl:: + load (object_type& obj) + { + if (!can_load_) + throw long_data_reload (); + + object_traits::callback (this->db_, obj, callback_event::pre_load); + + tc_.init (obj, + use_copy_ ? *image_copy_ : statements_.image (), + &this->db_); + + // If we are using a copy, make sure the callback information for + // long data also comes from the copy. + // + can_load_ = !statement_->stream_result ( + use_copy_ ? &statements_.image () : 0, + use_copy_ ? image_copy_ : 0); + + object_traits::callback (this->db_, obj, callback_event::post_load); + } + + template + void no_id_object_result_impl:: + next () + { + can_load_ = true; + this->current (pointer_type ()); + + typename object_traits::image_type& im (statements_.image ()); + change_callback_type& cc (im.change_callback_); + + if (cc.context == this) + { + cc.callback = 0; + cc.context = 0; + } + + use_copy_ = false; + + if (im.version != statements_.select_image_version ()) + { + binding& b (statements_.select_image_binding ()); + tc_.bind (b.bind, im, statement_select); + statements_.select_image_version (im.version); + b.version++; + } + + if (statement_->fetch () == select_statement::no_data) + { + statement_->free_result (); + this->end_ = true; + } + else + { + cc.callback = &change_callback; + cc.context = this; + } + } + + template + void no_id_object_result_impl:: + cache () + { + } + + template + std::size_t no_id_object_result_impl:: + size () + { + throw result_not_cached (); + } + + template + void no_id_object_result_impl:: + change_callback (void* c) + { + no_id_object_result_impl* r ( + static_cast*> (c)); + + typename object_traits::image_type im (r->statements_.image ()); + + if (r->image_copy_ == 0) + r->image_copy_ = new typename object_traits::image_type (im); + else + *r->image_copy_ = im; + + im.change_callback_.callback = 0; + im.change_callback_.context = 0; + + r->use_copy_ = true; + } + } +} -- cgit v1.1