From 3405fff26a02b5bee51686c5d22200be320b87d8 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Wed, 7 Mar 2012 10:21:08 +0200 Subject: Use RAII to free select statement results --- odb/pgsql/object-result.txx | 10 ++++++++++ odb/pgsql/statement.hxx | 13 +++++++++++++ odb/pgsql/view-result.txx | 5 +++++ 3 files changed, 28 insertions(+) (limited to 'odb/pgsql') diff --git a/odb/pgsql/object-result.txx b/odb/pgsql/object-result.txx index 3a20e2d..c5334cc 100644 --- a/odb/pgsql/object-result.txx +++ b/odb/pgsql/object-result.txx @@ -20,6 +20,8 @@ namespace odb object_result_impl:: ~object_result_impl () { + if (!this->end_) + statement_->free_result (); } template @@ -87,7 +89,10 @@ namespace odb this->current (pointer_type ()); if (!statement_->next ()) + { + statement_->free_result (); this->end_ = true; + } } template @@ -146,6 +151,8 @@ namespace odb object_result_impl_no_id:: ~object_result_impl_no_id () { + if (!this->end_) + statement_->free_result (); } template @@ -207,7 +214,10 @@ namespace odb this->current (pointer_type ()); if (!statement_->next ()) + { + statement_->free_result (); this->end_ = true; + } } template diff --git a/odb/pgsql/statement.hxx b/odb/pgsql/statement.hxx index c643687..94fceb6 100644 --- a/odb/pgsql/statement.hxx +++ b/odb/pgsql/statement.hxx @@ -209,6 +209,19 @@ namespace odb std::size_t current_row_; }; + struct LIBODB_PGSQL_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_PGSQL_EXPORT insert_statement: public statement { public: diff --git a/odb/pgsql/view-result.txx b/odb/pgsql/view-result.txx index 0989d62..2219463 100644 --- a/odb/pgsql/view-result.txx +++ b/odb/pgsql/view-result.txx @@ -14,6 +14,8 @@ namespace odb view_result_impl:: ~view_result_impl () { + if (!this->end_) + statement_->free_result (); } template @@ -75,7 +77,10 @@ namespace odb this->current (pointer_type ()); if (!statement_->next ()) + { + statement_->free_result (); this->end_ = true; + } } template -- cgit v1.1