From d2fc34834f0b7660374f78d4409e24a165950c2c Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Wed, 7 Mar 2012 10:21:09 +0200 Subject: Use RAII to free select statement results --- odb/oracle/object-result.txx | 12 ++++++++++++ odb/oracle/statement.cxx | 3 --- odb/oracle/statement.hxx | 13 +++++++++++++ odb/oracle/view-result.txx | 6 ++++++ 4 files changed, 31 insertions(+), 3 deletions(-) diff --git a/odb/oracle/object-result.txx b/odb/oracle/object-result.txx index 19ac6fe..ddc9783 100644 --- a/odb/oracle/object-result.txx +++ b/odb/oracle/object-result.txx @@ -30,6 +30,9 @@ namespace odb } delete image_copy_; + + if (!this->end_) + statement_->free_result (); } template @@ -124,7 +127,10 @@ namespace odb } if (statement_->fetch () == select_statement::no_data) + { + statement_->free_result (); this->end_ = true; + } else { cc.callback = &change_callback; @@ -186,6 +192,9 @@ namespace odb } delete image_copy_; + + if (!this->end_) + statement_->free_result (); } template @@ -249,7 +258,10 @@ namespace odb } if (statement_->fetch () == select_statement::no_data) + { + statement_->free_result (); this->end_ = true; + } else { cc.callback = &change_callback; diff --git a/odb/oracle/statement.cxx b/odb/oracle/statement.cxx index 2a08566..8cf2452 100644 --- a/odb/oracle/statement.cxx +++ b/odb/oracle/statement.cxx @@ -1337,9 +1337,6 @@ namespace odb void select_statement:: execute () { - if (!done_) - free_result (); - { odb::tracer* t; if ((t = conn_.transaction_tracer ()) || diff --git a/odb/oracle/statement.hxx b/odb/oracle/statement.hxx index f26aa42..ed8f298 100644 --- a/odb/oracle/statement.hxx +++ b/odb/oracle/statement.hxx @@ -192,6 +192,19 @@ namespace odb bool done_; }; + struct LIBODB_ORACLE_EXPORT auto_result + { + explicit auto_result (select_statement& s): s_ (s) {} + ~auto_result () {s_.free_result ();} + + private: + auto_result (const auto_result&); + auto_result& operator= (const auto_result&); + + private: + select_statement& s_; + }; + class LIBODB_ORACLE_EXPORT insert_statement: public statement { public: diff --git a/odb/oracle/view-result.txx b/odb/oracle/view-result.txx index 4f1d01e..64d949e 100644 --- a/odb/oracle/view-result.txx +++ b/odb/oracle/view-result.txx @@ -24,6 +24,9 @@ namespace odb } delete image_copy_; + + if (!this->end_) + statement_->free_result (); } template @@ -87,7 +90,10 @@ namespace odb } if (statement_->fetch () == select_statement::no_data) + { + statement_->free_result (); this->end_ = true; + } else { cc.callback = &change_callback; -- cgit v1.1