aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2012-03-07 10:21:08 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2012-03-07 10:21:08 +0200
commit7d52205f2b2fc9403b9ea46483e8a17746c6be35 (patch)
tree588d4ab4e730c3c3d72dcc0cdf98769eae61afdb
parent2de569a55b9fc25142844f88d35f7b6d2d3fb53c (diff)
Use RAII to free select statement results
-rw-r--r--odb/sqlite/object-result.txx10
-rw-r--r--odb/sqlite/statement.hxx13
-rw-r--r--odb/sqlite/view-result.txx5
3 files changed, 28 insertions, 0 deletions
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<T>::
~object_result_impl ()
{
+ if (!this->end_)
+ statement_->free_result ();
}
template <typename T>
@@ -88,7 +90,10 @@ namespace odb
this->current (pointer_type ());
if (!statement_->next ())
+ {
+ statement_->free_result ();
this->end_ = true;
+ }
}
template <typename T>
@@ -147,6 +152,8 @@ namespace odb
object_result_impl_no_id<T>::
~object_result_impl_no_id ()
{
+ if (!this->end_)
+ statement_->free_result ();
}
template <typename T>
@@ -208,7 +215,10 @@ namespace odb
this->current (pointer_type ());
if (!statement_->next ())
+ {
+ statement_->free_result ();
this->end_ = true;
+ }
}
template <typename T>
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<T>::
~view_result_impl ()
{
+ if (!this->end_)
+ statement_->free_result ();
}
template <typename T>
@@ -76,7 +78,10 @@ namespace odb
this->current (pointer_type ());
if (!statement_->next ())
+ {
+ statement_->free_result ();
this->end_ = true;
+ }
}
template <typename T>