From 7d52205f2b2fc9403b9ea46483e8a17746c6be35 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/sqlite/object-result.txx | 10 ++++++++++ odb/sqlite/statement.hxx | 13 +++++++++++++ odb/sqlite/view-result.txx | 5 +++++ 3 files changed, 28 insertions(+) diff --git a/odb/sqlite/object-result.txx b/odb/sqlite/object-result.txx index a6b4e50..39dcdd7 100644 --- a/odb/sqlite/object-result.txx +++ b/odb/sqlite/object-result.txx @@ -21,6 +21,8 @@ namespace odb object_result_impl:: ~object_result_impl () { + if (!this->end_) + statement_->free_result (); } template @@ -88,7 +90,10 @@ namespace odb this->current (pointer_type ()); if (!statement_->next ()) + { + statement_->free_result (); this->end_ = true; + } } template @@ -147,6 +152,8 @@ namespace odb object_result_impl_no_id:: ~object_result_impl_no_id () { + if (!this->end_) + statement_->free_result (); } template @@ -208,7 +215,10 @@ namespace odb this->current (pointer_type ()); if (!statement_->next ()) + { + statement_->free_result (); this->end_ = true; + } } template diff --git a/odb/sqlite/statement.hxx b/odb/sqlite/statement.hxx index cf94c71..0ed8aa8 100644 --- a/odb/sqlite/statement.hxx +++ b/odb/sqlite/statement.hxx @@ -294,6 +294,19 @@ namespace odb binding& result_; }; + struct LIBODB_SQLITE_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_SQLITE_EXPORT insert_statement: public statement { public: diff --git a/odb/sqlite/view-result.txx b/odb/sqlite/view-result.txx index c240add..49d0e68 100644 --- a/odb/sqlite/view-result.txx +++ b/odb/sqlite/view-result.txx @@ -15,6 +15,8 @@ namespace odb view_result_impl:: ~view_result_impl () { + if (!this->end_) + statement_->free_result (); } template @@ -76,7 +78,10 @@ namespace odb this->current (pointer_type ()); if (!statement_->next ()) + { + statement_->free_result (); this->end_ = true; + } } template -- cgit v1.1