From 078365febcc3171650e2beb8f68d6add04208778 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Rombauts?= Date: Sun, 3 May 2015 17:05:28 +0200 Subject: [PATCH] Fix part of issue #34 about 64 bits long with GCC on AMD64 --- include/SQLiteCpp/Column.h | 10 ++++++++++ tests/Column_test.cpp | 8 ++++++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/include/SQLiteCpp/Column.h b/include/SQLiteCpp/Column.h index d16e6f7..0364d4f 100644 --- a/include/SQLiteCpp/Column.h +++ b/include/SQLiteCpp/Column.h @@ -199,6 +199,16 @@ public: return getText(); } #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. inline const char* errmsg() const diff --git a/tests/Column_test.cpp b/tests/Column_test.cpp index 8e52781..030449c 100644 --- a/tests/Column_test.cpp +++ b/tests/Column_test.cpp @@ -16,7 +16,7 @@ #include #include -#include +#include TEST(Column, basis) { @@ -54,7 +54,9 @@ TEST(Column, basis) { // validates every variant of cast operators, and conversions of types { - int64_t id = query.getColumn(0); // operator sqlite3_int64() + 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 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() @@ -62,6 +64,8 @@ TEST(Column, basis) { const void* pblob = query.getColumn(4); // operator void*() const void* pempty = query.getColumn(5); // operator void*() EXPECT_EQ(1, id); + EXPECT_EQ(1, id2); + EXPECT_EQ(1, id3); EXPECT_STREQ("first", ptxt); EXPECT_EQ("first", msg); EXPECT_EQ(123, integer);