diff options
author | Andreas Baumann <abaumann@yahoo.com> | 2010-03-25 09:25:59 +0100 |
---|---|---|
committer | Andreas Baumann <abaumann@yahoo.com> | 2010-03-25 09:25:59 +0100 |
commit | d97b78e6d6978e9e288f1269f54bc820e378868f (patch) | |
tree | 086c38feef9e432c4ec79c070b9f576490ccb781 | |
parent | 44e6b7e472c31f214ed41833621e65acebd8375a (diff) | |
download | sqlitexx-d97b78e6d6978e9e288f1269f54bc820e378868f.tar.gz sqlitexx-d97b78e6d6978e9e288f1269f54bc820e378868f.tar.bz2 |
fixed finalizing of prepared statements in destructor of connection
added a trace() method to get the tracing status
-rw-r--r-- | include/sqlite3xx/connection.hpp | 1 | ||||
-rw-r--r-- | src/connection.cpp | 12 | ||||
-rw-r--r-- | src/prepared_statement.cpp | 1 |
3 files changed, 13 insertions, 1 deletions
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; } |