diff --git a/Makefile b/Makefile index 06d7346..8263310 100644 --- a/Makefile +++ b/Makefile @@ -13,10 +13,10 @@ BUILD ?= Debug ### Conditionally set variables: ### ifeq ($(BUILD),Debug) -BUILD_FLAGS = -g3 -rdynamic -fstack-protector-all -fno-inline -O0 -DDEBUG -D_DEBUG +BUILD_FLAGS = -g3 -rdynamic -fstack-protector-all -fno-inline -O0 -D_DEBUG endif ifeq ($(BUILD),Release) -BUILD_FLAGS = -O2 +BUILD_FLAGS = -O2 -DNDEBUG endif ifeq ($(BUILD),Debug) LINK_FLAGS = -g3 -rdynamic diff --git a/TODO.txt b/TODO.txt index 50c8a70..afae270 100644 --- a/TODO.txt +++ b/TODO.txt @@ -4,11 +4,11 @@ C++11 explicit support Adding an encapsulation to the statement ref counter -Using (optionnal) assert() on errors in destructors - copyright 2013 + => V0.5.0 +using assert() in example program to provide a basic test coverage Missing features in v0.4.0: - Blob diff --git a/src/SQLiteC++/Column.cpp b/src/SQLiteC++/Column.cpp index 2b31194..a53cbd2 100644 --- a/src/SQLiteC++/Column.cpp +++ b/src/SQLiteC++/Column.cpp @@ -47,11 +47,10 @@ Column::~Column(void) throw() // nothrow { // When count reaches zero, finalize the sqlite3_stmt, as no Column nor Statement object use it any more int ret = sqlite3_finalize(mpStmt); - if (SQLITE_OK != ret) - { - // Never throw an exception in a destructor - //std::cout << sqlite3_errmsg(mpSQLite) << std::endl; - } + // Never throw an exception in a destructor + //std::cout << sqlite3_errmsg(mpSQLite) << std::endl; + SQLITE_CPP_ASSERT (SQLITE_OK == ret); + mpStmt = NULL; // and delete the reference counter diff --git a/src/SQLiteC++/Database.cpp b/src/SQLiteC++/Database.cpp index 7e63feb..3694001 100644 --- a/src/SQLiteC++/Database.cpp +++ b/src/SQLiteC++/Database.cpp @@ -34,11 +34,9 @@ Database::Database(const char* apFilename, const int aFlags /*= SQLITE_OPEN_READ Database::~Database(void) throw() // nothrow { int ret = sqlite3_close(mpSQLite); - if (SQLITE_OK != ret) - { - // Never throw an exception in a destructor - //std::cout << sqlite3_errmsg(mpSQLite) << std::endl; - } + // Never throw an exception in a destructor + //std::cout << sqlite3_errmsg(mpSQLite) << std::endl; + SQLITE_CPP_ASSERT (SQLITE_OK == ret); } // Shortcut to execute one or multiple SQL statements without results (UPDATE, INSERT, ALTER, COMMIT...). diff --git a/src/SQLiteC++/Exception.h b/src/SQLiteC++/Exception.h index 9751b66..a768879 100644 --- a/src/SQLiteC++/Exception.h +++ b/src/SQLiteC++/Exception.h @@ -10,6 +10,19 @@ #pragma once #include +#include + + +// assert() is used in destructors, where exceptions are not allowed +// here you can chose if you whant to use them or not +#ifdef _DEBUG + // in debug mode : + #define SQLITE_CPP_ASSERT(expression) assert(expression) +#else + // in release mode : + #define SQLITE_CPP_ASSERT(expression) (expression) +#endif + #ifdef _WIN32 #pragma warning(disable:4290) // Disable warning C4290: C++ exception specification ignored except to indicate a function is not __declspec(nothrow) diff --git a/src/SQLiteC++/Statement.cpp b/src/SQLiteC++/Statement.cpp index b24203b..da84164 100644 --- a/src/SQLiteC++/Statement.cpp +++ b/src/SQLiteC++/Statement.cpp @@ -43,11 +43,10 @@ Statement::~Statement(void) throw() // nothrow { // If count reaches zero, finalize the sqlite3_stmt, as no Column objet use it anymore int ret = sqlite3_finalize(mpStmt); - if (SQLITE_OK != ret) - { - // Never throw an exception in a destructor - //std::cout << sqlite3_errmsg(mpSQLite) << std::endl; - } + // Never throw an exception in a destructor + //std::cout << sqlite3_errmsg(mpSQLite) << std::endl; + SQLITE_CPP_ASSERT (SQLITE_OK == ret); + mpStmt = NULL; // and delete the reference counter diff --git a/src/SQLiteC++/Transaction.cpp b/src/SQLiteC++/Transaction.cpp index 5bf6dcd..627f503 100644 --- a/src/SQLiteC++/Transaction.cpp +++ b/src/SQLiteC++/Transaction.cpp @@ -35,6 +35,7 @@ Transaction::~Transaction(void) throw() // nothrow { // Never throw an exception in a destructor //std::cout << e.what() << std::endl; + SQLITE_CPP_ASSERT(false); } } }