diff --git a/.project b/.project index eb159f5..c3f149d 100644 --- a/.project +++ b/.project @@ -5,6 +5,11 @@ + + org.python.pydev.PyDevBuilder + + + org.eclipse.cdt.managedbuilder.core.genmakebuilder clean,full,incremental, @@ -75,5 +80,6 @@ org.eclipse.cdt.core.ccnature org.eclipse.cdt.managedbuilder.core.managedBuildNature org.eclipse.cdt.managedbuilder.core.ScannerConfigNature + org.python.pydev.pythonNature diff --git a/cpplint.py b/cpplint.py index 9280f96..6b97648 100755 --- a/cpplint.py +++ b/cpplint.py @@ -4499,7 +4499,7 @@ def CheckForIncludeWhatYouUse(filename, clean_lines, include_state, error, template = required[required_header_unstripped][1] if required_header_unstripped.strip('<>"') not in include_state: error(filename, required[required_header_unstripped][0], - 'build/include_what_you_use', 4, + 'build/include_what_you_use', 2, 'Add #include ' + required_header_unstripped + ' for ' + template) diff --git a/include/SQLiteCpp/Column.h b/include/SQLiteCpp/Column.h index 2d8e47b..17798cd 100644 --- a/include/SQLiteCpp/Column.h +++ b/include/SQLiteCpp/Column.h @@ -16,6 +16,7 @@ #include #include +#include namespace SQLite @@ -41,13 +42,6 @@ namespace SQLite class Column { public: - // Make clang happy by explicitly implementing the copy-constructor: - Column(const Column & aOther) : - mStmtPtr(aOther.mStmtPtr), - mIndex(aOther.mIndex) - { - } - /** * @brief Encapsulation of a Column in a Row of the result. * @@ -55,18 +49,25 @@ public: * @param[in] aIndex Index of the column in the row of result */ Column(Statement::Ptr& aStmtPtr, int aIndex) noexcept; // nothrow - /// @brief Simple destructor + /// Simple destructor virtual ~Column() noexcept; // nothrow // default copy constructor and assignment operator are perfectly suited : // they copy the Statement::Ptr which in turn increments the reference counter. + /// Make clang happy by explicitly implementing the copy-constructor: + Column(const Column & aOther) : + mStmtPtr(aOther.mStmtPtr), + mIndex(aOther.mIndex) + { + } + /** * @brief Return a pointer to the named assigned to this result column (potentially aliased) * * @see getOriginName() to get original column name (not aliased) */ - const char* getName() const noexcept; // nothrow + const char* getName() const noexcept; // nothrow #ifdef SQLITE_ENABLE_COLUMN_METADATA /** @@ -76,36 +77,36 @@ 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() const noexcept; // nothrow + const char* getOriginName() const noexcept; // nothrow #endif - /// @brief Return the integer value of the column. - int getInt() const noexcept; // nothrow - /// @brief Return the 64bits integer value of the column. - sqlite3_int64 getInt64() const noexcept; // nothrow - /// @brief Return the double (64bits float) value of the column. - double getDouble() const noexcept; // nothrow + /// Return the integer value of the column. + int getInt() const noexcept; // nothrow + /// Return the 64bits integer value of the column. + int64_t getInt64() const noexcept; // nothrow + /// Return the double (64bits float) value of the column. + double getDouble() 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(const char* apDefaultValue = "") const noexcept; // nothrow + const char* getText(const char* apDefaultValue = "") 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() const noexcept; // nothrow + const void* getBlob() const noexcept; // nothrow /** * @brief Return a std::string for a TEXT or BLOB column. * * Note this correctly handles strings that contain null bytes. * */ - std::string getString() const noexcept; // nothrow + std::string getString() const noexcept; // nothrow /** * @brief Return the type of the value of the column @@ -117,27 +118,27 @@ public: */ int getType() const noexcept; // nothrow - /// @brief Test if the column is an integer type value (meaningful only before any conversion) + /// Test if the column is an integer type value (meaningful only before any conversion) inline bool isInteger() const noexcept // nothrow { return (SQLITE_INTEGER == getType()); } - /// @brief Test if the column is a floating point type value (meaningful only before any conversion) + /// Test if the column is a floating point type value (meaningful only before any conversion) inline bool isFloat() const noexcept // nothrow { return (SQLITE_FLOAT == getType()); } - /// @brief Test if the column is a text type value (meaningful only before any conversion) + /// Test if the column is a text type value (meaningful only before any conversion) inline bool isText() const noexcept // nothrow { return (SQLITE_TEXT == getType()); } - /// @brief Test if the column is a binary blob type value (meaningful only before any conversion) + /// Test if the column is a binary blob type value (meaningful only before any conversion) inline bool isBlob() const noexcept // nothrow { return (SQLITE_BLOB == getType()); } - /// @brief Test if the column is NULL (meaningful only before any conversion) + /// Test if the column is NULL (meaningful only before any conversion) inline bool isNull() const noexcept // nothrow { return (SQLITE_NULL == getType()); @@ -154,28 +155,42 @@ public: */ int getBytes() const noexcept; - /// @brief Alias returning the number of bytes used by the text (or blob) value of the column + /// Alias returning the number of bytes used by the text (or blob) value of the column inline int size() const noexcept { return getBytes (); } - /// @brief Inline cast operator to int + /// Inline cast operator to int inline operator int() const { return getInt(); } - /// @brief Inline cast operator to 32bits unsigned integer +#if !defined(__x86_64__) || defined(__APPLE__) + /// Inline cast operator to long as 32bits integer for 32bit systems + inline operator long() const + { + return getInt(); + } +#endif // __x86_64__ +#if defined(__GNUC__) && !defined(__APPLE__) + /// Inline cast operator to long long for GCC and Clang + inline operator long long() const + { + return getInt64(); + } +#endif // __GNUC__ + /// Inline cast operator to 64bits integer + inline operator int64_t() const + { + return getInt64(); + } + /// Inline cast operator to 32bits unsigned integer inline operator uint32_t() const { return static_cast(getInt64()); } - /// @brief Inline cast operator to 64bits integer - inline operator sqlite3_int64() const - { - return getInt64(); - } - /// @brief Inline cast operator to double + /// Inline cast operator to double inline operator double() const { return getDouble(); @@ -218,18 +233,7 @@ public: } #endif - // NOTE : the following is required by GCC and Clang to cast a Column result in a long/int64_t - /// @brief Inline cast operator to long as 64bits integer - inline operator long() const - { -#ifdef __x86_64__ - return getInt64(); -#else - return getInt(); -#endif - } - - /// @brief Return UTF-8 encoded English language explanation of the most recent error. + /// Return UTF-8 encoded English language explanation of the most recent error. inline const char* errmsg() const { return sqlite3_errmsg(mStmtPtr); diff --git a/include/SQLiteCpp/Database.h b/include/SQLiteCpp/Database.h index 5a8d6b6..45ffb49 100644 --- a/include/SQLiteCpp/Database.h +++ b/include/SQLiteCpp/Database.h @@ -237,7 +237,7 @@ public: * * @return Rowid of the most recent successful INSERT into the database, or 0 if there was none. */ - inline sqlite3_int64 getLastInsertRowid() const noexcept // nothrow + inline int64_t getLastInsertRowid() const noexcept // nothrow { return sqlite3_last_insert_rowid(mpSQLite); } @@ -252,25 +252,25 @@ public: return sqlite3_total_changes(mpSQLite); } - /// @brief Return the filename used to open the database. + /// Return the filename used to open the database. inline const std::string& getFilename() const noexcept // nothrow { return mFilename; } - /// @brief Return the numeric result code for the most recent failed API call (if any). + /// Return the numeric result code for the most recent failed API call (if any). inline int getErrorCode() const noexcept // nothrow { return sqlite3_errcode(mpSQLite); } - /// @brief Return the extended numeric result code for the most recent failed API call (if any). + /// Return the extended numeric result code for the most recent failed API call (if any). inline int getExtendedErrorCode() const noexcept // nothrow { return sqlite3_extended_errcode(mpSQLite); } - /// @brief Return UTF-8 encoded English language explanation of the most recent failed API call (if any). + /// Return UTF-8 encoded English language explanation of the most recent failed API call (if any). inline const char* errmsg() const noexcept // nothrow { return sqlite3_errmsg(mpSQLite); diff --git a/include/SQLiteCpp/Statement.h b/include/SQLiteCpp/Statement.h index d1a8597..4757b46 100644 --- a/include/SQLiteCpp/Statement.h +++ b/include/SQLiteCpp/Statement.h @@ -68,14 +68,10 @@ public: */ Statement(Database& aDatabase, const std::string& aQuery); - /** - * @brief Finalize and unregister the SQL query from the SQLite Database Connection. - */ + /// Finalize and unregister the SQL query from the SQLite Database Connection. virtual ~Statement() noexcept; // nothrow - /** - * @brief Reset the statement to make it ready for a new execution. - */ + /// Reset the statement to make it ready for a new execution. void reset(); /** @@ -110,7 +106,7 @@ public: /** * @brief Bind a 64bits int value to a parameter "?", "?NNN", ":VVV", "@VVV" or "$VVV" in the SQL prepared statement (aIndex >= 1) */ - void bind(const int aIndex, const sqlite3_int64 aValue); + void bind(const int aIndex, const int64_t aValue); /** * @brief Bind a 32bits unsigned int value to a parameter "?", "?NNN", ":VVV", "@VVV" or "$VVV" in the SQL prepared statement (aIndex >= 1) */ @@ -169,7 +165,7 @@ public: /** * @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 int64_t aValue); /** * @brief Bind a 32bits unsigned int value to a named parameter "?NNN", ":VVV", "@VVV" or "$VVV" in the SQL prepared statement (aIndex >= 1) */ @@ -232,7 +228,7 @@ public: /** * @brief Bind a 64bits int value to a named parameter "?NNN", ":VVV", "@VVV" or "$VVV" in the SQL prepared statement (aIndex >= 1) */ - inline void bind(const std::string& aName, const sqlite3_int64 aValue) + inline void bind(const std::string& aName, const int64_t aValue) { bind(aName.c_str(), aValue); } @@ -314,7 +310,6 @@ public: bind(aName.c_str()); } - //////////////////////////////////////////////////////////////////////////// /** @@ -449,32 +444,32 @@ public: //////////////////////////////////////////////////////////////////////////// - /// @brief Return the UTF-8 SQL Query. + /// Return the UTF-8 SQL Query. inline const std::string& getQuery() const { return mQuery; } - /// @brief Return the number of columns in the result set returned by the prepared statement + /// Return the number of columns in the result set returned by the prepared statement inline int getColumnCount() const { return mColumnCount; } - /// @brief true when a row has been fetched with executeStep() + /// true when a row has been fetched with executeStep() inline bool isOk() const { return mbOk; } - /// @brief true when the last executeStep() had no more row to fetch + /// true when the last executeStep() had no more row to fetch inline bool isDone() const { return mbDone; } - /// @brief Return the numeric result code for the most recent failed API call (if any). + /// Return the numeric result code for the most recent failed API call (if any). inline int getErrorCode() const noexcept // nothrow { return sqlite3_errcode(mStmtPtr); } - /// @brief Return the extended numeric result code for the most recent failed API call (if any). + /// Return the extended numeric result code for the most recent failed API call (if any). inline int getExtendedErrorCode() const noexcept // nothrow { return sqlite3_extended_errcode(mStmtPtr); @@ -503,13 +498,13 @@ private: // Decrement the ref counter and finalize the sqlite3_stmt when it reaches 0 ~Ptr() noexcept; // nothrow (no virtual destructor needed here) - /// @brief Inline cast operator returning the pointer to SQLite Database Connection Handle + /// Inline cast operator returning the pointer to SQLite Database Connection Handle inline operator sqlite3*() const { return mpSQLite; } - /// @brief Inline cast operator returning the pointer to SQLite Statement Object + /// Inline cast operator returning the pointer to SQLite Statement Object inline operator sqlite3_stmt*() const { return mpStmt; diff --git a/src/Backup.cpp b/src/Backup.cpp index e495d96..c638239 100644 --- a/src/Backup.cpp +++ b/src/Backup.cpp @@ -15,8 +15,6 @@ #include -#include - namespace SQLite { diff --git a/src/Column.cpp b/src/Column.cpp index 1503039..78efab2 100644 --- a/src/Column.cpp +++ b/src/Column.cpp @@ -11,13 +11,11 @@ #include #include -#include namespace SQLite { - // Encapsulation of a Column in a row of the result pointed by the prepared Statement. Column::Column(Statement::Ptr& aStmtPtr, int aIndex) noexcept : // nothrow mStmtPtr(aStmtPtr), @@ -52,7 +50,7 @@ int Column::getInt() const noexcept // nothrow } // Return the 64bits integer value of the column specified by its index starting at 0 -sqlite3_int64 Column::getInt64() const noexcept // nothrow +int64_t Column::getInt64() const noexcept // nothrow { return sqlite3_column_int64(mStmtPtr, mIndex); } diff --git a/src/Database.cpp b/src/Database.cpp index f125a5b..1322104 100644 --- a/src/Database.cpp +++ b/src/Database.cpp @@ -14,7 +14,6 @@ #include #include -#include #ifndef SQLITE_DETERMINISTIC #define SQLITE_DETERMINISTIC 0x800 diff --git a/src/Statement.cpp b/src/Statement.cpp index 3788734..e141f17 100644 --- a/src/Statement.cpp +++ b/src/Statement.cpp @@ -15,8 +15,6 @@ #include #include -#include - namespace SQLite { @@ -74,7 +72,7 @@ void Statement::bind(const int aIndex, const int aValue) } // 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) +void Statement::bind(const int aIndex, const int64_t aValue) { const int ret = sqlite3_bind_int64(mStmtPtr, aIndex, aValue); check(ret); @@ -155,7 +153,7 @@ void Statement::bind(const char* apName, const int aValue) } // Bind a 64bits int value to a parameter "?NNN", ":VVV", "@VVV" or "$VVV" in the SQL prepared statement -void Statement::bind(const char* apName, const sqlite3_int64 aValue) +void Statement::bind(const char* apName, const int64_t aValue) { const int index = sqlite3_bind_parameter_index(mStmtPtr, apName); const int ret = sqlite3_bind_int64(mStmtPtr, index, aValue); diff --git a/tests/Column_test.cpp b/tests/Column_test.cpp index 920d51f..ee2322a 100644 --- a/tests/Column_test.cpp +++ b/tests/Column_test.cpp @@ -16,7 +16,6 @@ #include #include -#include TEST(Column, basis) { @@ -55,18 +54,20 @@ TEST(Column, basis) { // validates every variant of cast operators, and conversions of types { - sqlite3_int64 id = query.getColumn(0); // operator sqlite3_int64() - int64_t id2 = query.getColumn(0); // operator sqlite3_int64() (or long() with GCC 64bits) - long id3 = query.getColumn(0); // operator sqlite3_int64() (or long() with GCC 64bits) + const sqlite3_int64 id1 = query.getColumn(0); // operator int64_t() + const int64_t id2 = query.getColumn(0); // operator int64_t() + const long long id3 = query.getColumn(0); // operator int64_t() + const long id4 = query.getColumn(0); // operator int64_t() or long() depending on compiler/architecture const char* ptxt = query.getColumn(1); // operator const char*() const std::string msg = query.getColumn(1); // operator std::string() (or const char* with MSVC) const int integer = query.getColumn(2); // operator int() const double real = query.getColumn(3); // operator double() const void* pblob = query.getColumn(4); // operator void*() const void* pempty = query.getColumn(5); // operator void*() - EXPECT_EQ(1, id); + EXPECT_EQ(1, id1); EXPECT_EQ(1, id2); EXPECT_EQ(1, id3); + EXPECT_EQ(1, id4); EXPECT_STREQ("first", ptxt); EXPECT_EQ("first", msg); EXPECT_EQ(123, integer); diff --git a/tests/Statement_test.cpp b/tests/Statement_test.cpp index b8aee3f..b632725 100644 --- a/tests/Statement_test.cpp +++ b/tests/Statement_test.cpp @@ -108,13 +108,15 @@ TEST(Statement, executeStep) { query.executeStep(); EXPECT_TRUE (query.isOk()); EXPECT_FALSE(query.isDone()); - const sqlite3_int64 id = query.getColumn(0); + const int64_t id = query.getColumn(0); const std::string msg = query.getColumn(1); const int integer = query.getColumn(2); + const long integer2= query.getColumn(2); const double real = query.getColumn(3); EXPECT_EQ(1, id); EXPECT_EQ("first", msg); EXPECT_EQ(123, integer); + EXPECT_EQ(123, integer2); EXPECT_EQ(0.123, real); // Step one more time to discover there is nothing more @@ -210,10 +212,10 @@ TEST(Statement, bindings) { insert.clearBindings(); // Fourth row with string/int64/float - const std::string second("second"); - const sqlite_int64 int64 = 12345678900000LL; + const std::string fourth("fourth"); + const int64_t int64 = 12345678900000LL; const float float32 = 0.234f; - insert.bind(1, second); + insert.bind(1, fourth); insert.bind(2, int64); insert.bind(3, float32); EXPECT_EQ(1, insert.exec()); @@ -224,14 +226,14 @@ TEST(Statement, bindings) { EXPECT_TRUE (query.isOk()); EXPECT_FALSE(query.isDone()); EXPECT_EQ(4, query.getColumn(0).getInt64()); - EXPECT_EQ(second, query.getColumn(1).getText()); + EXPECT_EQ(fourth, query.getColumn(1).getText()); EXPECT_EQ(12345678900000LL, query.getColumn(2).getInt64()); EXPECT_EQ(0.234f, query.getColumn(3).getDouble()); // reset() without clearbindings() insert.reset(); - // Fourth row with binary buffer and a null parameter + // Fifth row with binary buffer and a null parameter const char buffer[] = "binary"; insert.bind(1, buffer, sizeof(buffer)); insert.bind(2); @@ -288,7 +290,7 @@ TEST(Statement, bindByName) { // Second row with string/int64/float const std::string second("second"); - const sqlite_int64 int64 = 12345678900000LL; + const int64_t int64 = 12345678900000LL; const float float32 = 0.234f; insert.bind("@msg", second); insert.bind("@int", int64);