From 62d4405faf1060e447dc06fbda6789ff36bdbe36 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Sun, 30 Oct 2011 17:52:31 +0200 Subject: Rework statement interfaces wrt param/result passing --- odb/oracle/object-statements.hxx | 14 +++++++-- odb/oracle/object-statements.txx | 4 ++- odb/oracle/statement.cxx | 61 +++++++++++++++++++--------------------- odb/oracle/statement.hxx | 33 +++++++++++----------- 4 files changed, 59 insertions(+), 53 deletions(-) diff --git a/odb/oracle/object-statements.hxx b/odb/oracle/object-statements.hxx index 807bb1e..8f469c7 100644 --- a/odb/oracle/object-statements.hxx +++ b/odb/oracle/object-statements.hxx @@ -223,6 +223,12 @@ namespace odb void update_image_version (std::size_t v) {update_image_version_ = v;} + std::size_t + update_id_image_version () const { return update_id_image_version_;} + + void + update_id_image_version (std::size_t v) {update_id_image_version_ = v;} + binding& update_image_binding () {return update_image_binding_;} @@ -290,7 +296,6 @@ namespace odb new (details::shared) update_statement_type ( conn_, object_traits::update_statement, - id_image_binding_, update_image_binding_)); return *update_; @@ -362,10 +367,13 @@ namespace odb binding insert_image_binding_; bind insert_image_bind_[insert_column_count]; - // Update binding. The suffix of the bind array is object id. We - // do it this way for consistency with other database runtimes. + // Update binding. Note that the id suffix is bound to id_image_ + // below instead of image_ which makes this binding effectively + // bound to two images. As a result, we have to track versions + // for both of them. // std::size_t update_image_version_; + std::size_t update_id_image_version_; binding update_image_binding_; bind update_image_bind_[update_column_count + id_column_count]; diff --git a/odb/oracle/object-statements.txx b/odb/oracle/object-statements.txx index 212c03c..c187c07 100644 --- a/odb/oracle/object-statements.txx +++ b/odb/oracle/object-statements.txx @@ -33,7 +33,8 @@ namespace odb container_statement_cache_ (conn), select_image_binding_ (select_image_bind_, select_column_count), insert_image_binding_ (insert_image_bind_, insert_column_count), - update_image_binding_ (update_image_bind_, update_column_count), + update_image_binding_ (update_image_bind_, + update_column_count + id_column_count), id_image_binding_ (update_image_bind_ + update_column_count, id_column_count) { @@ -41,6 +42,7 @@ namespace odb select_image_version_ = 0; insert_image_version_ = 0; update_image_version_ = 0; + update_id_image_version_ = 0; id_image_.version = 0; id_image_version_ = 0; diff --git a/odb/oracle/statement.cxx b/odb/oracle/statement.cxx index 8e96696..0446353 100644 --- a/odb/oracle/statement.cxx +++ b/odb/oracle/statement.cxx @@ -153,16 +153,15 @@ namespace odb } void statement:: - bind_param (bind* b, size_t c, size_t o) + bind_param (bind* b, size_t n) { OCIError* err (conn_.error_handle ()); // The parameter position in OCIBindByPos is specified as a 1-based - // index. Convert o to a 1-based offset. + // index. // - ++o; - - for (size_t e (o + c); o < e; ++o, ++b) + n++; + for (ub4 i (1); i < n; ++i, ++b) { #if OCI_MAJOR_VERSION < 11 || \ (OCI_MAJOR_VERSION == 11 && OCI_MINOR_VERSION < 2) @@ -180,7 +179,7 @@ namespace odb sword r (OCIBindByPos (stmt_, &h, err, - o, + i, callback ? 0 : b->buffer, // When parameter callbacks are in use, set the // allowable data length to the maximum @@ -541,33 +540,33 @@ namespace odb select_statement:: select_statement (connection& conn, const string& s, - binding& cond, - binding& data, + binding& param, + binding& result, size_t lob_prefetch_size) : statement (conn, s), - data_ (data), - data_version_ (0), + result_ (result), + result_version_ (0), lob_prefetch_size_ (lob_prefetch_size), done_ (true) { - bind_param (cond.bind, cond.count, 0); - bind_result (data.bind, data.count, lob_prefetch_size); - data_version_ = data_.version; + bind_param (param.bind, param.count); + bind_result (result.bind, result.count, lob_prefetch_size); + result_version_ = result_.version; } select_statement:: select_statement (connection& conn, const string& s, - binding& data, + binding& result, size_t lob_prefetch_size) : statement (conn, s), - data_ (data), - data_version_ (0), + result_ (result), + result_version_ (0), lob_prefetch_size_ (lob_prefetch_size), done_ (true) { - bind_result (data.bind, data.count, lob_prefetch_size); - data_version_ = data_.version; + bind_result (result.bind, result.count, lob_prefetch_size); + result_version_ = result_.version; } void select_statement:: @@ -608,7 +607,7 @@ namespace odb // of this assertion is a native view with a number of data members // not matching the number of columns in the SELECT-list. // - assert (n == data_.count); + assert (n == result_.count); #endif } @@ -617,15 +616,15 @@ namespace odb { if (!done_) { - change_callback* cc (data_.change_callback); + change_callback* cc (result_.change_callback); if (cc != 0 && cc->callback != 0) (cc->callback) (cc->context); - if (data_version_ != data_.version) + if (result_version_ != result_.version) { - rebind_result (data_.bind, data_.count, lob_prefetch_size_); - data_version_ = data_.version; + rebind_result (result_.bind, result_.count, lob_prefetch_size_); + result_version_ = result_.version; } sword r (OCIStmtFetch2 (stmt_, @@ -728,11 +727,11 @@ namespace odb insert_statement:: insert_statement (connection& conn, const string& s, - binding& data, + binding& param, bool returning) : statement (conn, s) { - bind_param (data.bind, data.count, 0); + bind_param (param.bind, param.count); if (returning) { @@ -742,7 +741,7 @@ namespace odb sword r (OCIBindByPos (stmt_, &h, err, - data.count + 1, + param.count + 1, 0, #if (OCI_MAJOR_VERSION == 11 && OCI_MINOR_VERSION >=2) \ || OCI_MAJOR_VERSION > 11 @@ -842,12 +841,10 @@ namespace odb update_statement:: update_statement (connection& conn, const string& s, - binding& cond, - binding& data) + binding& param) : statement (conn, s) { - bind_param (data.bind, data.count, 0); - bind_param (cond.bind, cond.count, data.count); + bind_param (param.bind, param.count); } void update_statement:: @@ -898,10 +895,10 @@ namespace odb delete_statement:: delete_statement (connection& conn, const string& s, - binding& cond) + binding& param) : statement (conn, s) { - bind_param (cond.bind, cond.count, 0); + bind_param (param.bind, param.count); } unsigned long long delete_statement:: diff --git a/odb/oracle/statement.hxx b/odb/oracle/statement.hxx index a883d6c..0b56b8f 100644 --- a/odb/oracle/statement.hxx +++ b/odb/oracle/statement.hxx @@ -36,16 +36,16 @@ namespace odb protected: statement (connection&, const std::string& statement); - // Bind output parameters to this statement. This function must only - // be called once. Multiple calls to it will result in memory leaks due - // to lost OCIBind resources. + // Bind parameters for this statement. This function must only + // be called once. Multiple calls to it will result in memory + // leaks due to lost OCIBind resources. // void - bind_param (bind*, std::size_t count, std::size_t offset); + bind_param (bind*, std::size_t count); - // Bind input parameters to this statement. This function must only be - // called once. Multiple calls to it will result in memory leaks due to - // lost OCIDefine resources. + // Bind results for this statement. This function must only be + // called once. Multiple calls to it will result in memory leaks + // due to lost OCIDefine resources. // void bind_result (bind*, @@ -81,13 +81,13 @@ namespace odb select_statement (connection& conn, const std::string& statement, - binding& cond, - binding& data, + binding& param, + binding& result, std::size_t lob_prefetch_size = 0); select_statement (connection& conn, const std::string& statement, - binding& data, + binding& result, std::size_t lob_prefetch_size = 0); enum result @@ -105,7 +105,7 @@ namespace odb void stream_result () { - statement::stream_result (data_.bind, data_.count); + statement::stream_result (result_.bind, result_.count); } void @@ -116,8 +116,8 @@ namespace odb select_statement& operator= (const select_statement&); private: - binding& data_; - std::size_t data_version_; + binding& result_; + std::size_t result_version_; const std::size_t lob_prefetch_size_; bool done_; }; @@ -130,7 +130,7 @@ namespace odb insert_statement (connection& conn, const std::string& statement, - binding& data, + binding& param, bool returning); // Return true if successful and false if the row is a duplicate. All @@ -175,8 +175,7 @@ namespace odb update_statement (connection& conn, const std::string& statement, - binding& cond, - binding& data); + binding& param); void execute (); @@ -193,7 +192,7 @@ namespace odb delete_statement (connection& conn, const std::string& statement, - binding& cond); + binding& param); unsigned long long execute (); -- cgit v1.1