mirror of
https://github.com/cuberite/SQLiteCpp.git
synced 2025-08-04 09:46:02 -04:00
Using the C++11 "noexcept" keyword instead of "throw()"
- added a compatibility #define for older compilers
This commit is contained in:
parent
b2a34a1ee4
commit
b0e9104047
@ -43,8 +43,3 @@ namespace SQLite
|
||||
#define SQLITECPP_ASSERT(expression,message) assert(expression && message)
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
#if defined(_WIN32) && defined(_MSC_VER)
|
||||
#pragma warning(disable:4290) // Disable warning C4290: C++ exception specification ignored except to indicate a function is not __declspec(nothrow)
|
||||
#endif
|
||||
|
@ -18,70 +18,71 @@ namespace SQLite
|
||||
|
||||
|
||||
// Encapsulation of a Column in a row of the result pointed by the prepared Statement.
|
||||
Column::Column(Statement::Ptr& aStmtPtr, int aIndex) throw() : // nothrow
|
||||
Column::Column(Statement::Ptr& aStmtPtr, int aIndex) noexcept : // nothrow
|
||||
mStmtPtr (aStmtPtr),
|
||||
mIndex (aIndex)
|
||||
{
|
||||
}
|
||||
|
||||
// Finalize and unregister the SQL query from the SQLite Database Connection.
|
||||
Column::~Column(void) throw() // nothrow
|
||||
Column::~Column(void) noexcept // nothrow
|
||||
{
|
||||
// the finalization will be done by the destructor of the last shared pointer
|
||||
}
|
||||
|
||||
// Return the named assigned to this result column (potentially aliased)
|
||||
const char * Column::getName(void) const throw() // nothrow
|
||||
const char * Column::getName(void) const noexcept // nothrow
|
||||
{
|
||||
return sqlite3_column_name(mStmtPtr, mIndex);
|
||||
}
|
||||
|
||||
#ifdef SQLITE_ENABLE_COLUMN_METADATA
|
||||
// Return the name of the table column that is the origin of this result column
|
||||
const char * Column::getOriginName(void) const throw() // nothrow
|
||||
const char * Column::getOriginName(void) const noexcept // nothrow
|
||||
{
|
||||
return sqlite3_column_origin_name(mStmtPtr, mIndex);
|
||||
}
|
||||
#endif
|
||||
|
||||
// Return the integer value of the column specified by its index starting at 0
|
||||
int Column::getInt(void) const throw() // nothrow
|
||||
int Column::getInt(void) const noexcept // nothrow
|
||||
{
|
||||
return sqlite3_column_int(mStmtPtr, mIndex);
|
||||
}
|
||||
|
||||
// Return the 64bits integer value of the column specified by its index starting at 0
|
||||
sqlite3_int64 Column::getInt64(void) const throw() // nothrow
|
||||
sqlite3_int64 Column::getInt64(void) const noexcept // nothrow
|
||||
{
|
||||
return sqlite3_column_int64(mStmtPtr, mIndex);
|
||||
}
|
||||
|
||||
// Return the double value of the column specified by its index starting at 0
|
||||
double Column::getDouble(void) const throw() // nothrow
|
||||
double Column::getDouble(void) const noexcept // nothrow
|
||||
{
|
||||
return sqlite3_column_double(mStmtPtr, mIndex);
|
||||
}
|
||||
|
||||
// Return a pointer to the text value (NULL terminated string) of the column specified by its index starting at 0
|
||||
const char* Column::getText(void) const throw() // nothrow
|
||||
const char* Column::getText(void) const noexcept // nothrow
|
||||
{
|
||||
// TODO what if NULL !?
|
||||
return (const char*)sqlite3_column_text(mStmtPtr, mIndex);
|
||||
}
|
||||
|
||||
// Return a pointer to the text value (NULL terminated string) of the column specified by its index starting at 0
|
||||
const void* Column::getBlob(void) const throw() // nothrow
|
||||
const void* Column::getBlob(void) const noexcept // nothrow
|
||||
{
|
||||
return sqlite3_column_blob(mStmtPtr, mIndex);
|
||||
}
|
||||
|
||||
// Return the type of the value of the column
|
||||
int Column::getType(void) const throw() // nothrow
|
||||
int Column::getType(void) const noexcept // nothrow
|
||||
{
|
||||
return sqlite3_column_type(mStmtPtr, mIndex);
|
||||
}
|
||||
|
||||
// Return the number of bytes used by the text value of the column
|
||||
int Column::getBytes(void) const throw() // nothrow
|
||||
int Column::getBytes(void) const noexcept // nothrow
|
||||
{
|
||||
return sqlite3_column_bytes(mStmtPtr, mIndex);
|
||||
}
|
||||
|
36
src/Column.h
36
src/Column.h
@ -13,6 +13,7 @@
|
||||
#include <sqlite3.h>
|
||||
|
||||
#include "Statement.h"
|
||||
#include "Exception.h"
|
||||
|
||||
|
||||
namespace SQLite
|
||||
@ -44,9 +45,9 @@ public:
|
||||
* @param[in] aStmtPtr Shared pointer to the prepared SQLite Statement Object.
|
||||
* @param[in] aIndex Index of the column in the row of result
|
||||
*/
|
||||
Column(Statement::Ptr& aStmtPtr, int aIndex) throw(); // nothrow
|
||||
Column(Statement::Ptr& aStmtPtr, int aIndex) noexcept; // nothrow
|
||||
/// @brief Simple destructor
|
||||
virtual ~Column(void) throw(); // nothrow
|
||||
virtual ~Column(void) noexcept; // nothrow
|
||||
|
||||
// default copy constructor and assignment operator are perfectly suited :
|
||||
// they copy the Statement::Ptr which in turn increments the reference counter.
|
||||
@ -54,7 +55,7 @@ public:
|
||||
/**
|
||||
* @brief Return a pointer to the named assigned to a result column (potentially aliased)
|
||||
*/
|
||||
const char* getName (void) const throw(); // nothrow
|
||||
const char* getName (void) const noexcept; // nothrow
|
||||
|
||||
#ifdef SQLITE_ENABLE_COLUMN_METADATA
|
||||
/**
|
||||
@ -64,29 +65,29 @@ public:
|
||||
* - when building the SQLite library itself (which is the case for the Debian libsqlite3 binary for instance),
|
||||
* - and also when compiling this wrapper.
|
||||
*/
|
||||
const char* getOriginName (void) const throw(); // nothrow
|
||||
const char* getOriginName (void) const noexcept; // nothrow
|
||||
#endif
|
||||
|
||||
/// @brief Return the integer value of the column.
|
||||
int getInt (void) const throw(); // nothrow
|
||||
int getInt (void) const noexcept; // nothrow
|
||||
/// @brief Return the 64bits integer value of the column.
|
||||
sqlite3_int64 getInt64 (void) const throw(); // nothrow
|
||||
sqlite3_int64 getInt64 (void) const noexcept; // nothrow
|
||||
/// @brief Return the double (64bits float) value of the column.
|
||||
double getDouble(void) const throw(); // nothrow
|
||||
double getDouble(void) const noexcept; // nothrow
|
||||
/**
|
||||
* @brief Return a pointer to the text value (NULL terminated string) of the column.
|
||||
*
|
||||
* @warning The value pointed at is only valid while the statement is valid (ie. not finalized),
|
||||
* thus you must copy it before using it beyond its scope (to a std::string for instance).
|
||||
*/
|
||||
const char* getText (void) const throw(); // nothrow
|
||||
const char* getText (void) const noexcept; // nothrow
|
||||
/**
|
||||
* @brief Return a pointer to the binary blob value of the column.
|
||||
*
|
||||
* @warning The value pointed at is only valid while the statement is valid (ie. not finalized),
|
||||
* thus you must copy it before using it beyond its scope (to a std::string for instance).
|
||||
*/
|
||||
const void* getBlob (void) const throw(); // nothrow
|
||||
const void* getBlob (void) const noexcept; // nothrow
|
||||
|
||||
/**
|
||||
* @brief Return the type of the value of the column
|
||||
@ -96,30 +97,30 @@ public:
|
||||
* @warning After a type conversion (by a call to a getXxx on a Column of a Yyy type),
|
||||
* the value returned by sqlite3_column_type() is undefined.
|
||||
*/
|
||||
int getType(void) const throw(); // nothrow
|
||||
int getType(void) const noexcept; // nothrow
|
||||
|
||||
/// @brief Test if the column is an integer type value (meaningful only before any conversion)
|
||||
inline bool isInteger(void) const throw() // nothrow
|
||||
inline bool isInteger(void) const noexcept // nothrow
|
||||
{
|
||||
return (SQLITE_INTEGER == getType());
|
||||
}
|
||||
/// @brief Test if the column is a floating point type value (meaningful only before any conversion)
|
||||
inline bool isFloat(void) const throw() // nothrow
|
||||
inline bool isFloat(void) const noexcept // nothrow
|
||||
{
|
||||
return (SQLITE_FLOAT == getType());
|
||||
}
|
||||
/// @brief Test if the column is a text type value (meaningful only before any conversion)
|
||||
inline bool isText(void) const throw() // nothrow
|
||||
inline bool isText(void) const noexcept // nothrow
|
||||
{
|
||||
return (SQLITE_TEXT == getType());
|
||||
}
|
||||
/// @brief Test if the column is a binary blob type value (meaningful only before any conversion)
|
||||
inline bool isBlob(void) const throw() // nothrow
|
||||
inline bool isBlob(void) const noexcept // nothrow
|
||||
{
|
||||
return (SQLITE_BLOB == getType());
|
||||
}
|
||||
/// @brief Test if the column is NULL (meaningful only before any conversion)
|
||||
inline bool isNull(void) const throw() // nothrow
|
||||
inline bool isNull(void) const noexcept // nothrow
|
||||
{
|
||||
return (SQLITE_NULL == getType());
|
||||
}
|
||||
@ -133,10 +134,10 @@ public:
|
||||
* - size in bytes of the binary blob returned by getBlob()
|
||||
* - 0 for a NULL value
|
||||
*/
|
||||
int getBytes(void) const throw();
|
||||
int getBytes(void) const noexcept;
|
||||
|
||||
/// @brief Alias returning the number of bytes used by the text (or blob) value of the column
|
||||
inline int size(void) const throw()
|
||||
inline int size(void) const noexcept
|
||||
{
|
||||
return getBytes ();
|
||||
}
|
||||
@ -183,6 +184,7 @@ public:
|
||||
/// Inline cast operator to std::string
|
||||
inline operator const std::string() const
|
||||
{
|
||||
// TODO what if NULL !?
|
||||
return getText();
|
||||
}
|
||||
#endif
|
||||
|
@ -51,7 +51,7 @@ Database::Database(const std::string& aFilename, const int aFlags /*= SQLITE_OPE
|
||||
}
|
||||
|
||||
// Close the SQLite database connection.
|
||||
Database::~Database(void) throw() // nothrow
|
||||
Database::~Database(void) noexcept // nothrow
|
||||
{
|
||||
int ret = sqlite3_close(mpSQLite);
|
||||
// Never throw an exception in a destructor
|
||||
|
@ -79,7 +79,7 @@ public:
|
||||
* All SQLite statements must have been finalized before,
|
||||
* so all Statement objects must have been unregistered.
|
||||
*/
|
||||
virtual ~Database(void) throw(); // nothrow
|
||||
virtual ~Database(void) noexcept; // nothrow
|
||||
|
||||
/**
|
||||
* @brief Shortcut to execute one or multiple statements without results.
|
||||
@ -201,7 +201,7 @@ public:
|
||||
*
|
||||
* @param[in] aTimeoutMs Amount of milliseconds to wait before returning SQLITE_BUSY
|
||||
*/
|
||||
inline int setBusyTimeout(int aTimeoutMs) // throw(); nothrow
|
||||
inline int setBusyTimeout(int aTimeoutMs) // noexcept; nothrow
|
||||
{
|
||||
return sqlite3_busy_timeout(mpSQLite, aTimeoutMs);
|
||||
}
|
||||
@ -211,7 +211,7 @@ public:
|
||||
*
|
||||
* @return Rowid of the most recent successful INSERT into the database, or 0 if there was none.
|
||||
*/
|
||||
inline sqlite3_int64 getLastInsertRowid(void) const // throw(); nothrow
|
||||
inline sqlite3_int64 getLastInsertRowid(void) const // noexcept; nothrow
|
||||
{
|
||||
return sqlite3_last_insert_rowid(mpSQLite);
|
||||
}
|
||||
|
@ -36,3 +36,20 @@ public:
|
||||
|
||||
|
||||
} // namespace SQLite
|
||||
|
||||
|
||||
/// Compatibility with non-clang compilers.
|
||||
#ifndef __has_feature
|
||||
#define __has_feature(x) 0
|
||||
#endif
|
||||
|
||||
// Detect whether the compiler supports C++11 noexcept exception specifications.
|
||||
#if (defined(__GNUC__) && (__GNUC__ >= 4 && __GNUC_MINOR__ >= 7 ) && defined(__GXX_EXPERIMENTAL_CXX0X__))
|
||||
// GCC 4.7 and following have noexcept
|
||||
#elif defined(__clang__) && __has_feature(cxx_noexcept)
|
||||
// Clang 3.0 and above have noexcept
|
||||
#elif defined(_MSC_VER) && (_MSC_VER >= 1700)
|
||||
// Visual Studio 2012 and above have noexcept
|
||||
#else
|
||||
#define noexcept throw()
|
||||
#endif
|
||||
|
@ -42,7 +42,7 @@ Statement::Statement(Database &aDatabase, const std::string& aQuery) : // throw(
|
||||
}
|
||||
|
||||
// Finalize and unregister the SQL query from the SQLite Database Connection.
|
||||
Statement::~Statement(void) throw() // nothrow
|
||||
Statement::~Statement(void) noexcept // nothrow
|
||||
{
|
||||
// the finalization will be done by the destructor of the last shared pointer
|
||||
}
|
||||
@ -315,7 +315,7 @@ Statement::Ptr::Ptr(const Statement::Ptr& aPtr) :
|
||||
/**
|
||||
* @brief Decrement the ref counter and finalize the sqlite3_stmt when it reaches 0
|
||||
*/
|
||||
Statement::Ptr::~Ptr(void) throw() // nothrow
|
||||
Statement::Ptr::~Ptr(void) noexcept // nothrow
|
||||
{
|
||||
assert(NULL != mpRefCount);
|
||||
assert(0 != *mpRefCount);
|
||||
|
@ -13,6 +13,8 @@
|
||||
#include <sqlite3.h>
|
||||
#include <string>
|
||||
|
||||
#include "Exception.h"
|
||||
|
||||
|
||||
namespace SQLite
|
||||
{
|
||||
@ -67,7 +69,7 @@ public:
|
||||
/**
|
||||
* @brief Finalize and unregister the SQL query from the SQLite Database Connection.
|
||||
*/
|
||||
virtual ~Statement(void) throw(); // nothrow
|
||||
virtual ~Statement(void) noexcept; // nothrow
|
||||
|
||||
/**
|
||||
* @brief Reset the statement to make it ready for a new execution.
|
||||
@ -341,7 +343,7 @@ public:
|
||||
// Copy constructor increments the ref counter
|
||||
Ptr(const Ptr& aPtr);
|
||||
// Decrement the ref counter and finalize the sqlite3_stmt when it reaches 0
|
||||
~Ptr(void) throw(); // nothrow (no virtual destructor needed here)
|
||||
~Ptr(void) noexcept; // nothrow (no virtual destructor needed here)
|
||||
|
||||
/// @brief Inline cast operator returning the pointer to SQLite Database Connection Handle
|
||||
inline operator sqlite3*() const
|
||||
|
@ -12,7 +12,6 @@
|
||||
|
||||
#include "Database.h"
|
||||
#include "Assertion.h"
|
||||
#include "Exception.h"
|
||||
|
||||
|
||||
namespace SQLite
|
||||
@ -28,7 +27,7 @@ Transaction::Transaction(Database& aDatabase) : // throw(SQLite::Exception)
|
||||
}
|
||||
|
||||
// Safely rollback the transaction if it has not been committed.
|
||||
Transaction::~Transaction(void) throw() // nothrow
|
||||
Transaction::~Transaction(void) noexcept // nothrow
|
||||
{
|
||||
if (false == mbCommited)
|
||||
{
|
||||
|
@ -10,6 +10,8 @@
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include "Exception.h"
|
||||
|
||||
|
||||
namespace SQLite
|
||||
{
|
||||
@ -53,7 +55,7 @@ public:
|
||||
/**
|
||||
* @brief Safely rollback the transaction if it has not been committed.
|
||||
*/
|
||||
virtual ~Transaction(void) throw(); // nothrow
|
||||
virtual ~Transaction(void) noexcept; // nothrow
|
||||
|
||||
/**
|
||||
* @brief Commit the transaction.
|
||||
|
Loading…
x
Reference in New Issue
Block a user