Cleanup on PR #142 : remove whitespaces and mutualize some code

This commit is contained in:
Sébastien Rombauts 2017-08-28 16:00:50 +02:00
parent f4947e7a03
commit 94c7897d1b
2 changed files with 9 additions and 12 deletions

View File

@ -75,11 +75,10 @@ public:
/// Finalize and unregister the SQL query from the SQLite Database Connection. /// Finalize and unregister the SQL query from the SQLite Database Connection.
~Statement(); ~Statement();
/// Reset the statement to make it ready for a new execution. /// Reset the statement to make it ready for a new execution. Throws an exception on error.
void reset(); void reset();
/// Reset the statement to make it ready for a new execution. Returns the sqlite result code /// Reset the statement. Returns the sqlite result code instead of throwing an exception on error.
/// instead of throwing an exception on error.
int tryReset() noexcept; int tryReset() noexcept;
/** /**
@ -350,7 +349,7 @@ public:
* @throw SQLite::Exception in case of error * @throw SQLite::Exception in case of error
*/ */
bool executeStep(); bool executeStep();
/** /**
* @brief Try to execute a step of the prepared query to fetch one row of results, returning the sqlite result code. * @brief Try to execute a step of the prepared query to fetch one row of results, returning the sqlite result code.
* *

View File

@ -52,9 +52,7 @@ Statement::~Statement()
// Reset the statement to make it ready for a new execution (see also #clearBindings() bellow) // Reset the statement to make it ready for a new execution (see also #clearBindings() bellow)
void Statement::reset() void Statement::reset()
{ {
mbOk = false; const int ret = tryReset();
mbDone = false;
const int ret = sqlite3_reset(mStmtPtr);
check(ret); check(ret);
} }
@ -62,8 +60,7 @@ int Statement::tryReset() noexcept
{ {
mbOk = false; mbOk = false;
mbDone = false; mbDone = false;
const int ret = sqlite3_reset(mStmtPtr); return sqlite3_reset(mStmtPtr);
return ret;
} }
// Clears away all the bindings of a prepared statement (can be associated with #reset() above). // Clears away all the bindings of a prepared statement (can be associated with #reset() above).
@ -274,7 +271,8 @@ bool Statement::executeStep()
return mbOk; // true only if one row is accessible by getColumn(N) return mbOk; // true only if one row is accessible by getColumn(N)
} }
int Statement::tryExecuteStep() noexcept { int Statement::tryExecuteStep() noexcept
{
const int ret = sqlite3_step(mStmtPtr); const int ret = sqlite3_step(mStmtPtr);
if (SQLITE_ROW == ret) // one row is ready : call getColumn(N) to access it if (SQLITE_ROW == ret) // one row is ready : call getColumn(N) to access it
{ {
@ -290,7 +288,7 @@ int Statement::tryExecuteStep() noexcept {
mbOk = false; mbOk = false;
mbDone = false; mbDone = false;
} }
return ret; return ret;
} }