From d9f372d7b1bc1abbff5fdf9735118290cd024d5e Mon Sep 17 00:00:00 2001 From: Karen Arutyunov Date: Thu, 25 Jan 2024 17:28:38 +0300 Subject: Turn libodb-pgsql repository into package for muti-package repository --- libodb-pgsql/odb/pgsql/view-result.txx | 114 +++++++++++++++++++++++++++++++++ 1 file changed, 114 insertions(+) create mode 100644 libodb-pgsql/odb/pgsql/view-result.txx (limited to 'libodb-pgsql/odb/pgsql/view-result.txx') diff --git a/libodb-pgsql/odb/pgsql/view-result.txx b/libodb-pgsql/odb/pgsql/view-result.txx new file mode 100644 index 0000000..980811a --- /dev/null +++ b/libodb-pgsql/odb/pgsql/view-result.txx @@ -0,0 +1,114 @@ +// file : odb/pgsql/view-result.txx +// license : GNU GPL v2; see accompanying LICENSE file + +#include + +#include + +namespace odb +{ + namespace pgsql + { + template + view_result_impl:: + ~view_result_impl () + { + if (!this->end_) + statement_->free_result (); + } + + template + void view_result_impl:: + invalidate () + { + if (!this->end_) + { + statement_->free_result (); + this->end_ = true; + } + + statement_.reset (); + } + + template + view_result_impl:: + view_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), + count_ (0) + { + } + + template + void view_result_impl:: + load (view_type& view) + { + // The image can grow between calls to load() as a result of other + // statements execution. + // + typename view_traits::image_type& im (statements_.image ()); + + if (im.version != statements_.image_version ()) + { + binding& b (statements_.image_binding ()); + tc_.bind (b.bind, im); + statements_.image_version (im.version); + b.version++; + } + + select_statement::result r (statement_->load ()); + + if (r == select_statement::truncated) + { + if (tc_.grow (im, statements_.image_truncated ())) + im.version++; + + if (im.version != statements_.image_version ()) + { + binding& b (statements_.image_binding ()); + tc_.bind (b.bind, im); + statements_.image_version (im.version); + b.version++; + statement_->reload (); + } + } + + view_traits::callback (this->db_, view, callback_event::pre_load); + tc_.init (view, im, &this->db_); + view_traits::callback (this->db_, view, callback_event::post_load); + } + + template + void view_result_impl:: + next () + { + this->current (pointer_type ()); + + if (statement_->next ()) + count_++; + else + { + statement_->free_result (); + this->end_ = true; + } + } + + template + void view_result_impl:: + cache () + { + } + + template + std::size_t view_result_impl:: + size () + { + return this->end_ ? count_ : statement_->result_size (); + } + } +} -- cgit v1.1