From d97b78e6d6978e9e288f1269f54bc820e378868f Mon Sep 17 00:00:00 2001 From: Andreas Baumann Date: Thu, 25 Mar 2010 09:25:59 +0100 Subject: fixed finalizing of prepared statements in destructor of connection added a trace() method to get the tracing status --- include/sqlite3xx/connection.hpp | 1 + src/connection.cpp | 12 +++++++++++- src/prepared_statement.cpp | 1 + 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/include/sqlite3xx/connection.hpp b/include/sqlite3xx/connection.hpp index ab1fa70..0d95a7e 100644 --- a/include/sqlite3xx/connection.hpp +++ b/include/sqlite3xx/connection.hpp @@ -62,6 +62,7 @@ class SQLITEXX_LIBEXPORT connection { ~connection( ); void trace( bool __trace ); + bool trace( ) { return _trace; } result exec( string sql ); result prepared_exec( const string& name ); diff --git a/src/connection.cpp b/src/connection.cpp index ceb5d3e..30ab00a 100644 --- a/src/connection.cpp +++ b/src/connection.cpp @@ -56,7 +56,17 @@ connection::connection( const connection& c ) { connection::~connection( ) { assert( db != NULL ); - sqlite3_close( db ); + + // remove all prepared statements + for( PSMap::iterator it = prepared_stmts.begin( ); it != prepared_stmts.end( ); it++ ) { + delete (*it).second; + } + + // close database now + int rt = sqlite3_close( db ); + if( rt != SQLITE_OK ) { + cerr << "ERROR in destructor of connection: " << rt << endl; + } } extern "C" void profiling_callback( void *a, const char *b, sqlite3_uint64 c ) { diff --git a/src/prepared_statement.cpp b/src/prepared_statement.cpp index 4843a86..fef5090 100644 --- a/src/prepared_statement.cpp +++ b/src/prepared_statement.cpp @@ -125,6 +125,7 @@ prepared_stmt::prepared_stmt( sqlite3 *db, string __sql ) : prepared_stmt::~prepared_stmt( ) { assert( _stmt != NULL ); + if( false /* TODO: access to _c.trace( ) */ ) cout << "TRACE: finalizing prepared statement '" << _sql << "'" << endl; sqlite3_finalize( _stmt ); _stmt = NULL; } -- cgit v1.2.3-54-g00ecf