diff options
-rw-r--r-- | odb/sqlite/container-statements.hxx | 42 | ||||
-rw-r--r-- | odb/sqlite/container-statements.txx | 34 |
2 files changed, 62 insertions, 14 deletions
diff --git a/odb/sqlite/container-statements.hxx b/odb/sqlite/container-statements.hxx index e0df250..d67388d 100644 --- a/odb/sqlite/container-statements.hxx +++ b/odb/sqlite/container-statements.hxx @@ -24,7 +24,8 @@ namespace odb { class connection; - // Template argument is the generated container traits type. + // Template argument is the generated abstract container traits type. + // That is, it doesn't need to provide column counts and statements. // template <typename T> class container_statements @@ -166,7 +167,7 @@ namespace odb { insert_one_.reset ( new (details::shared) insert_statement_type ( - conn_, traits::insert_one_statement, data_image_binding_)); + conn_, insert_one_text_, data_image_binding_)); insert_one_->cached (true); } @@ -182,7 +183,7 @@ namespace odb select_all_.reset ( new (details::shared) select_statement_type ( conn_, - traits::select_all_statement, + select_all_text_, cond_image_binding_, data_image_binding_)); @@ -199,7 +200,7 @@ namespace odb { delete_all_.reset ( new (details::shared) delete_statement_type ( - conn_, traits::delete_all_statement, cond_image_binding_)); + conn_, delete_all_text_, cond_image_binding_)); delete_all_->cached (true); } @@ -211,7 +212,7 @@ namespace odb container_statements (const container_statements&); container_statements& operator= (const container_statements&); - private: + protected: connection_type& conn_; functions_type functions_; @@ -221,19 +222,44 @@ namespace odb std::size_t cond_image_version_; std::size_t cond_id_binding_version_; binding cond_image_binding_; - bind cond_image_bind_[traits::cond_column_count]; + bind* cond_image_bind_; data_image_type data_image_; std::size_t data_image_version_; std::size_t data_id_binding_version_; binding data_image_binding_; - bind data_image_bind_[traits::data_column_count]; - bool data_image_truncated_[traits::data_column_count]; + bind* data_image_bind_; + bool* data_image_truncated_; + + const char* insert_one_text_; + const char* select_all_text_; + const char* delete_all_text_; details::shared_ptr<insert_statement_type> insert_one_; details::shared_ptr<select_statement_type> select_all_; details::shared_ptr<delete_statement_type> delete_all_; }; + + // Template argument is the generated concrete container traits type. + // + template <typename T> + class container_statements_impl: public T::statements_type + { + public: + typedef T traits; + typedef typename T::statements_type base; + + container_statements_impl (connection&); + + private: + container_statements_impl (const container_statements_impl&); + container_statements_impl& operator= (const container_statements_impl&); + + private: + bind cond_image_bind_array_[traits::cond_column_count]; + bind data_image_bind_array_[traits::data_column_count]; + bool data_image_truncated_array_[traits::data_column_count]; + }; } } diff --git a/odb/sqlite/container-statements.txx b/odb/sqlite/container-statements.txx index 15bd4a7..bad380c 100644 --- a/odb/sqlite/container-statements.txx +++ b/odb/sqlite/container-statements.txx @@ -22,8 +22,8 @@ namespace odb &traits::load_all, &traits::delete_all), id_binding_ (0), - cond_image_binding_ (cond_image_bind_, traits::cond_column_count), - data_image_binding_ (data_image_bind_, traits::data_column_count) + cond_image_binding_ (0, 0), // Initialized by impl. + data_image_binding_ (0, 0) // Initialized by impl. { cond_image_.version = 0; cond_image_version_ = 0; @@ -32,13 +32,35 @@ namespace odb data_image_.version = 0; data_image_version_ = 0; data_id_binding_version_ = 0; + } + + template <typename T> + container_statements_impl<T>:: + container_statements_impl (connection& conn) + : base (conn) + { + this->cond_image_bind_ = cond_image_bind_array_; + this->data_image_bind_ = data_image_bind_array_; + this->data_image_truncated_ = data_image_truncated_array_; - std::memset (cond_image_bind_, 0, sizeof (cond_image_bind_)); - std::memset (data_image_bind_, 0, sizeof (data_image_bind_)); - std::memset (data_image_truncated_, 0, sizeof (data_image_truncated_)); + this->cond_image_binding_.bind = this->cond_image_bind_; + this->cond_image_binding_.count = traits::cond_column_count; + + this->data_image_binding_.bind = this->data_image_bind_; + this->data_image_binding_.count = traits::data_column_count; + + std::memset (cond_image_bind_array_, 0, sizeof (cond_image_bind_array_)); + std::memset (data_image_bind_array_, 0, sizeof (data_image_bind_array_)); + std::memset (data_image_truncated_array_, + 0, + sizeof (data_image_truncated_array_)); for (std::size_t i (0); i < traits::data_column_count; ++i) - data_image_bind_[i].truncated = data_image_truncated_ + i; + data_image_bind_array_[i].truncated = data_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; } } } |