aboutsummaryrefslogtreecommitdiff
path: root/odb/sqlite/connection.cxx
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2011-03-24 14:02:16 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2011-03-24 14:02:16 +0200
commit7939f7972cf22ee9a74518978e4f7d4d77535e09 (patch)
treeb211e2f455ef717482370fc262a63a5f7bfeb77f /odb/sqlite/connection.cxx
parent01e70d9a1d49bcb126adc45f85168aa7c9cbad19 (diff)
Add support for clearing connection from active and uncached statements
Diffstat (limited to 'odb/sqlite/connection.cxx')
-rw-r--r--odb/sqlite/connection.cxx32
1 files changed, 25 insertions, 7 deletions
diff --git a/odb/sqlite/connection.cxx b/odb/sqlite/connection.cxx
index 37f5e20..9af5a3b 100644
--- a/odb/sqlite/connection.cxx
+++ b/odb/sqlite/connection.cxx
@@ -9,6 +9,7 @@
#include <odb/sqlite/database.hxx>
#include <odb/sqlite/connection.hxx>
+#include <odb/sqlite/statement.hxx>
#include <odb/sqlite/statement-cache.hxx>
#include <odb/sqlite/error.hxx>
@@ -19,8 +20,17 @@ namespace odb
namespace sqlite
{
connection::
+ ~connection ()
+ {
+ statement_cache_.reset (); // Free prepared statements.
+
+ if (sqlite3_close (handle_) == SQLITE_BUSY)
+ assert (false); // Connection has outstanding prepared statements.
+ }
+
+ connection::
connection (database_type& db)
- : db_ (db)
+ : db_ (db), statements_ (0)
{
int f (db.flags ());
const string& n (db.name ());
@@ -47,13 +57,21 @@ namespace odb
statement_cache_.reset (new statement_cache_type (*this));
}
- connection::
- ~connection ()
+ void connection::
+ clear ()
{
- statement_cache_.reset (); // Free prepared statements.
-
- if (sqlite3_close (handle_) == SQLITE_BUSY)
- assert (false); // Connection has outstanding prepared statements.
+ // The current first statement will remove itself from the list
+ // and make the second statement (if any) the new first.
+ //
+ while (statement* s = statements_)
+ {
+ if (!s->cached ())
+ s->finilize ();
+ else if (s->active ())
+ s->reset ();
+ else
+ assert (false); // Statement is neither active nor unached.
+ }
}
}
}