Style cleanup on top of PR #86

This commit is contained in:
Sébastien Rombauts 2016-07-02 14:11:02 +02:00
parent 9a07f3918d
commit bcdbea2cf8
2 changed files with 26 additions and 25 deletions

View File

@ -68,15 +68,15 @@ public:
*/ */
Statement(Database& aDatabase, const std::string& aQuery); Statement(Database& aDatabase, const std::string& aQuery);
// Require C++11 #if (__cplusplus >= 201103L) || ( defined(_MSC_VER) && (_MSC_VER >= 1600) ) // C++11: Visual Studio 2010
#if ( __cplusplus>= 201103L) || ( defined(_MSC_VER) && (_MSC_VER >= 1900) )
#define Statement_CAN_MOVE 1
/** /**
* @breif Move Constructor * @brief Move Constructor
* *
* (Allows inserting into STL containers that may need to move memory when growing.) * Allows inserting into STL containers that may need to move memory when growing.
*
* @param aOther Statement to move to
*/ */
Statement(Statement &&other); Statement(Statement&& aOther);
#endif #endif
/** /**
@ -113,6 +113,7 @@ public:
// This is under-optimized for static data (a static text define in code) // This is under-optimized for static data (a static text define in code)
// as well as for dynamic allocated buffer which could be transfer to sqlite // as well as for dynamic allocated buffer which could be transfer to sqlite
// instead of being copied. // instead of being copied.
// => if you now what you are doing, use bindNoCopy()
/** /**
* @brief Bind an int value to a parameter "?", "?NNN", ":VVV", "@VVV" or "$VVV" in the SQL prepared statement (aIndex >= 1) * @brief Bind an int value to a parameter "?", "?NNN", ":VVV", "@VVV" or "$VVV" in the SQL prepared statement (aIndex >= 1)
@ -125,7 +126,7 @@ public:
/** /**
* @brief Bind a 32bits unsigned int value to a parameter "?", "?NNN", ":VVV", "@VVV" or "$VVV" in the SQL prepared statement (aIndex >= 1) * @brief Bind a 32bits unsigned int value to a parameter "?", "?NNN", ":VVV", "@VVV" or "$VVV" in the SQL prepared statement (aIndex >= 1)
*/ */
void bind(const int aIndex, const uint32_t aValue); void bind(const int aIndex, const uint32_t aValue);
/** /**
* @brief Bind a double (64bits float) value to a parameter "?", "?NNN", ":VVV", "@VVV" or "$VVV" in the SQL prepared statement (aIndex >= 1) * @brief Bind a double (64bits float) value to a parameter "?", "?NNN", ":VVV", "@VVV" or "$VVV" in the SQL prepared statement (aIndex >= 1)
*/ */
@ -135,34 +136,34 @@ public:
* *
* @note This uses the SQLITE_TRANSIENT flag, making a copy of the data, for SQLite internal use * @note This uses the SQLITE_TRANSIENT flag, making a copy of the data, for SQLite internal use
*/ */
void bind(const int aIndex, const std::string& aValue); void bind(const int aIndex, const std::string& aValue);
/** /**
* @brief Bind a string value to a parameter "?", "?NNN", ":VVV", "@VVV" or "$VVV" in the SQL prepared statement (aIndex >= 1) * @brief Bind a string value to a parameter "?", "?NNN", ":VVV", "@VVV" or "$VVV" in the SQL prepared statement (aIndex >= 1)
* *
* @note This uses the SQLITE_STATIC flag, NOT making a copy of the data. It must exist while executing the statement. * @note This uses the SQLITE_STATIC flag, avoiding a copy of the data. The string must remains unchanged while executing the statement.
*/ */
void bindNoCopy(const int aIndex, const std::string& aValue); void bindNoCopy(const int aIndex, const std::string& aValue);
/** /**
* @brief Bind a text value to a parameter "?", "?NNN", ":VVV", "@VVV" or "$VVV" in the SQL prepared statement (aIndex >= 1) * @brief Bind a text value to a parameter "?", "?NNN", ":VVV", "@VVV" or "$VVV" in the SQL prepared statement (aIndex >= 1)
* *
* @note This uses the SQLITE_TRANSIENT flag, making a copy of the data, for SQLite internal use * @note This uses the SQLITE_TRANSIENT flag, making a copy of the data, for SQLite internal use
*/ */
void bind(const int aIndex, const char* apValue); void bind(const int aIndex, const char* apValue);
/** /**
* @brief Bind a binary blob value to a parameter "?", "?NNN", ":VVV", "@VVV" or "$VVV" in the SQL prepared statement (aIndex >= 1) * @brief Bind a binary blob value to a parameter "?", "?NNN", ":VVV", "@VVV" or "$VVV" in the SQL prepared statement (aIndex >= 1)
* *
* @note This uses the SQLITE_TRANSIENT flag, making a copy of the data, for SQLite internal use * @note This uses the SQLITE_TRANSIENT flag, making a copy of the data, for SQLite internal use
*/ */
void bind(const int aIndex, const void* apValue, const int aSize); void bind(const int aIndex, const void* apValue, const int aSize);
/** /**
* @brief Bind a binary blob value to a parameter "?", "?NNN", ":VVV", "@VVV" or "$VVV" in the SQL prepared statement (aIndex >= 1) * @brief Bind a binary blob value to a parameter "?", "?NNN", ":VVV", "@VVV" or "$VVV" in the SQL prepared statement (aIndex >= 1)
* *
* @note This uses the SQLITE_STATIC flag, NOT making a copy of the data. It must exist while executing the statement. * @note This uses the SQLITE_STATIC flag, NOT making a copy of the data. It must exist while executing the statement.
*/ */
void bindNoCopy(const int aIndex, const void* apValue, const int aSize); void bindNoCopy(const int aIndex, const void* apValue, const int aSize);
/** /**
* @brief Bind a NULL value to a parameter "?", "?NNN", ":VVV", "@VVV" or "$VVV" in the SQL prepared statement (aIndex >= 1) * @brief Bind a NULL value to a parameter "?", "?NNN", ":VVV", "@VVV" or "$VVV" in the SQL prepared statement (aIndex >= 1)
@ -172,19 +173,19 @@ public:
/** /**
* @brief Bind an int value to a named parameter "?NNN", ":VVV", "@VVV" or "$VVV" in the SQL prepared statement (aIndex >= 1) * @brief Bind an int value to a named parameter "?NNN", ":VVV", "@VVV" or "$VVV" in the SQL prepared statement (aIndex >= 1)
*/ */
void bind(const char* apName, const int aValue); void bind(const char* apName, const int aValue);
/** /**
* @brief Bind a 64bits int value to a named parameter "?NNN", ":VVV", "@VVV" or "$VVV" in the SQL prepared statement (aIndex >= 1) * @brief Bind a 64bits int value to a named parameter "?NNN", ":VVV", "@VVV" or "$VVV" in the SQL prepared statement (aIndex >= 1)
*/ */
void bind(const char* apName, const sqlite3_int64 aValue); void bind(const char* apName, const sqlite3_int64 aValue);
/** /**
* @brief Bind a 32bits unsigned int value to a named parameter "?NNN", ":VVV", "@VVV" or "$VVV" in the SQL prepared statement (aIndex >= 1) * @brief Bind a 32bits unsigned int value to a named parameter "?NNN", ":VVV", "@VVV" or "$VVV" in the SQL prepared statement (aIndex >= 1)
*/ */
void bind(const char* apName, const uint32_t aValue); void bind(const char* apName, const uint32_t aValue);
/** /**
* @brief Bind a double (64bits float) value to a named parameter "?NNN", ":VVV", "@VVV" or "$VVV" in the SQL prepared statement (aIndex >= 1) * @brief Bind a double (64bits float) value to a named parameter "?NNN", ":VVV", "@VVV" or "$VVV" in the SQL prepared statement (aIndex >= 1)
*/ */
void bind(const char* apName, const double aValue); void bind(const char* apName, const double aValue);
/** /**
* @brief Bind a string value to a named parameter "?NNN", ":VVV", "@VVV" or "$VVV" in the SQL prepared statement (aIndex >= 1) * @brief Bind a string value to a named parameter "?NNN", ":VVV", "@VVV" or "$VVV" in the SQL prepared statement (aIndex >= 1)
* *

View File

@ -43,15 +43,15 @@ Statement::Statement(Database &aDatabase, const std::string& aQuery) :
mColumnCount = sqlite3_column_count(mStmtPtr); mColumnCount = sqlite3_column_count(mStmtPtr);
} }
#ifdef Statement_CAN_MOVE #if (__cplusplus >= 201103L) || ( defined(_MSC_VER) && (_MSC_VER >= 1600) ) // C++11: Visual Studio 2010
// Move Constructor // Move Constructor
Statement::Statement(Statement &&other): Statement::Statement(Statement&& aOther):
mQuery(std::move(other.mQuery)), mQuery(std::move(aOther.mQuery)),
mStmtPtr(other.mStmtPtr), mStmtPtr(aOther.mStmtPtr), // TODO: need a move operator
mColumnCount(other.mColumnCount), mColumnCount(aOther.mColumnCount),
mColumnNames(std::move(other.mColumnNames)), mColumnNames(std::move(aOther.mColumnNames)),
mbOk(other.mbOk), mbOk(aOther.mbOk),
mbDone(other.mbDone) mbDone(aOther.mbDone)
{ {
// other.mStmtPtr = nullptr; // doesn't support reassigning // other.mStmtPtr = nullptr; // doesn't support reassigning
other.mColumnCount = 0; other.mColumnCount = 0;