From 32613d718b36a6c400d6f05da50d30b3fd25c3b8 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Tue, 5 Feb 2013 15:50:07 +0200 Subject: Add support for change-tracking containers ODB now supports "smart" ordered containers. Such containers get extra functions for updating and deleting individual elements. Based on this functionality implement two change-tracking containers: odb::vector (equivalent to std::vector) and QOdbList (equivalent to QList). New tests: common/container/change-tracking and qt/common/container/change- tracking. --- odb/sqlite/container-statements.txx | 79 ++++++++++++++++++++++++++----------- 1 file changed, 56 insertions(+), 23 deletions(-) (limited to 'odb/sqlite/container-statements.txx') diff --git a/odb/sqlite/container-statements.txx b/odb/sqlite/container-statements.txx index 19ecfdc..4d575b7 100644 --- a/odb/sqlite/container-statements.txx +++ b/odb/sqlite/container-statements.txx @@ -11,48 +11,61 @@ namespace odb { // container_statements // - template container_statements:: - container_statements (connection_type& conn) + container_statements (connection_type& conn, binding& id) : conn_ (conn), - functions_ (this, - &traits::insert_one, - &traits::load_all, - &traits::delete_all), - id_binding_ (0), + id_binding_ (id), + functions_ (this), + insert_image_binding_ (0, 0), // Initialized by impl. + select_image_binding_ (0, 0) // Initialized by impl. + { + functions_.insert_ = &traits::insert; + functions_.select_ = &traits::select; + functions_.delete__ = &traits::delete_; + + data_image_.version = 0; + data_image_version_ = 0; + data_id_binding_version_ = 0; + } + + // smart_container_statements + // + template + smart_container_statements:: + smart_container_statements (connection_type& conn, binding& id) + : container_statements (conn, id), cond_image_binding_ (0, 0), // Initialized by impl. - data_image_binding_ (0, 0), // Initialized by impl. - select_image_binding_ (0, 0) // Initialized by impl. + update_image_binding_ (0, 0) // Initialized by impl. { + this->functions_.update_ = &traits::update; + cond_image_.version = 0; cond_image_version_ = 0; cond_id_binding_version_ = 0; - data_image_.version = 0; - data_image_version_ = 0; - data_id_binding_version_ = 0; + update_id_binding_version_ = 0; + update_cond_image_version_ = 0; + update_data_image_version_ = 0; } + // container_statements_impl + // template container_statements_impl:: - container_statements_impl (connection_type& conn) - : base (conn) + container_statements_impl (connection_type& conn, binding& id) + : base (conn, id) { this->select_image_truncated_ = select_image_truncated_array_; - this->cond_image_binding_.bind = cond_image_bind_; - this->cond_image_binding_.count = traits::cond_column_count; - - this->data_image_binding_.bind = data_image_bind_; - this->data_image_binding_.count = traits::data_column_count; + this->insert_image_binding_.bind = data_image_bind_; + this->insert_image_binding_.count = traits::data_column_count; this->select_image_binding_.bind = data_image_bind_ + traits::id_column_count; this->select_image_binding_.count = traits::data_column_count - traits::id_column_count; - std::memset (cond_image_bind_, 0, sizeof (cond_image_bind_)); std::memset (data_image_bind_, 0, sizeof (data_image_bind_)); std::memset (select_image_truncated_array_, 0, @@ -64,9 +77,29 @@ namespace odb data_image_bind_[i + traits::id_column_count].truncated = select_image_truncated_array_ + i; - this->insert_one_text_ = traits::insert_one_statement; - this->select_all_text_ = traits::select_all_statement; - this->delete_all_text_ = traits::delete_all_statement; + this->insert_text_ = traits::insert_statement; + this->select_text_ = traits::select_statement; + this->delete_text_ = traits::delete_statement; + } + + // smart_container_statements_impl + // + template + smart_container_statements_impl:: + smart_container_statements_impl (connection_type& conn, binding& id) + : container_statements_impl (conn, id) + { + this->cond_image_binding_.bind = cond_image_bind_; + this->cond_image_binding_.count = traits::cond_column_count; + + this->update_image_binding_.bind = update_image_bind_; + this->update_image_binding_.count = traits::value_column_count + + traits::cond_column_count; + + std::memset (cond_image_bind_, 0, sizeof (cond_image_bind_)); + std::memset (update_image_bind_, 0, sizeof (update_image_bind_)); + + this->update_text_ = traits::update_statement; } } } -- cgit v1.1