diff options
-rw-r--r-- | odb/mysql/container-statements.hxx | 69 | ||||
-rw-r--r-- | odb/mysql/container-statements.txx | 9 | ||||
-rw-r--r-- | odb/mysql/object-statements.hxx | 30 | ||||
-rw-r--r-- | odb/mysql/object-statements.txx | 6 | ||||
-rw-r--r-- | odb/mysql/result.txx | 25 | ||||
-rw-r--r-- | odb/mysql/statement.hxx | 6 |
6 files changed, 142 insertions, 3 deletions
diff --git a/odb/mysql/container-statements.hxx b/odb/mysql/container-statements.hxx index 4d23d5a..d3b2625 100644 --- a/odb/mysql/container-statements.hxx +++ b/odb/mysql/container-statements.hxx @@ -31,6 +31,7 @@ namespace odb public: typedef T traits; + typedef typename traits::id_image_type id_image_type; typedef typename traits::data_image_type data_image_type; typedef typename traits::cond_image_type cond_image_type; @@ -58,6 +59,20 @@ namespace odb return functions_; } + // Id image (external). + // + id_image_type& + id_image () + { + return *id_image_; + } + + void + id_image (id_image_type& i) + { + id_image_ = &i; + } + // Condition image. // cond_image_type& @@ -66,6 +81,30 @@ namespace odb return cond_image_; } + std::size_t + cond_image_version () const + { + return cond_image_version_; + } + + void + cond_image_version (std::size_t v) + { + cond_image_version_ = v; + } + + std::size_t + cond_id_image_version () const + { + return cond_id_image_version_; + } + + void + cond_id_image_version (std::size_t v) + { + cond_id_image_version_ = v; + } + binding& cond_image_binding () { @@ -80,6 +119,30 @@ namespace odb return data_image_; } + std::size_t + data_image_version () const + { + return data_image_version_; + } + + void + data_image_version (std::size_t v) + { + data_image_version_ = v; + } + + std::size_t + data_id_image_version () const + { + return data_id_image_version_; + } + + void + data_id_image_version (std::size_t v) + { + data_id_image_version_ = v; + } + binding& data_image_binding () { @@ -140,11 +203,17 @@ namespace odb connection_type& conn_; functions_type functions_; + id_image_type* id_image_; + cond_image_type cond_image_; + std::size_t cond_image_version_; + std::size_t cond_id_image_version_; binding cond_image_binding_; MYSQL_BIND cond_image_bind_[traits::cond_column_count]; data_image_type data_image_; + std::size_t data_image_version_; + std::size_t data_id_image_version_; binding data_image_binding_; MYSQL_BIND data_image_bind_[traits::data_column_count]; my_bool data_image_error_[traits::data_column_count]; diff --git a/odb/mysql/container-statements.txx b/odb/mysql/container-statements.txx index 18d7831..2eb5e3a 100644 --- a/odb/mysql/container-statements.txx +++ b/odb/mysql/container-statements.txx @@ -21,9 +21,18 @@ namespace odb &traits::insert_one, &traits::load_all, &traits::delete_all), + id_image_ (0), cond_image_binding_ (cond_image_bind_, traits::cond_column_count), data_image_binding_ (data_image_bind_, traits::data_column_count) { + cond_image_.version = 0; + cond_image_version_ = 0; + cond_id_image_version_ = 0; + + data_image_.version = 0; + data_image_version_ = 0; + data_id_image_version_ = 0; + std::memset (cond_image_bind_, 0, sizeof (cond_image_bind_)); std::memset (data_image_bind_, 0, sizeof (data_image_bind_)); std::memset (data_image_error_, 0, sizeof (data_image_error_)); diff --git a/odb/mysql/object-statements.hxx b/odb/mysql/object-statements.hxx index ad51d05..c2c97e8 100644 --- a/odb/mysql/object-statements.hxx +++ b/odb/mysql/object-statements.hxx @@ -69,12 +69,26 @@ namespace odb object_statements (connection_type&); + // Object image. + // image_type& image () { return image_; } + std::size_t + image_version () const + { + return image_version_; + } + + void + image_version (std::size_t v) + { + image_version_ = v; + } + binding& image_binding () { @@ -87,12 +101,26 @@ namespace odb return image_error_; } + // Object id image. + // id_image_type& id_image () { return id_image_; } + std::size_t + id_image_version () const + { + return id_image_version_; + } + + void + id_image_version (std::size_t v) + { + id_image_version_ = v; + } + binding& id_image_binding () { @@ -172,10 +200,12 @@ namespace odb MYSQL_BIND image_bind_[object_traits::column_count + 1]; image_type image_; + std::size_t image_version_; my_bool image_error_[object_traits::column_count]; binding image_binding_; id_image_type id_image_; + std::size_t id_image_version_; binding id_image_binding_; details::shared_ptr<persist_statement_type> persist_; diff --git a/odb/mysql/object-statements.txx b/odb/mysql/object-statements.txx index 553447b..4b8e356 100644 --- a/odb/mysql/object-statements.txx +++ b/odb/mysql/object-statements.txx @@ -21,6 +21,12 @@ namespace odb image_binding_ (image_bind_, object_traits::column_count), id_image_binding_ (image_bind_ + object_traits::column_count, 1) { + image_.version = 0; + image_version_ = 0; + + id_image_.version = 0; + id_image_version_ = 0; + std::memset (image_bind_, 0, sizeof (image_bind_)); std::memset (image_error_, 0, sizeof (image_error_)); diff --git a/odb/mysql/result.txx b/odb/mysql/result.txx index 931ecf9..e1e8440 100644 --- a/odb/mysql/result.txx +++ b/odb/mysql/result.txx @@ -36,18 +36,37 @@ namespace odb next () { this->current (pointer_type ()); + + // If the result was cached the image can grow between calls + // to next() as a result of other statements execution. + // + if (statement_->cached ()) + { + typename traits::image_type& im (statements_.image ()); + + if (im.version != statements_.image_version ()) + { + binding& b (statements_.image_binding ()); + traits::bind (b.bind, im); + statements_.image_version (im.version); + b.version++; + } + } + select_statement::result r (statement_->fetch ()); switch (r) { case select_statement::truncated: { - typename traits::image_type& i (statements_.image ()); + typename traits::image_type& im (statements_.image ()); + traits::grow (im, statements_.image_error ()); - if (traits::grow (i, statements_.image_error ())) + if (im.version != statements_.image_version ()) { binding& b (statements_.image_binding ()); - traits::bind (b.bind, i); + traits::bind (b.bind, im); + statements_.image_version (im.version); b.version++; statement_->refetch (); } diff --git a/odb/mysql/statement.hxx b/odb/mysql/statement.hxx index 3df86c0..343595d 100644 --- a/odb/mysql/statement.hxx +++ b/odb/mysql/statement.hxx @@ -70,6 +70,12 @@ namespace odb void cache (); + bool + cached () const + { + return cached_; + } + std::size_t result_size (); |