From df7d113a3b41f4a6790623113ec16a9e28dbfba4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Rombauts?= Date: Sat, 2 Mar 2019 18:20:10 +0100 Subject: [PATCH] Add test case to try to repro the reported ambiguous bind() int64_t on LP64 Android --- include/SQLiteCpp/Column.h | 6 +++--- include/SQLiteCpp/Statement.h | 12 ++++++------ tests/Statement_test.cpp | 26 ++++++++++++++++++++++++-- 3 files changed, 33 insertions(+), 11 deletions(-) diff --git a/include/SQLiteCpp/Column.h b/include/SQLiteCpp/Column.h index c39abf1..1143e69 100644 --- a/include/SQLiteCpp/Column.h +++ b/include/SQLiteCpp/Column.h @@ -176,7 +176,7 @@ public: { return getUInt(); } -#if (LONG_MAX == INT_MAX) // sizeof(long)==4 means the data model of the system is ILP32 (32bits OS or Windows 64bits) +#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 inline operator long() const { @@ -187,8 +187,8 @@ public: { return getUInt(); } -#else // sizeof(long)==8 means the data model of the system is LLP64 (64bits Linux) - /// Inline cast operator to 64bits long when the data model of the system is ILP64 (Linux 64 bits...) +#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...) inline operator long() const { return getInt64(); diff --git a/include/SQLiteCpp/Statement.h b/include/SQLiteCpp/Statement.h index bfb4efc..ecf417b 100644 --- a/include/SQLiteCpp/Statement.h +++ b/include/SQLiteCpp/Statement.h @@ -116,7 +116,7 @@ public: */ void bind(const int aIndex, const unsigned aValue); -#if (LONG_MAX == INT_MAX) // sizeof(long)==4 means the data model of the system is ILP32 (32bits OS or Windows 64bits) +#if (LONG_MAX == INT_MAX) // 4 bytes "long" type means the data model is ILP32 or LLP64 (Win64 Visual C++ and MinGW) /** * @brief Bind a 32bits long value to a parameter "?", "?NNN", ":VVV", "@VVV" or "$VVV" in the SQL prepared statement (aIndex >= 1) */ @@ -124,7 +124,7 @@ public: { bind(aIndex, static_cast(aValue)); } -#else // sizeof(long)==8 means the data model of the system is LLP64 (64bits Linux) +#else // 8 bytes "long" type means the data model is LP64 (Most Unix-like, Windows when using Cygwin; z/OS) /** * @brief Bind a 64bits long value to a parameter "?", "?NNN", ":VVV", "@VVV" or "$VVV" in the SQL prepared statement (aIndex >= 1) */ @@ -198,7 +198,7 @@ public: */ void bind(const char* apName, const unsigned aValue); -#if (LONG_MAX == INT_MAX) // sizeof(long)==4 means the data model of the system is ILP32 (32bits OS or Windows 64bits) +#if (LONG_MAX == INT_MAX) // 4 bytes "long" type means the data model is ILP32 or LLP64 (Win64 Visual C++ and MinGW) /** * @brief Bind a 32bits long value to a parameter "?", "?NNN", ":VVV", "@VVV" or "$VVV" in the SQL prepared statement (aIndex >= 1) */ @@ -206,7 +206,7 @@ public: { bind(apName, static_cast(aValue)); } -#else // sizeof(long)==8 means the data model of the system is LLP64 (64bits Linux) +#else // 8 bytes "long" type means the data model is LP64 (Most Unix-like, Windows when using Cygwin; z/OS) /** * @brief Bind a 64bits long value to a parameter "?", "?NNN", ":VVV", "@VVV" or "$VVV" in the SQL prepared statement (aIndex >= 1) */ @@ -286,7 +286,7 @@ public: bind(aName.c_str(), aValue); } -#if (LONG_MAX == INT_MAX) // sizeof(long)==4 means the data model of the system is ILP32 (32bits OS or Windows 64bits) +#if (LONG_MAX == INT_MAX) // 4 bytes "long" type means the data model is ILP32 or LLP64 (Win64 Visual C++ and MinGW) /** * @brief Bind a 32bits long value to a parameter "?", "?NNN", ":VVV", "@VVV" or "$VVV" in the SQL prepared statement (aIndex >= 1) */ @@ -294,7 +294,7 @@ public: { bind(aName.c_str(), static_cast(aValue)); } -#else // sizeof(long)==8 means the data model of the system is LLP64 (64bits Linux) +#else // 8 bytes "long" type means the data model is LP64 (Most Unix-like, Windows when using Cygwin; z/OS) /** * @brief Bind a 64bits long value to a parameter "?", "?NNN", ":VVV", "@VVV" or "$VVV" in the SQL prepared statement (aIndex >= 1) */ diff --git a/tests/Statement_test.cpp b/tests/Statement_test.cpp index e4c9f04..3e4d919 100644 --- a/tests/Statement_test.cpp +++ b/tests/Statement_test.cpp @@ -338,6 +338,25 @@ TEST(Statement, bindings) { EXPECT_EQ(4294967295U, query.getColumn(2).getUInt()); EXPECT_EQ(-123, query.getColumn(3).getInt()); } + + + // reset() without clearbindings() + insert.reset(); + + // Seventh row using another variant of int64 type + { + const int64_t int64 = 12345678900000LL; + insert.bind(2, int64); + EXPECT_EQ(1, insert.exec()); + EXPECT_EQ(SQLITE_DONE, db.getErrorCode()); + + // Check the result + query.executeStep(); + EXPECT_TRUE(query.hasRow()); + EXPECT_FALSE(query.isDone()); + EXPECT_EQ(7, query.getColumn(0).getInt64()); + EXPECT_EQ(12345678900000LL, query.getColumn(2).getInt64()); + } } TEST(Statement, bindNoCopy) { @@ -466,10 +485,12 @@ TEST(Statement, bindByName) { // reset() without clearbindings() insert.reset(); - // Fourth row with uint32_t unsigned value + // Fourth row with uint32_t unsigned value and int64_t 64bits value { const uint32_t uint32 = 4294967295U; + const int64_t int64 = 12345678900000LL; insert.bind("@int", uint32); + insert.bind("@long", int64); EXPECT_EQ(1, insert.exec()); EXPECT_EQ(SQLITE_DONE, db.getErrorCode()); @@ -479,6 +500,7 @@ TEST(Statement, bindByName) { EXPECT_FALSE(query.isDone()); EXPECT_EQ(4, query.getColumn(0).getInt64()); EXPECT_EQ(4294967295U, query.getColumn(2).getUInt()); + EXPECT_EQ(12345678900000LL, query.getColumn(4).getInt64()); } } @@ -762,7 +784,7 @@ TEST(Statement, getColumns) { } #endif -#if (LONG_MAX > INT_MAX) // sizeof(long)==8 means the data model of the system is LLP64 (64bits Linux) +#if (LONG_MAX > INT_MAX) // sizeof(long)==8 means the data model of the system is LP64 (64bits Linux) TEST(Statement, bind64bitsLong) { // Create a new database SQLite::Database db(":memory:", SQLite::OPEN_READWRITE|SQLite::OPEN_CREATE);