mirror of
https://github.com/cuberite/SQLiteCpp.git
synced 2025-08-04 17:56:13 -04:00
Added a small private method Statement::check(ret)
- Throws a SQLite::Exception with the SQLite error message
This commit is contained in:
parent
00d6be86bc
commit
9658ee7e16
@ -45,7 +45,8 @@ Database::~Database(void) throw() // nothrow
|
|||||||
int ret = sqlite3_close(mpSQLite);
|
int ret = sqlite3_close(mpSQLite);
|
||||||
if (SQLITE_OK != ret)
|
if (SQLITE_OK != ret)
|
||||||
{
|
{
|
||||||
std::cout << sqlite3_errmsg(mpSQLite);
|
// Never throw an exception in a destructor
|
||||||
|
//std::cout << sqlite3_errmsg(mpSQLite);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -24,10 +24,7 @@ Statement::Statement(Database &aDatabase, const char* apQuery) : // throw(SQLite
|
|||||||
mbDone(false)
|
mbDone(false)
|
||||||
{
|
{
|
||||||
int ret = sqlite3_prepare_v2(mDatabase.mpSQLite, mQuery.c_str(), mQuery.size(), &mpStmt, NULL);
|
int ret = sqlite3_prepare_v2(mDatabase.mpSQLite, mQuery.c_str(), mQuery.size(), &mpStmt, NULL);
|
||||||
if (SQLITE_OK != ret)
|
check(ret);
|
||||||
{
|
|
||||||
throw SQLite::Exception(sqlite3_errmsg(mDatabase.mpSQLite));
|
|
||||||
}
|
|
||||||
mColumnCount = sqlite3_column_count(mpStmt);
|
mColumnCount = sqlite3_column_count(mpStmt);
|
||||||
mDatabase.registerStatement(*this);
|
mDatabase.registerStatement(*this);
|
||||||
}
|
}
|
||||||
@ -38,7 +35,8 @@ Statement::~Statement(void) throw() // nothrow
|
|||||||
int ret = sqlite3_finalize(mpStmt);
|
int ret = sqlite3_finalize(mpStmt);
|
||||||
if (SQLITE_OK != ret)
|
if (SQLITE_OK != ret)
|
||||||
{
|
{
|
||||||
std::cout << sqlite3_errmsg(mDatabase.mpSQLite);
|
// Never throw an exception in a destructor
|
||||||
|
//std::cout << sqlite3_errmsg(mDatabase.mpSQLite);
|
||||||
}
|
}
|
||||||
mpStmt = NULL;
|
mpStmt = NULL;
|
||||||
mDatabase.unregisterStatement(*this);
|
mDatabase.unregisterStatement(*this);
|
||||||
@ -50,71 +48,49 @@ void Statement::reset(void) // throw(SQLite::Exception)
|
|||||||
mbOk = false;
|
mbOk = false;
|
||||||
mbDone = false;
|
mbDone = false;
|
||||||
int ret = sqlite3_reset(mpStmt);
|
int ret = sqlite3_reset(mpStmt);
|
||||||
if (SQLITE_OK != ret)
|
check(ret);
|
||||||
{
|
|
||||||
throw SQLite::Exception(sqlite3_errmsg(mDatabase.mpSQLite));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Bind an int value to a parameter "?", "?NNN", ":VVV", "@VVV" or "$VVV" in the SQL prepared statement
|
// Bind an int value to a parameter "?", "?NNN", ":VVV", "@VVV" or "$VVV" in the SQL prepared statement
|
||||||
void Statement::bind(const int aIndex, const int& aValue) // throw(SQLite::Exception)
|
void Statement::bind(const int aIndex, const int& aValue) // throw(SQLite::Exception)
|
||||||
{
|
{
|
||||||
int ret = sqlite3_bind_int(mpStmt, aIndex, aValue);
|
int ret = sqlite3_bind_int(mpStmt, aIndex, aValue);
|
||||||
if (SQLITE_OK != ret)
|
check(ret);
|
||||||
{
|
|
||||||
throw SQLite::Exception(sqlite3_errmsg(mDatabase.mpSQLite));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Bind a 64bits int value to a parameter "?", "?NNN", ":VVV", "@VVV" or "$VVV" in the SQL prepared statement
|
// Bind a 64bits int value to a parameter "?", "?NNN", ":VVV", "@VVV" or "$VVV" in the SQL prepared statement
|
||||||
void Statement::bind(const int aIndex, const sqlite3_int64& aValue) // throw(SQLite::Exception)
|
void Statement::bind(const int aIndex, const sqlite3_int64& aValue) // throw(SQLite::Exception)
|
||||||
|
|
||||||
{
|
{
|
||||||
int ret = sqlite3_bind_int64(mpStmt, aIndex, aValue);
|
int ret = sqlite3_bind_int64(mpStmt, aIndex, aValue);
|
||||||
if (SQLITE_OK != ret)
|
check(ret);
|
||||||
{
|
|
||||||
throw SQLite::Exception(sqlite3_errmsg(mDatabase.mpSQLite));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Bind a double (64bits float) value to a parameter "?", "?NNN", ":VVV", "@VVV" or "$VVV" in the SQL prepared statement
|
// Bind a double (64bits float) value to a parameter "?", "?NNN", ":VVV", "@VVV" or "$VVV" in the SQL prepared statement
|
||||||
void Statement::bind(const int aIndex, const double& aValue) // throw(SQLite::Exception)
|
void Statement::bind(const int aIndex, const double& aValue) // throw(SQLite::Exception)
|
||||||
{
|
{
|
||||||
int ret = sqlite3_bind_double(mpStmt, aIndex, aValue);
|
int ret = sqlite3_bind_double(mpStmt, aIndex, aValue);
|
||||||
if (SQLITE_OK != ret)
|
check(ret);
|
||||||
{
|
|
||||||
throw SQLite::Exception(sqlite3_errmsg(mDatabase.mpSQLite));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Bind a string value to a parameter "?", "?NNN", ":VVV", "@VVV" or "$VVV" in the SQL prepared statement
|
// Bind a string value to a parameter "?", "?NNN", ":VVV", "@VVV" or "$VVV" in the SQL prepared statement
|
||||||
void Statement::bind(const int aIndex, const std::string& aValue) // throw(SQLite::Exception)
|
void Statement::bind(const int aIndex, const std::string& aValue) // throw(SQLite::Exception)
|
||||||
{
|
{
|
||||||
int ret = sqlite3_bind_text(mpStmt, aIndex, aValue.c_str(), aValue.size(), SQLITE_TRANSIENT);
|
int ret = sqlite3_bind_text(mpStmt, aIndex, aValue.c_str(), aValue.size(), SQLITE_TRANSIENT);
|
||||||
if (SQLITE_OK != ret)
|
check(ret);
|
||||||
{
|
|
||||||
throw SQLite::Exception(sqlite3_errmsg(mDatabase.mpSQLite));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Bind a text value to a parameter "?", "?NNN", ":VVV", "@VVV" or "$VVV" in the SQL prepared statement
|
// Bind a text value to a parameter "?", "?NNN", ":VVV", "@VVV" or "$VVV" in the SQL prepared statement
|
||||||
void Statement::bind(const int aIndex, const char* apValue) // throw(SQLite::Exception)
|
void Statement::bind(const int aIndex, const char* apValue) // throw(SQLite::Exception)
|
||||||
{
|
{
|
||||||
int ret = sqlite3_bind_text(mpStmt, aIndex, apValue, -1, SQLITE_TRANSIENT);
|
int ret = sqlite3_bind_text(mpStmt, aIndex, apValue, -1, SQLITE_TRANSIENT);
|
||||||
if (SQLITE_OK != ret)
|
check(ret);
|
||||||
{
|
|
||||||
throw SQLite::Exception(sqlite3_errmsg(mDatabase.mpSQLite));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Bind a NULL value to a parameter "?", "?NNN", ":VVV", "@VVV" or "$VVV" in the SQL prepared statement
|
// Bind a NULL value to a parameter "?", "?NNN", ":VVV", "@VVV" or "$VVV" in the SQL prepared statement
|
||||||
void Statement::bind(const int aIndex) // throw(SQLite::Exception)
|
void Statement::bind(const int aIndex) // throw(SQLite::Exception)
|
||||||
{
|
{
|
||||||
int ret = sqlite3_bind_null(mpStmt, aIndex);
|
int ret = sqlite3_bind_null(mpStmt, aIndex);
|
||||||
if (SQLITE_OK != ret)
|
check(ret);
|
||||||
{
|
|
||||||
throw SQLite::Exception(sqlite3_errmsg(mDatabase.mpSQLite));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Execute a step of the query to fetch one row of results
|
// Execute a step of the query to fetch one row of results
|
||||||
@ -217,4 +193,17 @@ bool Statement::isColumnNull(const int aIndex) const // throw(SQLite::Exception)
|
|||||||
return (SQLITE_NULL == sqlite3_column_type(mpStmt, aIndex));
|
return (SQLITE_NULL == sqlite3_column_type(mpStmt, aIndex));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Check if aRet equal SQLITE_OK, else throw a SQLite::Exception with the SQLite error message
|
||||||
|
*/
|
||||||
|
void Statement::check(const int aRet) const // throw(SQLite::Exception)
|
||||||
|
{
|
||||||
|
if (SQLITE_OK != aRet)
|
||||||
|
{
|
||||||
|
throw SQLite::Exception(sqlite3_errmsg(mDatabase.mpSQLite));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}; // namespace SQLite
|
}; // namespace SQLite
|
||||||
|
@ -136,6 +136,12 @@ public:
|
|||||||
return mbDone;
|
return mbDone;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
/**
|
||||||
|
* @brief Check if aRet equal SQLITE_OK, else throw a SQLite::Exception with the SQLite error message
|
||||||
|
*/
|
||||||
|
void check(const int aRet) const; // throw(SQLite::Exception);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
sqlite3_stmt* mpStmt; //!< Pointeur to SQLite Statement Object
|
sqlite3_stmt* mpStmt; //!< Pointeur to SQLite Statement Object
|
||||||
Database& mDatabase; //!< Reference to the SQLite Database Connection
|
Database& mDatabase; //!< Reference to the SQLite Database Connection
|
||||||
|
Loading…
x
Reference in New Issue
Block a user