From 7939f7972cf22ee9a74518978e4f7d4d77535e09 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Thu, 24 Mar 2011 14:02:16 +0200 Subject: Add support for clearing connection from active and uncached statements --- odb/sqlite/connection.cxx | 32 +++++++++++++++++++++++++------- 1 file changed, 25 insertions(+), 7 deletions(-) (limited to 'odb/sqlite/connection.cxx') 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 #include +#include #include #include @@ -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. + } } } } -- cgit v1.1