mirror of
https://github.com/cuberite/SQLiteCpp.git
synced 2025-08-04 17:56:13 -04:00
Using (optional) assert() on errors in destructors, where exceptions are not allowed
This commit is contained in:
parent
3f226983f0
commit
4448038af4
4
Makefile
4
Makefile
@ -13,10 +13,10 @@ BUILD ?= Debug
|
|||||||
### Conditionally set variables: ###
|
### Conditionally set variables: ###
|
||||||
|
|
||||||
ifeq ($(BUILD),Debug)
|
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
|
endif
|
||||||
ifeq ($(BUILD),Release)
|
ifeq ($(BUILD),Release)
|
||||||
BUILD_FLAGS = -O2
|
BUILD_FLAGS = -O2 -DNDEBUG
|
||||||
endif
|
endif
|
||||||
ifeq ($(BUILD),Debug)
|
ifeq ($(BUILD),Debug)
|
||||||
LINK_FLAGS = -g3 -rdynamic
|
LINK_FLAGS = -g3 -rdynamic
|
||||||
|
4
TODO.txt
4
TODO.txt
@ -4,11 +4,11 @@ C++11 explicit support
|
|||||||
|
|
||||||
Adding an encapsulation to the statement ref counter
|
Adding an encapsulation to the statement ref counter
|
||||||
|
|
||||||
Using (optionnal) assert() on errors in destructors
|
|
||||||
|
|
||||||
copyright 2013
|
copyright 2013
|
||||||
|
|
||||||
|
|
||||||
=> V0.5.0
|
=> V0.5.0
|
||||||
|
using assert() in example program to provide a basic test coverage
|
||||||
|
|
||||||
Missing features in v0.4.0:
|
Missing features in v0.4.0:
|
||||||
- Blob
|
- Blob
|
||||||
|
@ -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
|
// When count reaches zero, finalize the sqlite3_stmt, as no Column nor Statement object use it any more
|
||||||
int ret = sqlite3_finalize(mpStmt);
|
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
|
SQLITE_CPP_ASSERT (SQLITE_OK == ret);
|
||||||
//std::cout << sqlite3_errmsg(mpSQLite) << std::endl;
|
|
||||||
}
|
|
||||||
mpStmt = NULL;
|
mpStmt = NULL;
|
||||||
|
|
||||||
// and delete the reference counter
|
// and delete the reference counter
|
||||||
|
@ -34,11 +34,9 @@ Database::Database(const char* apFilename, const int aFlags /*= SQLITE_OPEN_READ
|
|||||||
Database::~Database(void) throw() // nothrow
|
Database::~Database(void) throw() // nothrow
|
||||||
{
|
{
|
||||||
int ret = sqlite3_close(mpSQLite);
|
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
|
SQLITE_CPP_ASSERT (SQLITE_OK == ret);
|
||||||
//std::cout << sqlite3_errmsg(mpSQLite) << std::endl;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Shortcut to execute one or multiple SQL statements without results (UPDATE, INSERT, ALTER, COMMIT...).
|
// Shortcut to execute one or multiple SQL statements without results (UPDATE, INSERT, ALTER, COMMIT...).
|
||||||
|
@ -10,6 +10,19 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
|
#include <cassert>
|
||||||
|
|
||||||
|
|
||||||
|
// 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
|
#ifdef _WIN32
|
||||||
#pragma warning(disable:4290) // Disable warning C4290: C++ exception specification ignored except to indicate a function is not __declspec(nothrow)
|
#pragma warning(disable:4290) // Disable warning C4290: C++ exception specification ignored except to indicate a function is not __declspec(nothrow)
|
||||||
|
@ -43,11 +43,10 @@ Statement::~Statement(void) throw() // nothrow
|
|||||||
{
|
{
|
||||||
// If count reaches zero, finalize the sqlite3_stmt, as no Column objet use it anymore
|
// If count reaches zero, finalize the sqlite3_stmt, as no Column objet use it anymore
|
||||||
int ret = sqlite3_finalize(mpStmt);
|
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
|
SQLITE_CPP_ASSERT (SQLITE_OK == ret);
|
||||||
//std::cout << sqlite3_errmsg(mpSQLite) << std::endl;
|
|
||||||
}
|
|
||||||
mpStmt = NULL;
|
mpStmt = NULL;
|
||||||
|
|
||||||
// and delete the reference counter
|
// and delete the reference counter
|
||||||
|
@ -35,6 +35,7 @@ Transaction::~Transaction(void) throw() // nothrow
|
|||||||
{
|
{
|
||||||
// Never throw an exception in a destructor
|
// Never throw an exception in a destructor
|
||||||
//std::cout << e.what() << std::endl;
|
//std::cout << e.what() << std::endl;
|
||||||
|
SQLITE_CPP_ASSERT(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user