diff --git a/include/SQLiteCpp/Assertion.h b/include/SQLiteCpp/Assertion.h index b6d00be..466c86d 100644 --- a/include/SQLiteCpp/Assertion.h +++ b/include/SQLiteCpp/Assertion.h @@ -26,7 +26,7 @@ namespace SQLite { // declaration of the assert handler to define in user code - void assertion_failed(const char* apFile, const long apLine, const char* apFunc, + void assertion_failed(const char* apFile, const int apLine, const char* apFunc, const char* apExpr, const char* apMsg); #ifdef _MSC_VER diff --git a/include/SQLiteCpp/Column.h b/include/SQLiteCpp/Column.h index bc349f9..d9e7c34 100644 --- a/include/SQLiteCpp/Column.h +++ b/include/SQLiteCpp/Column.h @@ -15,7 +15,6 @@ #include #include -#include // For INT_MAX // Forward declarations to avoid inclusion of in a header struct sqlite3_stmt; @@ -79,11 +78,11 @@ public: #endif /// Return the integer value of the column. - int getInt() const noexcept; + int32_t getInt() const noexcept; /// Return the 32bits unsigned integer value of the column (note that SQLite3 does not support unsigned 64bits). - unsigned getUInt() const noexcept; + uint32_t getUInt() const noexcept; /// Return the 64bits integer value of the column (note that SQLite3 does not support unsigned 64bits). - long long getInt64() const noexcept; + int64_t getInt64() const noexcept; /// Return the double (64bits float) value of the column double getDouble() const noexcept; /** @@ -160,62 +159,39 @@ public: return getBytes (); } - /// Inline cast operator to char + /// Inline cast operators to basic types operator char() const { return static_cast(getInt()); } - /// Inline cast operator to unsigned char - operator unsigned char() const + operator int8_t() const { - return static_cast(getInt()); + return static_cast(getInt()); } - /// Inline cast operator to short - operator short() const + operator uint8_t() const { - return static_cast(getInt()); + return static_cast(getInt()); } - /// Inline cast operator to unsigned short - operator unsigned short() const + operator int16_t() const { - return static_cast(getInt()); + return static_cast(getInt()); } - - /// Inline cast operator to int - operator int() const + operator uint16_t() const + { + return static_cast(getInt()); + } + operator int32_t() const { return getInt(); } - /// Inline cast operator to 32bits unsigned integer - operator unsigned int() const + operator uint32_t() const { return getUInt(); } -#if (LONG_MAX == INT_MAX) // 4 bytes "long" type means the data model is ILP32 or LLP64 (Win64 Visual C++ and MinGW) - /// Inline cast operator to 32bits long - operator long() const - { - return getInt(); - } - /// Inline cast operator to 32bits unsigned long - operator unsigned long() const - { - return getUInt(); - } -#else // 8 bytes "long" type means the data model is LP64 (Most Unix-like, Windows when using Cygwin; z/OS) - /// Inline cast operator to 64bits long when the data model of the system is LP64 (Linux 64 bits...) - operator long() const + operator int64_t() const { return getInt64(); } -#endif - - /// Inline cast operator to 64bits integer - operator long long() const - { - return getInt64(); - } - /// Inline cast operator to double operator double() const { return getDouble(); diff --git a/include/SQLiteCpp/Database.h b/include/SQLiteCpp/Database.h index a331961..3f55e50 100644 --- a/include/SQLiteCpp/Database.h +++ b/include/SQLiteCpp/Database.h @@ -429,7 +429,7 @@ public: * * @return Rowid of the most recent successful INSERT into the database, or 0 if there was none. */ - long long getLastInsertRowid() const noexcept; + int64_t getLastInsertRowid() const noexcept; /// Get number of rows modified by last INSERT, UPDATE or DELETE statement (not DROP table). int getChanges() const noexcept; diff --git a/src/Column.cpp b/src/Column.cpp index f5dc0d9..108f7f9 100644 --- a/src/Column.cpp +++ b/src/Column.cpp @@ -51,19 +51,19 @@ const char* Column::getOriginName() const noexcept #endif // Return the integer value of the column specified by its index starting at 0 -int Column::getInt() const noexcept +int32_t Column::getInt() const noexcept { return sqlite3_column_int(mStmtPtr.get(), mIndex); } // Return the unsigned integer value of the column specified by its index starting at 0 -unsigned Column::getUInt() const noexcept +uint32_t Column::getUInt() const noexcept { return static_cast(getInt64()); } // Return the 64bits integer value of the column specified by its index starting at 0 -long long Column::getInt64() const noexcept +int64_t Column::getInt64() const noexcept { return sqlite3_column_int64(mStmtPtr.get(), mIndex); } diff --git a/src/Database.cpp b/src/Database.cpp index eb76c88..88f63c1 100644 --- a/src/Database.cpp +++ b/src/Database.cpp @@ -151,7 +151,7 @@ bool Database::tableExists(const char* apTableName) } // Get the rowid of the most recent successful INSERT into the database from the current connection. -long long Database::getLastInsertRowid() const noexcept +int64_t Database::getLastInsertRowid() const noexcept { return sqlite3_last_insert_rowid(getHandle()); } diff --git a/tests/Column_test.cpp b/tests/Column_test.cpp index adc26bd..fac607b 100644 --- a/tests/Column_test.cpp +++ b/tests/Column_test.cpp @@ -13,8 +13,6 @@ #include #include -#include // for sqlite3_int64 - #include #include @@ -59,12 +57,13 @@ TEST(Column, basis) // validates every variant of cast operators, and conversions of types { - const sqlite3_int64 id1 = query.getColumn(0); // operator long long() - const int64_t id2 = query.getColumn(0); // operator long long() - const long long id3 = query.getColumn(0); // operator long long() - const long id4 = query.getColumn(0); // operator long long() or long() depending on compiler/architecture - const char id5 = query.getColumn(0); // operator char() - const short id6 = query.getColumn(0); // operator short() + const int64_t id1 = query.getColumn(0); // operator int64_t() + const int32_t id2 = query.getColumn(0); // operator int32_t() + const int id3 = query.getColumn(0); // operator int32_t() + const int16_t id4 = query.getColumn(0); // operator int32_t() + const short id5 = query.getColumn(0); // operator int32_t() + const int8_t id6 = query.getColumn(0); // operator int32_t() + const char id7 = query.getColumn(0); // operator int32_t() const unsigned int uint1 = query.getColumn(0); // operator unsigned int() const uint32_t uint2 = query.getColumn(0); // operator unsigned int() const unsigned char uint3 = query.getColumn(0); // operator unsigned char() @@ -83,9 +82,6 @@ TEST(Column, basis) EXPECT_EQ(1, id1); EXPECT_EQ(1, id2); EXPECT_EQ(1, id3); - EXPECT_EQ(1, id4); - EXPECT_EQ(1, id5); - EXPECT_EQ(1, id6); EXPECT_EQ(1U, uint1); EXPECT_EQ(1U, uint2); EXPECT_EQ(1U, uint3);