diff --git a/include/SQLiteCpp/Column.h b/include/SQLiteCpp/Column.h index 54d9406..cfafa07 100644 --- a/include/SQLiteCpp/Column.h +++ b/include/SQLiteCpp/Column.h @@ -14,7 +14,7 @@ #include #include -#include +#include namespace SQLite @@ -86,10 +86,10 @@ public: /// Return the integer value of the column. int getInt() const noexcept; // nothrow - /// Return the 32bits unsigned integer value of the column (note that SQLite3 does not support uint64_t). - uint32_t getUInt() const noexcept; // nothrow - /// Return the 64bits integer value of the column (note that SQLite3 does not support uint64_t). - int64_t getInt64() const noexcept; // nothrow + /// Return the 32bits unsigned integer value of the column (note that SQLite3 does not support unsigned 64bits). + unsigned getUInt() const noexcept; // nothrow + /// Return the 64bits integer value of the column (note that SQLite3 does not support unsigned 64bits). + long long getInt64() const noexcept; // nothrow /// Return the double (64bits float) value of the column double getDouble() const noexcept; // nothrow /** @@ -171,30 +171,35 @@ public: { return getInt(); } -#if !defined(__x86_64__) || defined(__APPLE__) - /// Inline cast operator to long as 32bits integer for 32bit systems + /// Inline cast operator to 32bits unsigned integer + inline operator unsigned int() const + { + return getUInt(); + } +#if (LONG_MAX == INT_MAX) // sizeof(long)==4 means the data model of the system is ILP32 (32bits OS or Windows 64bits) + /// Inline cast operator to 32bits long 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 cast operator to 32bits unsigned long + inline operator unsigned long() const + { + return getUInt(); + } +#else + /// Inline cast operator to 64bits long when the data model of the system is ILP64 (Linux 64 bits...) + inline operator long() const + { + return getInt64(); + } +#endif + + /// Inline cast operator to 64bits integer 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 getUInt(); - } /// Inline cast operator to double inline operator double() const { diff --git a/include/SQLiteCpp/Database.h b/include/SQLiteCpp/Database.h index 4d044eb..0cf793a 100644 --- a/include/SQLiteCpp/Database.h +++ b/include/SQLiteCpp/Database.h @@ -20,6 +20,7 @@ struct sqlite3_context; struct Mem; typedef struct Mem sqlite3_value; + namespace SQLite { @@ -256,7 +257,7 @@ public: * * @return Rowid of the most recent successful INSERT into the database, or 0 if there was none. */ - int64_t getLastInsertRowid() const noexcept; // nothrow + long long getLastInsertRowid() const noexcept; // nothrow /// Get total number of rows modified by all INSERT, UPDATE or DELETE statement since connection (not DROP table). int getTotalChanges() const noexcept; // nothrow diff --git a/include/SQLiteCpp/Statement.h b/include/SQLiteCpp/Statement.h index 4ae6835..594ee38 100644 --- a/include/SQLiteCpp/Statement.h +++ b/include/SQLiteCpp/Statement.h @@ -10,11 +10,10 @@ */ #pragma once +#include + #include #include -#include - -#include // Forward declarations to avoid inclusion of in a header struct sqlite3; @@ -108,14 +107,14 @@ public: * @brief Bind an int value to a parameter "?", "?NNN", ":VVV", "@VVV" or "$VVV" in the SQL prepared statement (aIndex >= 1) */ void bind(const int aIndex, const int aValue); - /** - * @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 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) */ - void bind(const int aIndex, const uint32_t aValue); + void bind(const int aIndex, const unsigned aValue); + /** + * @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 long long aValue); /** * @brief Bind a double (64bits float) value to a parameter "?", "?NNN", ":VVV", "@VVV" or "$VVV" in the SQL prepared statement (aIndex >= 1) */ @@ -171,14 +170,14 @@ public: * @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); - /** - * @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 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) */ - void bind(const char* apName, const uint32_t aValue); + void bind(const char* apName, const unsigned aValue); + /** + * @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 long long aValue); /** * @brief Bind a double (64bits float) value to a named parameter "?NNN", ":VVV", "@VVV" or "$VVV" in the SQL prepared statement (aIndex >= 1) */ @@ -239,16 +238,16 @@ public: bind(aName.c_str(), 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 32bits unsigned 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 int64_t aValue) + inline void bind(const std::string& aName, const unsigned aValue) { bind(aName.c_str(), 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 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 uint32_t aValue) + inline void bind(const std::string& aName, const long long aValue) { bind(aName.c_str(), aValue); } diff --git a/src/Column.cpp b/src/Column.cpp index 3529f87..c60d300 100644 --- a/src/Column.cpp +++ b/src/Column.cpp @@ -59,13 +59,13 @@ int Column::getInt() const noexcept // nothrow } // Return the unsigned integer value of the column specified by its index starting at 0 -uint32_t Column::getUInt() const noexcept // nothrow +unsigned Column::getUInt() const noexcept // nothrow { - return static_cast(getInt64()); + return static_cast(getInt64()); } // Return the 64bits integer value of the column specified by its index starting at 0 -int64_t Column::getInt64() const noexcept // nothrow +long long Column::getInt64() const noexcept // nothrow { return sqlite3_column_int64(mStmtPtr, mIndex); } diff --git a/src/Database.cpp b/src/Database.cpp index 0ef9145..734545e 100644 --- a/src/Database.cpp +++ b/src/Database.cpp @@ -142,7 +142,7 @@ bool Database::tableExists(const char* apTableName) } // Get the rowid of the most recent successful INSERT into the database from the current connection. -int64_t Database::getLastInsertRowid() const noexcept // nothrow +long long Database::getLastInsertRowid() const noexcept // nothrow { return sqlite3_last_insert_rowid(mpSQLite); } diff --git a/src/Statement.cpp b/src/Statement.cpp index dde461b..6661c08 100644 --- a/src/Statement.cpp +++ b/src/Statement.cpp @@ -72,15 +72,15 @@ void Statement::bind(const int aIndex, const int aValue) check(ret); } -// 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 int64_t aValue) +// Bind a 32bits unsigned int value to a parameter "?", "?NNN", ":VVV", "@VVV" or "$VVV" in the SQL prepared statement +void Statement::bind(const int aIndex, const unsigned aValue) { const int ret = sqlite3_bind_int64(mStmtPtr, aIndex, aValue); check(ret); } -// Bind a 32bits unsigned int value to a parameter "?", "?NNN", ":VVV", "@VVV" or "$VVV" in the SQL prepared statement -void Statement::bind(const int aIndex, const uint32_t 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 long long aValue) { const int ret = sqlite3_bind_int64(mStmtPtr, aIndex, aValue); check(ret); @@ -153,16 +153,16 @@ void Statement::bind(const char* apName, const int aValue) check(ret); } -// 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 int64_t aValue) +// Bind a 32bits unsigned int value to a parameter "?NNN", ":VVV", "@VVV" or "$VVV" in the SQL prepared statement +void Statement::bind(const char* apName, const unsigned aValue) { const int index = sqlite3_bind_parameter_index(mStmtPtr, apName); const int ret = sqlite3_bind_int64(mStmtPtr, index, aValue); check(ret); } -// Bind a 32bits unsigned int value to a parameter "?NNN", ":VVV", "@VVV" or "$VVV" in the SQL prepared statement -void Statement::bind(const char* apName, const uint32_t 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 long long 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 e86c321..a842137 100644 --- a/tests/Column_test.cpp +++ b/tests/Column_test.cpp @@ -18,6 +18,7 @@ #include #include +#include TEST(Column, basis) { diff --git a/tests/Statement_test.cpp b/tests/Statement_test.cpp index 7a0aed9..7f38b6b 100644 --- a/tests/Statement_test.cpp +++ b/tests/Statement_test.cpp @@ -17,6 +17,7 @@ #include #include +#include TEST(Statement, invalid) { @@ -231,7 +232,7 @@ TEST(Statement, bindings) { // Fourth row with string/int64/float { const std::string fourth("fourth"); - const int64_t int64 = 12345678900000LL; + const long long int64 = 12345678900000LL; const float float32 = 0.234f; insert.bind(1, fourth); insert.bind(2, int64); @@ -369,7 +370,7 @@ TEST(Statement, bindByName) { // Second row with string/int64/float { const std::string second("second"); - const int64_t int64 = 12345678900000LL; + const long long int64 = 12345678900000LL; const float float32 = 0.234f; insert.bind("@msg", second); insert.bind("@int", int64);